Best Phake code snippet using Converter
ParamConverterManagerTest.php
Source:ParamConverterManagerTest.php
1<?php2namespace Drupal\Tests\Core\ParamConverter;3use Drupal\Core\ParamConverter\ParamConverterManager;4use Drupal\Core\ParamConverter\ParamNotConvertedException;5use Drupal\Tests\UnitTestCase;6use Drupal\Core\Routing\RouteObjectInterface;7use Symfony\Component\Routing\Route;8use Symfony\Component\Routing\RouteCollection;9/**10 * @coversDefaultClass \Drupal\Core\ParamConverter\ParamConverterManager11 * @group ParamConverter12 */13class ParamConverterManagerTest extends UnitTestCase {14 /**15 * @var \Drupal\Core\ParamConverter\ParamConverterManager16 */17 protected $manager;18 /**19 * {@inheritdoc}20 */21 protected function setUp(): void {22 parent::setUp();23 $this->manager = new ParamConverterManager();24 }25 /**26 * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter().27 *28 * @dataProvider providerTestGetConverter29 *30 * @covers ::getConverter31 */32 public function testGetConverter($name, $class) {33 $converter = $this->getMockBuilder('Drupal\Core\ParamConverter\ParamConverterInterface')34 ->setMockClassName($class)35 ->getMock();36 $this->manager->addConverter($converter, $name);37 $this->assertInstanceOf($class, $this->manager->getConverter($name));38 // Assert that a second call to getConverter() does not use the container.39 $this->assertInstanceOf($class, $this->manager->getConverter($name));40 }41 /**42 * Tests \Drupal\Core\ParamConverter\ParamConverterManager::getConverter().43 *44 * @covers ::getConverter45 */46 public function testGetConverterException() {47 $this->expectException(\InvalidArgumentException::class);48 $this->manager->getConverter('undefined.converter');49 }50 /**51 * Provide data for parameter converter manager tests.52 *53 * @return array54 * An array of arrays, each containing the input parameters for55 * providerTestResolvers::testAddConverter().56 *57 * @see ParamConverterManagerTest::testAddConverter()58 */59 public function providerTestAddConverter() {60 $converters[0]['unsorted'] = [61 ['name' => 'strawberry'],62 ['name' => 'raspberry'],63 ['name' => 'pear'],64 ['name' => 'peach'],65 ['name' => 'pineapple'],66 ['name' => 'banana'],67 ['name' => 'apple'],68 ];69 $converters[0]['sorted'] = [70 'strawberry', 'raspberry', 'pear', 'peach',71 'pineapple', 'banana', 'apple',72 ];73 $converters[1]['unsorted'] = [74 ['name' => 'giraffe'],75 ['name' => 'zebra'],76 ['name' => 'eagle'],77 ['name' => 'ape'],78 ['name' => 'cat'],79 ['name' => 'puppy'],80 ['name' => 'llama'],81 ];82 $converters[1]['sorted'] = [83 'giraffe', 'zebra', 'eagle', 'ape',84 'cat', 'puppy', 'llama',85 ];86 return $converters;87 }88 /**89 * Provide data for parameter converter manager tests.90 *91 * @return array92 * An array of arrays, each containing the input parameters for93 * providerTestResolvers::testGetConverter().94 *95 * @see ParamConverterManagerTest::testGetConverter()96 */97 public function providerTestGetConverter() {98 return [99 ['ape', 'ApeConverterClass'],100 ['cat', 'CatConverterClass'],101 ['puppy', 'PuppyConverterClass'],102 ['llama', 'LlamaConverterClass'],103 ['giraffe', 'GiraffeConverterClass'],104 ['zebra', 'ZebraConverterClass'],105 ['eagle', 'EagleConverterClass'],106 ];107 }108 /**109 * @covers ::setRouteParameterConverters110 *111 * @dataProvider providerTestSetRouteParameterConverters112 */113 public function testSetRouteParameterConverters($path, $parameters = NULL, $expected = NULL) {114 $converter = $this->createMock('Drupal\Core\ParamConverter\ParamConverterInterface');115 $converter->expects($this->any())116 ->method('applies')117 ->with($this->anything(), 'id', $this->anything())118 ->will($this->returnValue(TRUE));119 $this->manager->addConverter($converter, 'applied');120 $route = new Route($path);121 if ($parameters) {122 $route->setOption('parameters', $parameters);123 }124 $collection = new RouteCollection();125 $collection->add('test_route', $route);126 $this->manager->setRouteParameterConverters($collection);127 foreach ($collection as $route) {128 $result = $route->getOption('parameters');129 if ($expected) {130 $this->assertSame($expected, $result['id']['converter']);131 }132 else {133 $this->assertNull($result);134 }135 }136 }137 /**138 * Provides data for testSetRouteParameterConverters().139 */140 public function providerTestSetRouteParameterConverters() {141 return [142 ['/test'],143 ['/test/{id}', ['id' => []], 'applied'],144 ['/test/{id}', ['id' => ['converter' => 'predefined']], 'predefined'],145 ];146 }147 /**148 * @covers ::convert149 */150 public function testConvert() {151 $route = new Route('/test/{id}/{literal}/{null}');152 $parameters = [153 'id' => [154 'converter' => 'test_convert',155 ],156 'literal' => [],157 'null' => [],158 ];159 $route->setOption('parameters', $parameters);160 $defaults = [161 RouteObjectInterface::ROUTE_OBJECT => $route,162 RouteObjectInterface::ROUTE_NAME => 'test_route',163 'id' => 1,164 'literal' => 'this is a literal',165 'null' => NULL,166 ];167 $expected = $defaults;168 $expected['id'] = 'something_better!';169 $converter = $this->createMock('Drupal\Core\ParamConverter\ParamConverterInterface');170 $converter->expects($this->any())171 ->method('convert')172 ->with(1, $this->isType('array'), 'id', $this->isType('array'))173 ->will($this->returnValue('something_better!'));174 $this->manager->addConverter($converter, 'test_convert');175 $result = $this->manager->convert($defaults);176 $this->assertEquals($expected, $result);177 }178 /**179 * @covers ::convert180 */181 public function testConvertNoConverting() {182 $route = new Route('/test');183 $defaults = [184 RouteObjectInterface::ROUTE_OBJECT => $route,185 RouteObjectInterface::ROUTE_NAME => 'test_route',186 ];187 $expected = $defaults;188 $result = $this->manager->convert($defaults);189 $this->assertEquals($expected, $result);190 }191 /**192 * @covers ::convert193 */194 public function testConvertMissingParam() {195 $route = new Route('/test/{id}');196 $parameters = [197 'id' => [198 'converter' => 'test_convert',199 ],200 ];201 $route->setOption('parameters', $parameters);202 $defaults = [203 RouteObjectInterface::ROUTE_OBJECT => $route,204 RouteObjectInterface::ROUTE_NAME => 'test_route',205 'id' => 1,206 ];207 $converter = $this->createMock('Drupal\Core\ParamConverter\ParamConverterInterface');208 $converter->expects($this->any())209 ->method('convert')210 ->with(1, $this->isType('array'), 'id', $this->isType('array'))211 ->will($this->returnValue(NULL));212 $this->manager->addConverter($converter, 'test_convert');213 $this->expectException(ParamNotConvertedException::class);214 $this->expectExceptionMessage('The "id" parameter was not converted for the path "/test/{id}" (route name: "test_route")');215 $this->manager->convert($defaults);216 }217}...
constants_spec.rb
Source:constants_spec.rb
1require File.expand_path('../../../../spec_helper', __FILE__)2with_feature :encoding do3 describe "Encoding::Converter::INVALID_MASK" do4 it "exists" do5 Encoding::Converter.should have_constant(:INVALID_MASK)6 end7 it "has a Fixnum value" do8 Encoding::Converter::INVALID_MASK.should be_an_instance_of(Fixnum)9 end10 end11 describe "Encoding::Converter::INVALID_REPLACE" do12 it "exists" do13 Encoding::Converter.should have_constant(:INVALID_REPLACE)14 end15 it "has a Fixnum value" do16 Encoding::Converter::INVALID_REPLACE.should be_an_instance_of(Fixnum)17 end18 end19 describe "Encoding::Converter::UNDEF_MASK" do20 it "exists" do21 Encoding::Converter.should have_constant(:UNDEF_MASK)22 end23 it "has a Fixnum value" do24 Encoding::Converter::UNDEF_MASK.should be_an_instance_of(Fixnum)25 end26 end27 describe "Encoding::Converter::UNDEF_REPLACE" do28 it "exists" do29 Encoding::Converter.should have_constant(:UNDEF_REPLACE)30 end31 it "has a Fixnum value" do32 Encoding::Converter::UNDEF_REPLACE.should be_an_instance_of(Fixnum)33 end34 end35 describe "Encoding::Converter::UNDEF_HEX_CHARREF" do36 it "exists" do37 Encoding::Converter.should have_constant(:UNDEF_HEX_CHARREF)38 end39 it "has a Fixnum value" do40 Encoding::Converter::UNDEF_HEX_CHARREF.should be_an_instance_of(Fixnum)41 end42 end43 describe "Encoding::Converter::PARTIAL_INPUT" do44 it "exists" do45 Encoding::Converter.should have_constant(:PARTIAL_INPUT)46 end47 it "has a Fixnum value" do48 Encoding::Converter::PARTIAL_INPUT.should be_an_instance_of(Fixnum)49 end50 end51 describe "Encoding::Converter::AFTER_OUTPUT" do52 it "exists" do53 Encoding::Converter.should have_constant(:AFTER_OUTPUT)54 end55 it "has a Fixnum value" do56 Encoding::Converter::AFTER_OUTPUT.should be_an_instance_of(Fixnum)57 end58 end59 describe "Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR" do60 it "exists" do61 Encoding::Converter.should have_constant(:UNIVERSAL_NEWLINE_DECORATOR)62 end63 it "has a Fixnum value" do64 Encoding::Converter::UNIVERSAL_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)65 end66 end67 describe "Encoding::Converter::CRLF_NEWLINE_DECORATOR" do68 it "exists" do69 Encoding::Converter.should have_constant(:CRLF_NEWLINE_DECORATOR)70 end71 it "has a Fixnum value" do72 Encoding::Converter::CRLF_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)73 end74 end75 describe "Encoding::Converter::CR_NEWLINE_DECORATOR" do76 it "exists" do77 Encoding::Converter.should have_constant(:CR_NEWLINE_DECORATOR)78 end79 it "has a Fixnum value" do80 Encoding::Converter::CR_NEWLINE_DECORATOR.should be_an_instance_of(Fixnum)81 end82 end83 describe "Encoding::Converter::XML_TEXT_DECORATOR" do84 it "exists" do85 Encoding::Converter.should have_constant(:XML_TEXT_DECORATOR)86 end87 it "has a Fixnum value" do88 Encoding::Converter::XML_TEXT_DECORATOR.should be_an_instance_of(Fixnum)89 end90 end91 describe "Encoding::Converter::XML_ATTR_CONTENT_DECORATOR" do92 it "exists" do93 Encoding::Converter.should have_constant(:XML_ATTR_CONTENT_DECORATOR)94 end95 it "has a Fixnum value" do96 Encoding::Converter::XML_ATTR_CONTENT_DECORATOR.should be_an_instance_of(Fixnum)97 end98 end99 describe "Encoding::Converter::XML_ATTR_QUOTE_DECORATOR" do100 it "exists" do101 Encoding::Converter.should have_constant(:XML_ATTR_QUOTE_DECORATOR)102 end103 it "has a Fixnum value" do104 Encoding::Converter::XML_ATTR_QUOTE_DECORATOR.should be_an_instance_of(Fixnum)105 end106 end107end...
coderay.rb
Source:coderay.rb
...5#6# This file is part of kramdown which is licensed under the MIT.7#++8#9module Kramdown::Converter::SyntaxHighlighter10 # Uses Coderay to highlight code blocks and code spans.11 module Coderay12 begin13 require 'coderay'14 # Highlighting via coderay is available if this constant is +true+.15 AVAILABLE = true16 rescue LoadError17 AVAILABLE = false # :nodoc:18 end19 def self.call(converter, text, lang, type, call_opts)20 return nil unless converter.options[:enable_coderay]21 if type == :span && lang22 ::CodeRay.scan(text, lang.to_sym).html(options(converter, :span)).chomp23 elsif type == :block && (lang || options(converter, :default_lang))...
converter.rb
Source:converter.rb
...9require 'kramdown/utils'10module Kramdown11 # This module contains all available converters, i.e. classes that take a root Element and convert12 # it to a specific output format. The result is normally a string. For example, the13 # Converter::Html module converts an element tree into valid HTML.14 #15 # Converters use the Base class for common functionality (like applying a template to the output)16 # \- see its API documentation for how to create a custom converter class.17 module Converter18 autoload :Base, 'kramdown/converter/base'19 autoload :Html, 'kramdown/converter/html'20 autoload :Latex, 'kramdown/converter/latex'21 autoload :Kramdown, 'kramdown/converter/kramdown'22 autoload :Toc, 'kramdown/converter/toc'23 autoload :RemoveHtmlTags, 'kramdown/converter/remove_html_tags'24 autoload :Pdf, 'kramdown/converter/pdf'25 autoload :HashAST, 'kramdown/converter/hash_ast'26 autoload :HashAst, 'kramdown/converter/hash_ast'27 autoload :Man, 'kramdown/converter/man'28 extend ::Kramdown::Utils::Configurable29 configurable(:syntax_highlighter)30 ['Minted', "Coderay", "Rouge"].each do |klass_name|31 kn_down = klass_name.downcase.intern32 add_syntax_highlighter(kn_down) do |converter, text, lang, type, opts|33 require "kramdown/converter/syntax_highlighter/#{kn_down}"34 klass = ::Kramdown::Utils.deep_const_get("::Kramdown::Converter::SyntaxHighlighter::#{klass_name}")35 if !klass.const_defined?(:AVAILABLE) || klass::AVAILABLE36 add_syntax_highlighter(kn_down, klass)37 else38 add_syntax_highlighter(kn_down) {|*args| nil}39 end40 syntax_highlighter(kn_down).call(converter, text, lang, type, opts)41 end42 end43 configurable(:math_engine)44 ['Mathjax', "MathjaxNode", "Ritex", "Itex2MML"].each do |klass_name|45 kn_down = klass_name.downcase.intern46 add_math_engine(kn_down) do |converter, el, opts|47 require "kramdown/converter/math_engine/#{kn_down}"48 klass = ::Kramdown::Utils.deep_const_get("::Kramdown::Converter::MathEngine::#{klass_name}")49 if !klass.const_defined?(:AVAILABLE) || klass::AVAILABLE50 add_math_engine(kn_down, klass)51 else52 add_math_engine(kn_down) {|*args| nil}53 end54 math_engine(kn_down).call(converter, el, opts)55 end56 end57 end58end...
Converter
Using AI Code Generation
1$conv = new Converter();2echo $conv->convert(2);3$conv = new Converter();4echo $conv->convert(3);5$conv = new Converter();6echo $conv->convert(4);7$conv = new Converter();8echo $conv->convert(5);9$conv = new Converter();10echo $conv->convert(6);11$conv = new Converter();12echo $conv->convert(7);13$conv = new Converter();14echo $conv->convert(8);15$conv = new Converter();16echo $conv->convert(9);17$conv = new Converter();18echo $conv->convert(10);19$conv = new Converter();20echo $conv->convert(11);21$conv = new Converter();22echo $conv->convert(12);23$conv = new Converter();24echo $conv->convert(13);25$conv = new Converter();26echo $conv->convert(14);27$conv = new Converter();28echo $conv->convert(15);29$conv = new Converter();30echo $conv->convert(16);31$conv = new Converter();32echo $conv->convert(17);
Converter
Using AI Code Generation
1$converter = new Converter();2echo $converter->convert(10);3$converter = new Converter();4echo $converter->convert(10);5$converter = new Converter();6echo $converter->convert(10);7$converter = new Converter();8echo $converter->convert(10);9$converter = new Converter();10echo $converter->convert(10);11$converter = new Converter();12echo $converter->convert(10);13$converter = new Converter();14echo $converter->convert(10);15$converter = new Converter();16echo $converter->convert(10);17$converter = new Converter();18echo $converter->convert(10);19$converter = new Converter();20echo $converter->convert(10);21$converter = new Converter();22echo $converter->convert(10);23$converter = new Converter();24echo $converter->convert(10);25$converter = new Converter();26echo $converter->convert(10);27$converter = new Converter();28echo $converter->convert(10);29$converter = new Converter();30echo $converter->convert(10);31$converter = new Converter();32echo $converter->convert(10);
Converter
Using AI Code Generation
1$convert = new Converter();2echo $convert->convert('2.php');3$convert = new Converter();4echo $convert->convert('3.php');5$convert = new Converter();6echo $convert->convert('4.php');7$convert = new Converter();8echo $convert->convert('5.php');9$convert = new Converter();10echo $convert->convert('6.php');11$convert = new Converter();12echo $convert->convert('7.php');13$convert = new Converter();14echo $convert->convert('8.php');15$convert = new Converter();16echo $convert->convert('9.php');17$convert = new Converter();18echo $convert->convert('10.php');19$convert = new Converter();20echo $convert->convert('11.php');21$convert = new Converter();22echo $convert->convert('12.php');23$convert = new Converter();24echo $convert->convert('13.php');25$convert = new Converter();26echo $convert->convert('14.php');27$convert = new Converter();28echo $convert->convert('15.php');29$convert = new Converter();30echo $convert->convert('16.php');31$convert = new Converter();32echo $convert->convert('17.php');
Converter
Using AI Code Generation
1$convert = new Converter();2$convert->convert('file1','file2');3$convert = new Converter();4$convert->convert('file1','file2');5$convert = new Converter();6$convert->convert('file1','file2');7$convert = new Converter();8$convert->convert('file1','file2');9$convert = new Converter();10$convert->convert('file1','file2');11$convert = new Converter();12$convert->convert('file1','file2');13$convert = new Converter();14$convert->convert('file1','file2');15$convert = new Converter();16$convert->convert('file1','file2');17$convert = new Converter();18$convert->convert('file1','file2');19$convert = new Converter();20$convert->convert('file1','file2');21$convert = new Converter();22$convert->convert('file1','file2');23$convert = new Converter();24$convert->convert('file1','file2');25$convert = new Converter();26$convert->convert('file1','file2');27$convert = new Converter();28$convert->convert('file1','file2');29$convert = new Converter();30$convert->convert('file1','file2');
Converter
Using AI Code Generation
1use Phake\Converter;2$converter = new Converter();3$converter->setInputFile('1.php');4$converter->setOutputFile('2.php');5$converter->convert();6use Phake\Converter;7$converter = new Converter();8$converter->setInputFile('2.php');9$converter->setOutputFile('3.php');10$converter->convert();11use Phake\Converter;12$converter = new Converter();13$converter->setInputFile('3.php');14$converter->setOutputFile('4.php');15$converter->convert();16use Phake\Converter;17$converter = new Converter();18$converter->setInputFile('4.php');19$converter->setOutputFile('5.php');20$converter->convert();21use Phake\Converter;22$converter = new Converter();23$converter->setInputFile('5.php');24$converter->setOutputFile('6.php');25$converter->convert();26use Phake\Converter;27$converter = new Converter();28$converter->setInputFile('6.php');29$converter->setOutputFile('7.php');30$converter->convert();31use Phake\Converter;32$converter = new Converter();33$converter->setInputFile('7.php');34$converter->setOutputFile('8.php');35$converter->convert();36use Phake\Converter;37$converter = new Converter();38$converter->setInputFile('8.php');39$converter->setOutputFile('9.php');40$converter->convert();
Converter
Using AI Code Generation
1include_once "Converter.php";2$converter = new Converter();3$converter->set('amount', 100);4$converter->set('from', 'usd');5$converter->set('to', 'inr');6print $converter->convert();7include_once "Converter.php";8$converter = new Converter();9$converter->set('amount', 100);10$converter->set('from', 'usd');11$converter->set('to', 'inr');12print $converter->convert();13include_once "Converter.php";14$converter = new Converter();15$converter->set('amount', 100);16$converter->set('from', 'usd');17$converter->set('to', 'inr');18print $converter->convert();19include_once "Converter.php";20$converter = new Converter();21$converter->set('amount', 100);22$converter->set('from', 'usd');23$converter->set('to', 'inr');24print $converter->convert();25include_once "Converter.php";26$converter = new Converter();27$converter->set('amount', 100);28$converter->set('from', 'usd');29$converter->set('to', 'inr');30print $converter->convert();31include_once "Converter.php";32$converter = new Converter();33$converter->set('amount', 100);34$converter->set('from', 'usd');35$converter->set('to', 'inr');36print $converter->convert();37include_once "Converter.php";38$converter = new Converter();39$converter->set('amount', 100);40$converter->set('from', 'usd');41$converter->set('to', 'inr');42print $converter->convert();43include_once "Converter.php";44$converter = new Converter();45$converter->set('amount', 100);46$converter->set('from', 'usd');
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!