diff --git a/tests/CompilerTest.php b/tests/CompilerTest.php index 31c462a37..d3aa65b73 100644 --- a/tests/CompilerTest.php +++ b/tests/CompilerTest.php @@ -20,7 +20,7 @@ class CompilerTest extends TestCase { public function testReprNumericValueWithLocale() { - $compiler = new Compiler(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $compiler = new Compiler(new Environment($this->createMock(LoaderInterface::class))); $locale = setlocale(LC_NUMERIC, 0); if (false === $locale) { diff --git a/tests/CustomExtensionTest.php b/tests/CustomExtensionTest.php index 4e9406f14..27f38fc87 100644 --- a/tests/CustomExtensionTest.php +++ b/tests/CustomExtensionTest.php @@ -26,7 +26,7 @@ class CustomExtensionTest extends TestCase $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage($expectedExceptionMessage); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $env = new Environment($this->createMock(LoaderInterface::class)); $env->addExtension($extension); $env->getUnaryOperators(); } diff --git a/tests/EnvironmentTest.php b/tests/EnvironmentTest.php index a51afdae7..0a3219bc2 100644 --- a/tests/EnvironmentTest.php +++ b/tests/EnvironmentTest.php @@ -58,7 +58,7 @@ class EnvironmentTest extends TestCase public function testGlobals() { - $loader = $this->getMockBuilder(LoaderInterface::class)->getMock(); + $loader = $this->createMock(LoaderInterface::class); $loader->expects($this->any())->method('getSourceContext')->willReturn(new Source('', '')); // globals can be added after calling getGlobals @@ -265,7 +265,7 @@ class EnvironmentTest extends TestCase public function testHasGetExtensionByClassName() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->addExtension($ext = new EnvironmentTest_Extension()); $this->assertSame($ext, $twig->getExtension('Twig\Tests\EnvironmentTest_Extension')); $this->assertSame($ext, $twig->getExtension('\Twig\Tests\EnvironmentTest_Extension')); @@ -276,7 +276,7 @@ class EnvironmentTest extends TestCase public function testAddExtension() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->addExtension(new EnvironmentTest_Extension()); $this->assertArrayHasKey('test', $twig->getTags()); @@ -313,7 +313,7 @@ class EnvironmentTest extends TestCase */ public function testInitRuntimeWithAnExtensionUsingInitRuntimeNoDeprecation() { - $loader = $this->getMockBuilder(LoaderInterface::class)->getMock(); + $loader = $this->createMock(LoaderInterface::class); $twig = new Environment($loader); $loader->expects($this->once())->method('getSourceContext')->willReturn(new Source('', '')); $twig->addExtension(new EnvironmentTest_ExtensionWithoutDeprecationInitRuntime()); @@ -329,7 +329,7 @@ class EnvironmentTest extends TestCase $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unable to register extension "Twig\Tests\EnvironmentTest_Extension" as it is already registered.'); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->addExtension(new EnvironmentTest_Extension()); $twig->addExtension(new EnvironmentTest_Extension()); @@ -373,7 +373,7 @@ class EnvironmentTest extends TestCase protected function getMockLoader($templateName, $templateContent) { - $loader = $this->getMockBuilder(LoaderInterface::class)->getMock(); + $loader = $this->createMock(LoaderInterface::class); $loader->expects($this->any()) ->method('getSourceContext') ->with($templateName) diff --git a/tests/ExpressionParserTest.php b/tests/ExpressionParserTest.php index 8e24e5bbd..c6b3a067d 100644 --- a/tests/ExpressionParserTest.php +++ b/tests/ExpressionParserTest.php @@ -31,7 +31,7 @@ class ExpressionParserTest extends TestCase { $this->expectException(SyntaxError::class); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source($template, 'index'))); } @@ -59,7 +59,7 @@ class ExpressionParserTest extends TestCase */ public function testArrayExpression($template, $expected) { - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $stream = $env->tokenize($source = new Source($template, '')); $parser = new Parser($env); $expected->setSourceContext($source); @@ -74,7 +74,7 @@ class ExpressionParserTest extends TestCase { $this->expectException(SyntaxError::class); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source($template, 'index'))); } @@ -167,7 +167,7 @@ class ExpressionParserTest extends TestCase { $this->expectException(SyntaxError::class); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); $stream = $env->tokenize(new Source('{{ "a" "b" }}', 'index')); $parser = new Parser($env); @@ -179,7 +179,7 @@ class ExpressionParserTest extends TestCase */ public function testStringExpression($template, $expected) { - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]); $stream = $env->tokenize($source = new Source($template, '')); $parser = new Parser($env); $expected->setSourceContext($source); @@ -238,7 +238,7 @@ class ExpressionParserTest extends TestCase { $this->expectException(SyntaxError::class); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{{ foo.bar(name="Foo") }}', 'index'))); @@ -248,7 +248,7 @@ class ExpressionParserTest extends TestCase { $this->expectException(SyntaxError::class); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index'))); @@ -259,7 +259,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{% macro foo("a") %}{% endmacro %}', 'index'))); @@ -273,7 +273,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source($template, 'index'))); @@ -292,7 +292,7 @@ class ExpressionParserTest extends TestCase */ public function testMacroDefinitionSupportsConstantDefaultValues($template) { - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source($template, 'index'))); @@ -320,7 +320,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{{ cycl() }}', 'index'))); @@ -331,7 +331,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('Unknown "foobar" function in "index" at line 1.'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{{ foobar() }}', 'index'))); @@ -342,7 +342,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{{ 1|lowe }}', 'index'))); @@ -353,7 +353,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('Unknown "foobar" filter in "index" at line 1.'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{{ 1|foobar }}', 'index'))); @@ -364,7 +364,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('Unknown "nul" test. Did you mean "null" in "index" at line 1'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $stream = $env->tokenize(new Source('{{ 1 is nul }}', 'index')); $parser->parse($stream); @@ -375,7 +375,7 @@ class ExpressionParserTest extends TestCase $this->expectException(SyntaxError::class); $this->expectExceptionMessage('Unknown "foobar" test in "index" at line 1.'); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $parser = new Parser($env); $parser->parse($env->tokenize(new Source('{{ 1 is foobar }}', 'index'))); diff --git a/tests/Extension/CoreTest.php b/tests/Extension/CoreTest.php index 0311d4967..33794fd46 100644 --- a/tests/Extension/CoreTest.php +++ b/tests/Extension/CoreTest.php @@ -23,7 +23,7 @@ class CoreTest extends TestCase */ public function testRandomFunction(array $expectedInArray, $value1, $value2 = null) { - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $env = new Environment($this->createMock(LoaderInterface::class)); for ($i = 0; $i < 100; ++$i) { $this->assertTrue(\in_array(twig_random($env, $value1, $value2), $expectedInArray, true)); // assertContains() would not consider the type @@ -84,29 +84,29 @@ class CoreTest extends TestCase $max = mt_getrandmax(); for ($i = 0; $i < 100; ++$i) { - $val = twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $val = twig_random(new Environment($this->createMock(LoaderInterface::class))); $this->assertTrue(\is_int($val) && $val >= 0 && $val <= $max); } } public function testRandomFunctionReturnsAsIs() { - $this->assertSame('', twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), '')); - $this->assertSame('', twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['charset' => null]), '')); + $this->assertSame('', twig_random(new Environment($this->createMock(LoaderInterface::class)), '')); + $this->assertSame('', twig_random(new Environment($this->createMock(LoaderInterface::class), ['charset' => null]), '')); $instance = new \stdClass(); - $this->assertSame($instance, twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), $instance)); + $this->assertSame($instance, twig_random(new Environment($this->createMock(LoaderInterface::class)), $instance)); } public function testRandomFunctionOfEmptyArrayThrowsException() { $this->expectException(RuntimeError::class); - twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), []); + twig_random(new Environment($this->createMock(LoaderInterface::class)), []); } public function testRandomFunctionOnNonUTF8String() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->setCharset('ISO-8859-1'); $text = iconv('UTF-8', 'ISO-8859-1', 'Äé'); @@ -118,7 +118,7 @@ class CoreTest extends TestCase public function testReverseFilterOnNonUTF8String() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->setCharset('ISO-8859-1'); $input = iconv('UTF-8', 'ISO-8859-1', 'Äé'); @@ -132,7 +132,7 @@ class CoreTest extends TestCase */ public function testTwigFirst($expected, $input) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertSame($expected, twig_first($twig, $input)); } @@ -154,7 +154,7 @@ class CoreTest extends TestCase */ public function testTwigLast($expected, $input) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertSame($expected, twig_last($twig, $input)); } @@ -227,7 +227,7 @@ class CoreTest extends TestCase */ public function testSliceFilter($expected, $input, $start, $length = null, $preserveKeys = false) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertSame($expected, twig_slice($twig, $input, $start, $length, $preserveKeys)); } diff --git a/tests/Extension/EscaperTest.php b/tests/Extension/EscaperTest.php index 59210d659..b7ec4065b 100644 --- a/tests/Extension/EscaperTest.php +++ b/tests/Extension/EscaperTest.php @@ -160,7 +160,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testHtmlEscapingConvertsSpecialChars() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); foreach ($this->htmlSpecialChars as $key => $value) { $this->assertEquals($value, twig_escape_filter($twig, $key, 'html'), 'Failed to escape: '.$key); } @@ -168,7 +168,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testHtmlAttributeEscapingConvertsSpecialChars() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); foreach ($this->htmlAttrSpecialChars as $key => $value) { $this->assertEquals($value, twig_escape_filter($twig, $key, 'html_attr'), 'Failed to escape: '.$key); } @@ -176,7 +176,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testJavascriptEscapingConvertsSpecialChars() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); foreach ($this->jsSpecialChars as $key => $value) { $this->assertEquals($value, twig_escape_filter($twig, $key, 'js'), 'Failed to escape: '.$key); } @@ -184,19 +184,19 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testJavascriptEscapingReturnsStringIfZeroLength() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertEquals('', twig_escape_filter($twig, '', 'js')); } public function testJavascriptEscapingReturnsStringIfContainsOnlyDigits() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertEquals('123', twig_escape_filter($twig, '123', 'js')); } public function testCssEscapingConvertsSpecialChars() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); foreach ($this->cssSpecialChars as $key => $value) { $this->assertEquals($value, twig_escape_filter($twig, $key, 'css'), 'Failed to escape: '.$key); } @@ -204,19 +204,19 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testCssEscapingReturnsStringIfZeroLength() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertEquals('', twig_escape_filter($twig, '', 'css')); } public function testCssEscapingReturnsStringIfContainsOnlyDigits() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $this->assertEquals('123', twig_escape_filter($twig, '123', 'css')); } public function testUrlEscapingConvertsSpecialChars() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); foreach ($this->urlSpecialChars as $key => $value) { $this->assertEquals($value, twig_escape_filter($twig, $key, 'url'), 'Failed to escape: '.$key); } @@ -273,7 +273,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testJavascriptEscapingEscapesOwaspRecommendedRanges() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $immune = [',', '.', '_']; // Exceptions to escaping ranges for ($chr = 0; $chr < 0xFF; ++$chr) { if ($chr >= 0x30 && $chr <= 0x39 @@ -297,7 +297,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testHtmlAttributeEscapingEscapesOwaspRecommendedRanges() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $immune = [',', '.', '-', '_']; // Exceptions to escaping ranges for ($chr = 0; $chr < 0xFF; ++$chr) { if ($chr >= 0x30 && $chr <= 0x39 @@ -321,7 +321,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testCssEscapingEscapesOwaspRecommendedRanges() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); // CSS has no exceptions to escaping ranges for ($chr = 0; $chr < 0xFF; ++$chr) { if ($chr >= 0x30 && $chr <= 0x39 @@ -344,7 +344,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase */ public function testCustomEscaper($expected, $string, $strategy) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->getExtension(EscaperExtension::class)->setEscaper('foo', 'Twig\Tests\foo_escaper_for_test'); $this->assertSame($expected, twig_escape_filter($twig, $string, $strategy)); @@ -363,7 +363,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase { $this->expectException(RuntimeError::class); - twig_escape_filter(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), 'foo', 'bar'); + twig_escape_filter(new Environment($this->createMock(LoaderInterface::class)), 'foo', 'bar'); } /** @@ -372,7 +372,7 @@ class Twig_Tests_Extension_EscaperTest extends TestCase public function testObjectEscaping(string $escapedHtml, string $escapedJs, array $safeClasses) { $obj = new Extension_TestClass(); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->getExtension('\Twig\Extension\EscaperExtension')->setSafeClasses($safeClasses); $this->assertSame($escapedHtml, twig_escape_filter($twig, $obj, 'html', null, true)); $this->assertSame($escapedJs, twig_escape_filter($twig, $obj, 'js', null, true)); diff --git a/tests/LexerTest.php b/tests/LexerTest.php index d956dc1fc..fdb58c2d5 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -25,7 +25,7 @@ class LexerTest extends TestCase { $template = '{% § %}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::BLOCK_START_TYPE); @@ -36,7 +36,7 @@ class LexerTest extends TestCase { $template = '{{ §() }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::VAR_START_TYPE); @@ -53,7 +53,7 @@ class LexerTest extends TestCase protected function countToken($template, $type, $value = null) { - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $count = 0; @@ -78,7 +78,7 @@ class LexerTest extends TestCase ."baz\n" ."}}\n"; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); // foo\nbar\n @@ -98,7 +98,7 @@ class LexerTest extends TestCase ."baz\n" ."}}\n"; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); // foo\nbar @@ -113,7 +113,7 @@ class LexerTest extends TestCase { $template = '{# '.str_repeat('*', 100000).' #}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above @@ -125,7 +125,7 @@ class LexerTest extends TestCase { $template = '{% verbatim %}'.str_repeat('*', 100000).'{% endverbatim %}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above @@ -137,7 +137,7 @@ class LexerTest extends TestCase { $template = '{{ '.str_repeat('x', 100000).' }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above @@ -149,7 +149,7 @@ class LexerTest extends TestCase { $template = '{% '.str_repeat('x', 100000).' %}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); // add a dummy assertion here to satisfy PHPUnit, the only thing we want to test is that the code above @@ -161,7 +161,7 @@ class LexerTest extends TestCase { $template = '{{ 922337203685477580700 }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->next(); $node = $stream->next(); @@ -175,7 +175,7 @@ class LexerTest extends TestCase '{{ "foo \" bar" }}' => 'foo " bar', ]; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); foreach ($tests as $template => $expected) { $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::VAR_START_TYPE); @@ -191,7 +191,7 @@ class LexerTest extends TestCase { $template = 'foo {{ "bar #{ baz + 1 }" }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::TEXT_TYPE, 'foo '); $stream->expect(Token::VAR_START_TYPE); @@ -212,7 +212,7 @@ class LexerTest extends TestCase { $template = '{{ "bar \#{baz+1}" }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::VAR_START_TYPE); $stream->expect(Token::STRING_TYPE, 'bar #{baz+1}'); @@ -227,7 +227,7 @@ class LexerTest extends TestCase { $template = '{{ "bar # baz" }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::VAR_START_TYPE); $stream->expect(Token::STRING_TYPE, 'bar # baz'); @@ -245,7 +245,7 @@ class LexerTest extends TestCase $template = '{{ "bar #{x" }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); } @@ -253,7 +253,7 @@ class LexerTest extends TestCase { $template = '{{ "bar #{ "foo#{bar}" }" }}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::VAR_START_TYPE); $stream->expect(Token::STRING_TYPE, 'bar '); @@ -274,7 +274,7 @@ class LexerTest extends TestCase { $template = '{% foo "bar #{ "foo#{bar}" }" %}'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::BLOCK_START_TYPE); $stream->expect(Token::NAME_TYPE, 'foo'); @@ -296,7 +296,7 @@ class LexerTest extends TestCase { $template = "{{ 1 and\n0}}"; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $stream = $lexer->tokenize(new Source($template, 'index')); $stream->expect(Token::VAR_START_TYPE); $stream->expect(Token::NUMBER_TYPE, 1); @@ -321,7 +321,7 @@ bar '; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); } @@ -339,14 +339,14 @@ bar '; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class))); $lexer->tokenize(new Source($template, 'index')); } public function testOverridingSyntax() { $template = '[# comment #]{# variable #}/# if true #/true/# endif #/'; - $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), [ + $lexer = new Lexer(new Environment($this->createMock(LoaderInterface::class)), [ 'tag_comment' => ['[#', '#]'], 'tag_block' => ['/#', '#/'], 'tag_variable' => ['{#', '#}'], diff --git a/tests/Loader/ChainTest.php b/tests/Loader/ChainTest.php index 441bd3e5f..faaaebe33 100644 --- a/tests/Loader/ChainTest.php +++ b/tests/Loader/ChainTest.php @@ -80,11 +80,11 @@ class ChainTest extends TestCase public function testExists() { - $loader1 = $this->getMockBuilder(LoaderInterface::class)->getMock(); + $loader1 = $this->createMock(LoaderInterface::class); $loader1->expects($this->once())->method('exists')->willReturn(false); $loader1->expects($this->never())->method('getSourceContext'); - $loader2 = $this->getMockBuilder(LoaderInterface::class)->getMock(); + $loader2 = $this->createMock(LoaderInterface::class); $loader2->expects($this->once())->method('exists')->willReturn(true); $loader2->expects($this->never())->method('getSourceContext'); diff --git a/tests/Node/DeprecatedTest.php b/tests/Node/DeprecatedTest.php index 5d4b1ef5b..24185f4b5 100644 --- a/tests/Node/DeprecatedTest.php +++ b/tests/Node/DeprecatedTest.php @@ -62,7 +62,7 @@ if (true) { EOF ]; - $environment = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $environment = new Environment($this->createMock(LoaderInterface::class)); $environment->addFunction(new TwigFunction('foo', 'foo', [])); $expr = new FunctionExpression('foo', new Node(), 1); diff --git a/tests/Node/Expression/FilterTest.php b/tests/Node/Expression/FilterTest.php index bb9ff65cb..ccac2ab82 100644 --- a/tests/Node/Expression/FilterTest.php +++ b/tests/Node/Expression/FilterTest.php @@ -37,7 +37,7 @@ class FilterTest extends NodeTestCase public function getTests() { - $environment = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $environment = new Environment($this->createMock(LoaderInterface::class)); $environment->addFilter(new TwigFilter('bar', 'twig_tests_filter_dummy', ['needs_environment' => true])); $environment->addFilter(new TwigFilter('barbar', 'Twig\Tests\Node\Expression\twig_tests_filter_barbar', ['needs_context' => true, 'is_variadic' => true])); diff --git a/tests/Node/Expression/FunctionTest.php b/tests/Node/Expression/FunctionTest.php index 820e32625..d0ca83dc9 100644 --- a/tests/Node/Expression/FunctionTest.php +++ b/tests/Node/Expression/FunctionTest.php @@ -34,7 +34,7 @@ class FunctionTest extends NodeTestCase public function getTests() { - $environment = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $environment = new Environment($this->createMock(LoaderInterface::class)); $environment->addFunction(new TwigFunction('foo', 'twig_tests_function_dummy', [])); $environment->addFunction(new TwigFunction('bar', 'twig_tests_function_dummy', ['needs_environment' => true])); $environment->addFunction(new TwigFunction('foofoo', 'twig_tests_function_dummy', ['needs_context' => true])); diff --git a/tests/Node/Expression/NameTest.php b/tests/Node/Expression/NameTest.php index 42533ad5f..57ba02b76 100644 --- a/tests/Node/Expression/NameTest.php +++ b/tests/Node/Expression/NameTest.php @@ -31,8 +31,8 @@ class NameTest extends NodeTestCase $self = new NameExpression('_self', 1); $context = new NameExpression('_context', 1); - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['strict_variables' => true]); - $env1 = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['strict_variables' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]); + $env1 = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => false]); $output = '(isset($context["foo"]) || array_key_exists("foo", $context) ? $context["foo"] : (function () { throw new RuntimeError(\'Variable "foo" does not exist.\', 1, $this->source); })())'; diff --git a/tests/Node/Expression/TestTest.php b/tests/Node/Expression/TestTest.php index b57557865..d8fc291c3 100644 --- a/tests/Node/Expression/TestTest.php +++ b/tests/Node/Expression/TestTest.php @@ -37,7 +37,7 @@ class TestTest extends NodeTestCase public function getTests() { - $environment = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $environment = new Environment($this->createMock(LoaderInterface::class)); $environment->addTest(new TwigTest('barbar', 'Twig\Tests\Node\Expression\twig_tests_test_barbar', ['is_variadic' => true, 'need_context' => true])); $tests = []; diff --git a/tests/Node/ModuleTest.php b/tests/Node/ModuleTest.php index 68fc8fea1..573f920aa 100644 --- a/tests/Node/ModuleTest.php +++ b/tests/Node/ModuleTest.php @@ -45,7 +45,7 @@ class ModuleTest extends NodeTestCase public function getTests() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $tests = []; @@ -200,7 +200,7 @@ EOF 2 ); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['debug' => true]); + $twig = new Environment($this->createMock(LoaderInterface::class), ['debug' => true]); $node = new ModuleNode($body, $extends, $blocks, $macros, $traits, new Node([]), $source); $tests[] = [$node, <<getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $stream = $env->parse($env->tokenize(new Source('{{ block("foo") }}', 'index'))); @@ -36,7 +36,7 @@ class OptimizerTest extends TestCase public function testRenderParentBlockOptimizer() { - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false, 'autoescape' => false]); $stream = $env->parse($env->tokenize(new Source('{% extends "foo" %}{% block content %}{{ parent() }}{% endblock %}', 'index'))); @@ -51,7 +51,7 @@ class OptimizerTest extends TestCase */ public function testForOptimizer($template, $expected) { - $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false]); + $env = new Environment($this->createMock(LoaderInterface::class), ['cache' => false]); $stream = $env->parse($env->tokenize(new Source($template, 'index'))); diff --git a/tests/ParserTest.php b/tests/ParserTest.php index 678334a9e..32f9f727a 100644 --- a/tests/ParserTest.php +++ b/tests/ParserTest.php @@ -37,7 +37,7 @@ class ParserTest extends TestCase new Token(Token::BLOCK_END_TYPE, '', 1), new Token(Token::EOF_TYPE, '', 1), ]); - $parser = new Parser(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $parser = new Parser(new Environment($this->createMock(LoaderInterface::class))); $parser->parse($stream); } @@ -52,7 +52,7 @@ class ParserTest extends TestCase new Token(Token::BLOCK_END_TYPE, '', 1), new Token(Token::EOF_TYPE, '', 1), ]); - $parser = new Parser(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $parser = new Parser(new Environment($this->createMock(LoaderInterface::class))); $parser->parse($stream); } @@ -133,7 +133,7 @@ class ParserTest extends TestCase public function testParseIsReentrant() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), [ + $twig = new Environment($this->createMock(LoaderInterface::class), [ 'autoescape' => false, 'optimizations' => 0, ]); @@ -156,7 +156,7 @@ class ParserTest extends TestCase public function testGetVarName() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), [ + $twig = new Environment($this->createMock(LoaderInterface::class), [ 'autoescape' => false, 'optimizations' => 0, ]); @@ -178,7 +178,7 @@ EOF protected function getParser() { - $parser = new Parser(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock())); + $parser = new Parser(new Environment($this->createMock(LoaderInterface::class))); $parser->setParent(new Node()); $p = new \ReflectionProperty($parser, 'stream'); diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index dc17e017d..950643f67 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -27,7 +27,7 @@ class TemplateTest extends TestCase { $this->expectException(\LogicException::class); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig); $template->displayBlock('foo', [], ['foo' => [new \stdClass(), 'foo']]); } @@ -87,7 +87,7 @@ class TemplateTest extends TestCase */ public function testGetAttributeWithSandbox($object, $item, $allowed) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $policy = new SecurityPolicy([], [], [/*method*/], [/*prop*/], []); $twig->addExtension(new SandboxExtension($policy, !$allowed)); $template = new TemplateForTest($twig); @@ -126,7 +126,7 @@ class TemplateTest extends TestCase $this->expectException(RuntimeError::class); $this->expectExceptionMessage('Block "unknown" on template "index.twig" does not exist in "index.twig".'); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig, 'index.twig'); try { $template->renderBlock('unknown', []); @@ -142,7 +142,7 @@ class TemplateTest extends TestCase $this->expectException(RuntimeError::class); $this->expectExceptionMessage('Block "unknown" on template "index.twig" does not exist in "index.twig".'); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig, 'index.twig'); $template->displayBlock('unknown', []); } @@ -152,14 +152,14 @@ class TemplateTest extends TestCase $this->expectException(RuntimeError::class); $this->expectExceptionMessage('Block "foo" should not call parent() in "index.twig" as the block does not exist in the parent template "parent.twig"'); - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig, 'parent.twig'); $template->displayBlock('foo', [], ['foo' => [new TemplateForTest($twig, 'index.twig'), 'block_foo']], false); } public function testGetAttributeOnArrayWithConfusableKey() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig); $array = ['Zero', 'One', -1 => 'MinusOne', '' => 'EmptyString', '1.5' => 'FloatButString', '01' => 'IntegerButStringWithLeadingZeros']; @@ -188,7 +188,7 @@ class TemplateTest extends TestCase */ public function testGetAttribute($defined, $value, $object, $item, $arguments, $type) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig); $this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type)); @@ -199,7 +199,7 @@ class TemplateTest extends TestCase */ public function testGetAttributeStrict($defined, $value, $object, $item, $arguments, $type, $exceptionMessage = null) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['strict_variables' => true]); + $twig = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]); $template = new TemplateForTest($twig); if ($defined) { @@ -218,7 +218,7 @@ class TemplateTest extends TestCase */ public function testGetAttributeDefined($defined, $value, $object, $item, $arguments, $type) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig); $this->assertEquals($defined, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type, true)); @@ -229,7 +229,7 @@ class TemplateTest extends TestCase */ public function testGetAttributeDefinedStrict($defined, $value, $object, $item, $arguments, $type) { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['strict_variables' => true]); + $twig = new Environment($this->createMock(LoaderInterface::class), ['strict_variables' => true]); $template = new TemplateForTest($twig); $this->assertEquals($defined, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type, true)); @@ -237,7 +237,7 @@ class TemplateTest extends TestCase public function testGetAttributeCallExceptions() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $template = new TemplateForTest($twig); $object = new TemplateMagicMethodExceptionObject(); @@ -383,7 +383,7 @@ class TemplateTest extends TestCase public function testGetIsMethods() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $getIsObject = new TemplateGetIsMethods(); $template = new TemplateForTest($twig, 'index.twig'); diff --git a/tests/Util/DeprecationCollectorTest.php b/tests/Util/DeprecationCollectorTest.php index 16aa1e89e..e2c9be963 100644 --- a/tests/Util/DeprecationCollectorTest.php +++ b/tests/Util/DeprecationCollectorTest.php @@ -24,7 +24,7 @@ class DeprecationCollectorTest extends TestCase */ public function testCollect() { - $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()); + $twig = new Environment($this->createMock(LoaderInterface::class)); $twig->addFunction(new TwigFunction('deprec', [$this, 'deprec'], ['deprecated' => true])); $collector = new DeprecationCollector($twig);