Browse code

Merge branch '2.x' into 3.x

* 2.x:
Fix PHPUnit deprecations
Update to PhpUnitBridge and fix deprecations

Fabien Potencier authored on 08/08/2019 09:05:13
Showing 21 changed files
... ...
@@ -4,6 +4,8 @@ return PhpCsFixer\Config::create()
4 4
     ->setRules([
5 5
         '@Symfony' => true,
6 6
         '@Symfony:risky' => true,
7
+        '@PHPUnit75Migration:risky' => true,
8
+        'php_unit_dedicate_assert' => ['target' => '5.6'],
7 9
         'array_syntax' => ['syntax' => 'short'],
8 10
         'php_unit_fqcn_annotation' => true,
9 11
         'no_unreachable_default_argument_value' => false,
... ...
@@ -5,6 +5,10 @@ cache:
5 5
         - vendor
6 6
         - $HOME/.composer/cache/files
7 7
 
8
+env:
9
+    global:
10
+        - SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1
11
+
8 12
 before_install:
9 13
     - phpenv config-rm xdebug.ini || return 0
10 14
 
... ...
@@ -29,7 +29,7 @@
29 29
         "symfony/polyfill-ctype": "^1.8"
30 30
     },
31 31
     "require-dev": {
32
-        "symfony/phpunit-bridge": "^4.3|^5.0",
32
+        "symfony/phpunit-bridge": "^4.4@dev|^5.0",
33 33
         "symfony/debug": "^3.4|^4.2|^5.0",
34 34
         "symfony/mime": "^4.3|^5.0",
35 35
         "psr/container": "^1.0"
... ...
@@ -42,7 +42,7 @@ class FilesystemTest extends TestCase
42 42
 
43 43
         $dir = \dirname($key);
44 44
         @mkdir($dir, 0777, true);
45
-        $this->assertTrue(is_dir($dir));
45
+        $this->assertDirectoryExists($dir);
46 46
         $this->assertFalse(class_exists($this->classname, false));
47 47
 
48 48
         $content = $this->generateSource();
... ...
@@ -79,12 +79,11 @@ class FilesystemTest extends TestCase
79 79
         $this->assertSame(file_get_contents($key), $content);
80 80
     }
81 81
 
82
-    /**
83
-     * @expectedException \RuntimeException
84
-     * @expectedExceptionMessage Unable to create the cache directory
85
-     */
86 82
     public function testWriteFailMkdir()
87 83
     {
84
+        $this->expectException(\RuntimeException::class);
85
+        $this->expectExceptionMessage('Unable to create the cache directory');
86
+
88 87
         if (\defined('PHP_WINDOWS_VERSION_BUILD')) {
89 88
             $this->markTestSkipped('Read-only directories not possible on Windows.');
90 89
         }
... ...
@@ -96,17 +95,16 @@ class FilesystemTest extends TestCase
96 95
 
97 96
         // Create read-only root directory.
98 97
         @mkdir($this->directory, 0555, true);
99
-        $this->assertTrue(is_dir($this->directory));
98
+        $this->assertDirectoryExists($this->directory);
100 99
 
101 100
         $this->cache->write($key, $content);
102 101
     }
103 102
 
104
-    /**
105
-     * @expectedException \RuntimeException
106
-     * @expectedExceptionMessage Unable to write in the cache directory
107
-     */
108 103
     public function testWriteFailDirWritable()
109 104
     {
105
+        $this->expectException(\RuntimeException::class);
106
+        $this->expectExceptionMessage('Unable to write in the cache directory');
107
+
110 108
         if (\defined('PHP_WINDOWS_VERSION_BUILD')) {
111 109
             $this->markTestSkipped('Read-only directories not possible on Windows.');
112 110
         }
... ...
@@ -120,17 +118,16 @@ class FilesystemTest extends TestCase
120 118
         @mkdir($this->directory, 0777, true);
121 119
         // Create read-only subdirectory.
122 120
         @mkdir($this->directory.'/cache', 0555);
123
-        $this->assertTrue(is_dir($this->directory.'/cache'));
121
+        $this->assertDirectoryExists($this->directory.'/cache');
124 122
 
125 123
         $this->cache->write($key, $content);
126 124
     }
127 125
 
128
-    /**
129
-     * @expectedException \RuntimeException
130
-     * @expectedExceptionMessage Failed to write cache file
131
-     */
132 126
     public function testWriteFailWriteFile()
133 127
     {
128
+        $this->expectException(\RuntimeException::class);
129
+        $this->expectExceptionMessage('Failed to write cache file');
130
+
134 131
         $key = $this->directory.'/cache/cachefile.php';
135 132
         $content = $this->generateSource();
136 133
 
... ...
@@ -138,7 +135,7 @@ class FilesystemTest extends TestCase
138 135
 
139 136
         // Create a directory in the place of the cache file.
140 137
         @mkdir($key, 0777, true);
141
-        $this->assertTrue(is_dir($key));
138
+        $this->assertDirectoryExists($key);
142 139
 
143 140
         $this->cache->write($key, $content);
144 141
     }
... ...
@@ -149,7 +146,7 @@ class FilesystemTest extends TestCase
149 146
 
150 147
         $dir = \dirname($key);
151 148
         @mkdir($dir, 0777, true);
152
-        $this->assertTrue(is_dir($dir));
149
+        $this->assertDirectoryExists($dir);
153 150
 
154 151
         // Create the file with a specific modification time.
155 152
         touch($key, 1234567890);
... ...
@@ -33,7 +33,7 @@ class CompilerTest extends TestCase
33 33
         }
34 34
 
35 35
         $this->assertEquals('1.2', $compiler->repr(1.2)->getSource());
36
-        $this->assertContains('fr', strtolower(setlocale(LC_NUMERIC, 0)));
36
+        $this->assertStringContainsString('fr', strtolower(setlocale(LC_NUMERIC, 0)));
37 37
 
38 38
         setlocale(LC_NUMERIC, $locale);
39 39
     }
... ...
@@ -23,12 +23,8 @@ class CustomExtensionTest extends TestCase
23 23
      */
24 24
     public function testGetInvalidOperators(ExtensionInterface $extension, $expectedExceptionMessage)
25 25
     {
26
-        if (method_exists($this, 'expectException')) {
27
-            $this->expectException('InvalidArgumentException');
28
-            $this->expectExceptionMessage($expectedExceptionMessage);
29
-        } else {
30
-            $this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
31
-        }
26
+        $this->expectException(\InvalidArgumentException::class);
27
+        $this->expectExceptionMessage($expectedExceptionMessage);
32 28
 
33 29
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
34 30
         $env->addExtension($extension);
... ...
@@ -15,6 +15,7 @@ use PHPUnit\Framework\TestCase;
15 15
 use Twig\Cache\CacheInterface;
16 16
 use Twig\Cache\FilesystemCache;
17 17
 use Twig\Environment;
18
+use Twig\Error\RuntimeError;
18 19
 use Twig\Extension\AbstractExtension;
19 20
 use Twig\Extension\ExtensionInterface;
20 21
 use Twig\Extension\GlobalsInterface;
... ...
@@ -309,6 +310,9 @@ class EnvironmentTest extends TestCase
309 310
      */
310 311
     public function testOverrideExtension()
311 312
     {
313
+        $this->expectException(\LogicException::class);
314
+        $this->expectExceptionMessage('Unable to register extension "Twig\Tests\EnvironmentTest_Extension" as it is already registered.');
315
+
312 316
         $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
313 317
 
314 318
         $twig->addExtension(new EnvironmentTest_Extension());
... ...
@@ -341,12 +345,11 @@ class EnvironmentTest extends TestCase
341 345
         $this->assertEquals('foo', $twig->render('func_string_named_args'));
342 346
     }
343 347
 
344
-    /**
345
-     * @expectedException \Twig\Error\RuntimeError
346
-     * @expectedExceptionMessage Failed to load Twig template "testFailLoadTemplate.twig", index "112233": cache might be corrupted in "testFailLoadTemplate.twig".
347
-     */
348 348
     public function testFailLoadTemplate()
349 349
     {
350
+        $this->expectException(RuntimeError::class);
351
+        $this->expectExceptionMessage('Failed to load Twig template "testFailLoadTemplate.twig", index "112233": cache might be corrupted in "testFailLoadTemplate.twig".');
352
+
350 353
         $template = 'testFailLoadTemplate.twig';
351 354
         $twig = new Environment(new ArrayLoader([$template => false]));
352 355
         $twig->loadTemplate($twig->getTemplateClass($template), $template, 112233);
... ...
@@ -26,7 +26,7 @@ class ErrorTest extends TestCase
26 26
         $error = new Error('foo');
27 27
         $error->setSourceContext(new Source('', new \SplFileInfo(__FILE__)));
28 28
 
29
-        $this->assertContains('tests'.\DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
29
+        $this->assertStringContainsString('tests'.\DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
30 30
     }
31 31
 
32 32
     public function testTwigExceptionGuessWithMissingVarAndArrayLoader()
... ...
@@ -13,6 +13,7 @@ namespace Twig\Tests;
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15 15
 use Twig\Environment;
16
+use Twig\Error\SyntaxError;
16 17
 use Twig\Loader\LoaderInterface;
17 18
 use Twig\Node\Expression\ArrayExpression;
18 19
 use Twig\Node\Expression\Binary\ConcatBinary;
... ...
@@ -24,14 +25,14 @@ use Twig\Source;
24 25
 class ExpressionParserTest extends TestCase
25 26
 {
26 27
     /**
27
-     * @expectedException \Twig\Error\SyntaxError
28 28
      * @dataProvider getFailingTestsForAssignment
29 29
      */
30 30
     public function testCanOnlyAssignToNames($template)
31 31
     {
32
+        $this->expectException(SyntaxError::class);
33
+
32 34
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
33 35
         $parser = new Parser($env);
34
-
35 36
         $parser->parse($env->tokenize(new Source($template, 'index')));
36 37
     }
37 38
 
... ...
@@ -67,14 +68,14 @@ class ExpressionParserTest extends TestCase
67 68
     }
68 69
 
69 70
     /**
70
-     * @expectedException \Twig\Error\SyntaxError
71 71
      * @dataProvider getFailingTestsForArray
72 72
      */
73 73
     public function testArraySyntaxError($template)
74 74
     {
75
+        $this->expectException(SyntaxError::class);
76
+
75 77
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
76 78
         $parser = new Parser($env);
77
-
78 79
         $parser->parse($env->tokenize(new Source($template, 'index')));
79 80
     }
80 81
 
... ...
@@ -162,11 +163,10 @@ class ExpressionParserTest extends TestCase
162 163
         ];
163 164
     }
164 165
 
165
-    /**
166
-     * @expectedException \Twig\Error\SyntaxError
167
-     */
168 166
     public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()
169 167
     {
168
+        $this->expectException(SyntaxError::class);
169
+
170 170
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
171 171
         $stream = $env->tokenize(new Source('{{ "a" "b" }}', 'index'));
172 172
         $parser = new Parser($env);
... ...
@@ -234,34 +234,31 @@ class ExpressionParserTest extends TestCase
234 234
         ];
235 235
     }
236 236
 
237
-    /**
238
-     * @expectedException \Twig\Error\SyntaxError
239
-     */
240 237
     public function testAttributeCallDoesNotSupportNamedArguments()
241 238
     {
239
+        $this->expectException(SyntaxError::class);
240
+
242 241
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
243 242
         $parser = new Parser($env);
244 243
 
245 244
         $parser->parse($env->tokenize(new Source('{{ foo.bar(name="Foo") }}', 'index')));
246 245
     }
247 246
 
248
-    /**
249
-     * @expectedException \Twig\Error\SyntaxError
250
-     */
251 247
     public function testMacroCallDoesNotSupportNamedArguments()
252 248
     {
249
+        $this->expectException(SyntaxError::class);
250
+
253 251
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
254 252
         $parser = new Parser($env);
255 253
 
256 254
         $parser->parse($env->tokenize(new Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
257 255
     }
258 256
 
259
-    /**
260
-     * @expectedException        \Twig\Error\SyntaxError
261
-     * @expectedExceptionMessage An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.
262
-     */
263 257
     public function testMacroDefinitionDoesNotSupportNonNameVariableName()
264 258
     {
259
+        $this->expectException(SyntaxError::class);
260
+        $this->expectExceptionMessage('An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.');
261
+
265 262
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
266 263
         $parser = new Parser($env);
267 264
 
... ...
@@ -269,12 +266,13 @@ class ExpressionParserTest extends TestCase
269 266
     }
270 267
 
271 268
     /**
272
-     * @expectedException        \Twig\Error\SyntaxError
273
-     * @expectedExceptionMessage A default value for an argument must be a constant (a boolean, a string, a number, or an array) in "index" at line 1
274 269
      * @dataProvider             getMacroDefinitionDoesNotSupportNonConstantDefaultValues
275 270
      */
276 271
     public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template)
277 272
     {
273
+        $this->expectException(SyntaxError::class);
274
+        $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');
275
+
278 276
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
279 277
         $parser = new Parser($env);
280 278
 
... ...
@@ -317,72 +315,66 @@ class ExpressionParserTest extends TestCase
317 315
         ];
318 316
     }
319 317
 
320
-    /**
321
-     * @expectedException        \Twig\Error\SyntaxError
322
-     * @expectedExceptionMessage Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?
323
-     */
324 318
     public function testUnknownFunction()
325 319
     {
320
+        $this->expectException(SyntaxError::class);
321
+        $this->expectExceptionMessage('Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?');
322
+
326 323
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
327 324
         $parser = new Parser($env);
328 325
 
329 326
         $parser->parse($env->tokenize(new Source('{{ cycl() }}', 'index')));
330 327
     }
331 328
 
332
-    /**
333
-     * @expectedException        \Twig\Error\SyntaxError
334
-     * @expectedExceptionMessage Unknown "foobar" function in "index" at line 1.
335
-     */
336 329
     public function testUnknownFunctionWithoutSuggestions()
337 330
     {
331
+        $this->expectException(SyntaxError::class);
332
+        $this->expectExceptionMessage('Unknown "foobar" function in "index" at line 1.');
333
+
338 334
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
339 335
         $parser = new Parser($env);
340 336
 
341 337
         $parser->parse($env->tokenize(new Source('{{ foobar() }}', 'index')));
342 338
     }
343 339
 
344
-    /**
345
-     * @expectedException        \Twig\Error\SyntaxError
346
-     * @expectedExceptionMessage Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?
347
-     */
348 340
     public function testUnknownFilter()
349 341
     {
342
+        $this->expectException(SyntaxError::class);
343
+        $this->expectExceptionMessage('Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?');
344
+
350 345
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
351 346
         $parser = new Parser($env);
352 347
 
353 348
         $parser->parse($env->tokenize(new Source('{{ 1|lowe }}', 'index')));
354 349
     }
355 350
 
356
-    /**
357
-     * @expectedException        \Twig\Error\SyntaxError
358
-     * @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1.
359
-     */
360 351
     public function testUnknownFilterWithoutSuggestions()
361 352
     {
353
+        $this->expectException(SyntaxError::class);
354
+        $this->expectExceptionMessage('Unknown "foobar" filter in "index" at line 1.');
355
+
362 356
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
363 357
         $parser = new Parser($env);
364 358
 
365 359
         $parser->parse($env->tokenize(new Source('{{ 1|foobar }}', 'index')));
366 360
     }
367 361
 
368
-    /**
369
-     * @expectedException        \Twig\Error\SyntaxError
370
-     * @expectedExceptionMessage Unknown "nul" test. Did you mean "null" in "index" at line 1
371
-     */
372 362
     public function testUnknownTest()
373 363
     {
364
+        $this->expectException(SyntaxError::class);
365
+        $this->expectExceptionMessage('Unknown "nul" test. Did you mean "null" in "index" at line 1');
366
+
374 367
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
375 368
         $parser = new Parser($env);
376 369
         $stream = $env->tokenize(new Source('{{ 1 is nul }}', 'index'));
377 370
         $parser->parse($stream);
378 371
     }
379 372
 
380
-    /**
381
-     * @expectedException        \Twig\Error\SyntaxError
382
-     * @expectedExceptionMessage Unknown "foobar" test in "index" at line 1.
383
-     */
384 373
     public function testUnknownTestWithoutSuggestions()
385 374
     {
375
+        $this->expectException(SyntaxError::class);
376
+        $this->expectExceptionMessage('Unknown "foobar" test in "index" at line 1.');
377
+
386 378
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
387 379
         $parser = new Parser($env);
388 380
 
... ...
@@ -13,6 +13,7 @@ namespace Twig\Tests\Extension;
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15 15
 use Twig\Environment;
16
+use Twig\Error\RuntimeError;
16 17
 use Twig\Loader\LoaderInterface;
17 18
 
18 19
 class CoreTest extends TestCase
... ...
@@ -97,11 +98,9 @@ class CoreTest extends TestCase
97 98
         $this->assertSame($instance, twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), $instance));
98 99
     }
99 100
 
100
-    /**
101
-     * @expectedException \Twig\Error\RuntimeError
102
-     */
103 101
     public function testRandomFunctionOfEmptyArrayThrowsException()
104 102
     {
103
+        $this->expectException(RuntimeError::class);
105 104
         twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), []);
106 105
     }
107 106
 
... ...
@@ -13,6 +13,7 @@ namespace Twig\Tests;
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15 15
 use Twig\Environment;
16
+use Twig\Error\RuntimeError;
16 17
 use Twig\Extension\EscaperExtension;
17 18
 use Twig\Loader\LoaderInterface;
18 19
 
... ...
@@ -358,11 +359,10 @@ class Twig_Tests_Extension_EscaperTest extends TestCase
358 359
         ];
359 360
     }
360 361
 
361
-    /**
362
-     * @expectedException \Twig\Error\RuntimeError
363
-     */
364 362
     public function testUnknownCustomEscaper()
365 363
     {
364
+        $this->expectException(RuntimeError::class);
365
+
366 366
         twig_escape_filter(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), 'foo', 'bar');
367 367
     }
368 368
 
... ...
@@ -53,12 +53,11 @@ class SandboxTest extends TestCase
53 53
         ];
54 54
     }
55 55
 
56
-    /**
57
-     * @expectedException        \Twig\Sandbox\SecurityError
58
-     * @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child" at line 3.
59
-     */
60 56
     public function testSandboxWithInheritance()
61 57
     {
58
+        $this->expectException(SecurityError::class);
59
+        $this->expectExceptionMessage('Filter "json_encode" is not allowed in "1_child" at line 3.');
60
+
62 61
         $twig = $this->getEnvironment(true, [], self::$templates, ['block']);
63 62
         $twig->load('1_child')->render([]);
64 63
     }
... ...
@@ -13,6 +13,7 @@ namespace Twig\Tests;
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15 15
 use Twig\Environment;
16
+use Twig\Error\SyntaxError;
16 17
 use Twig\Lexer;
17 18
 use Twig\Loader\LoaderInterface;
18 19
 use Twig\Source;
... ...
@@ -237,12 +238,11 @@ class LexerTest extends TestCase
237 238
         $this->addToAssertionCount(1);
238 239
     }
239 240
 
240
-    /**
241
-     * @expectedException \Twig\Error\SyntaxError
242
-     * @expectedExceptionMessage Unclosed """
243
-     */
244 241
     public function testStringWithUnterminatedInterpolation()
245 242
     {
243
+        $this->expectException(SyntaxError::class);
244
+        $this->expectExceptionMessage('Unclosed """');
245
+
246 246
         $template = '{{ "bar #{x" }}';
247 247
 
248 248
         $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()));
... ...
@@ -307,12 +307,11 @@ class LexerTest extends TestCase
307 307
         $this->addToAssertionCount(1);
308 308
     }
309 309
 
310
-    /**
311
-     * @expectedException \Twig\Error\SyntaxError
312
-     * @expectedExceptionMessage Unclosed "variable" in "index" at line 3
313
-     */
314 310
     public function testUnterminatedVariable()
315 311
     {
312
+        $this->expectException(SyntaxError::class);
313
+        $this->expectExceptionMessage('Unclosed "variable" in "index" at line 3');
314
+
316 315
         $template = '
317 316
 
318 317
 {{
... ...
@@ -326,12 +325,11 @@ bar
326 325
         $lexer->tokenize(new Source($template, 'index'));
327 326
     }
328 327
 
329
-    /**
330
-     * @expectedException \Twig\Error\SyntaxError
331
-     * @expectedExceptionMessage Unclosed "block" in "index" at line 3
332
-     */
333 328
     public function testUnterminatedBlock()
334 329
     {
330
+        $this->expectException(SyntaxError::class);
331
+        $this->expectExceptionMessage('Unclosed "block" in "index" at line 3');
332
+
335 333
         $template = '
336 334
 
337 335
 {%
... ...
@@ -12,15 +12,15 @@ namespace Twig\Tests\Loader;
12 12
  */
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15
+use Twig\Error\LoaderError;
15 16
 use Twig\Loader\ArrayLoader;
16 17
 
17 18
 class ArrayTest extends TestCase
18 19
 {
19
-    /**
20
-     * @expectedException \Twig\Error\LoaderError
21
-     */
22 20
     public function testGetSourceContextWhenTemplateDoesNotExist()
23 21
     {
22
+        $this->expectException(LoaderError::class);
23
+
24 24
         $loader = new ArrayLoader([]);
25 25
 
26 26
         $loader->getSourceContext('foo');
... ...
@@ -55,11 +55,10 @@ class ArrayTest extends TestCase
55 55
         $this->assertEquals('foo:__bar', $loader->getCacheKey('foo'));
56 56
     }
57 57
 
58
-    /**
59
-     * @expectedException \Twig\Error\LoaderError
60
-     */
61 58
     public function testGetCacheKeyWhenTemplateDoesNotExist()
62 59
     {
60
+        $this->expectException(LoaderError::class);
61
+
63 62
         $loader = new ArrayLoader([]);
64 63
 
65 64
         $loader->getCacheKey('foo');
... ...
@@ -79,11 +78,10 @@ class ArrayTest extends TestCase
79 78
         $this->assertTrue($loader->isFresh('foo', time()));
80 79
     }
81 80
 
82
-    /**
83
-     * @expectedException \Twig\Error\LoaderError
84
-     */
85 81
     public function testIsFreshWhenTemplateDoesNotExist()
86 82
     {
83
+        $this->expectException(LoaderError::class);
84
+
87 85
         $loader = new ArrayLoader([]);
88 86
 
89 87
         $loader->isFresh('foo', time());
... ...
@@ -12,6 +12,7 @@ namespace Twig\Tests\Loader;
12 12
  */
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15
+use Twig\Error\LoaderError;
15 16
 use Twig\Loader\ArrayLoader;
16 17
 use Twig\Loader\ChainLoader;
17 18
 use Twig\Loader\FilesystemLoader;
... ...
@@ -40,11 +41,10 @@ class ChainTest extends TestCase
40 41
         $this->assertNotEquals('baz', $loader->getSourceContext('errors/base.html')->getCode());
41 42
     }
42 43
 
43
-    /**
44
-     * @expectedException \Twig\Error\LoaderError
45
-     */
46 44
     public function testGetSourceContextWhenTemplateDoesNotExist()
47 45
     {
46
+        $this->expectException(LoaderError::class);
47
+
48 48
         $loader = new ChainLoader([]);
49 49
 
50 50
         $loader->getSourceContext('foo');
... ...
@@ -61,11 +61,10 @@ class ChainTest extends TestCase
61 61
         $this->assertEquals('bar:foo', $loader->getCacheKey('bar'));
62 62
     }
63 63
 
64
-    /**
65
-     * @expectedException \Twig\Error\LoaderError
66
-     */
67 64
     public function testGetCacheKeyWhenTemplateDoesNotExist()
68 65
     {
66
+        $this->expectException(LoaderError::class);
67
+
69 68
         $loader = new ChainLoader([]);
70 69
 
71 70
         $loader->getCacheKey('foo');
... ...
@@ -37,7 +37,7 @@ class FilesystemTest extends TestCase
37 37
             $loader->getCacheKey($template);
38 38
             $this->fail();
39 39
         } catch (LoaderError $e) {
40
-            $this->assertNotContains('Unable to find template', $e->getMessage());
40
+            $this->assertStringNotContainsString('Unable to find template', $e->getMessage());
41 41
         }
42 42
     }
43 43
 
... ...
@@ -157,7 +157,7 @@ class FilesystemTest extends TestCase
157 157
             $loader->getSourceContext('@named/nowhere.html');
158 158
         } catch (\Exception $e) {
159 159
             $this->assertInstanceOf(LoaderError::class, $e);
160
-            $this->assertContains('Unable to find template "@named/nowhere.html"', $e->getMessage());
160
+            $this->assertStringContainsString('Unable to find template "@named/nowhere.html"', $e->getMessage());
161 161
         }
162 162
     }
163 163
 
... ...
@@ -12,6 +12,7 @@ namespace Twig\Tests\Node\Expression;
12 12
  */
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15
+use Twig\Error\SyntaxError;
15 16
 use Twig\Node\Expression\CallExpression;
16 17
 
17 18
 class CallTest extends TestCase
... ...
@@ -22,52 +23,47 @@ class CallTest extends TestCase
22 23
         $this->assertEquals(['U', null], $this->getArguments($node, ['date', ['format' => 'U', 'timestamp' => null]]));
23 24
     }
24 25
 
25
-    /**
26
-     * @expectedException        \Twig\Error\SyntaxError
27
-     * @expectedExceptionMessage Positional arguments cannot be used after named arguments for function "date".
28
-     */
29 26
     public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
30 27
     {
28
+        $this->expectException(SyntaxError::class);
29
+        $this->expectExceptionMessage('Positional arguments cannot be used after named arguments for function "date".');
30
+
31 31
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
32 32
         $this->getArguments($node, ['date', ['timestamp' => 123456, 'Y-m-d']]);
33 33
     }
34 34
 
35
-    /**
36
-     * @expectedException        \Twig\Error\SyntaxError
37
-     * @expectedExceptionMessage Argument "format" is defined twice for function "date".
38
-     */
39 35
     public function testGetArgumentsWhenArgumentIsDefinedTwice()
40 36
     {
37
+        $this->expectException(SyntaxError::class);
38
+        $this->expectExceptionMessage('Argument "format" is defined twice for function "date".');
39
+
41 40
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
42 41
         $this->getArguments($node, ['date', ['Y-m-d', 'format' => 'U']]);
43 42
     }
44 43
 
45
-    /**
46
-     * @expectedException        \Twig\Error\SyntaxError
47
-     * @expectedExceptionMessage Unknown argument "unknown" for function "date(format, timestamp)".
48
-     */
49 44
     public function testGetArgumentsWithWrongNamedArgumentName()
50 45
     {
46
+        $this->expectException(SyntaxError::class);
47
+        $this->expectExceptionMessage('Unknown argument "unknown" for function "date(format, timestamp)".');
48
+
51 49
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
52 50
         $this->getArguments($node, ['date', ['Y-m-d', 'timestamp' => null, 'unknown' => '']]);
53 51
     }
54 52
 
55
-    /**
56
-     * @expectedException        \Twig\Error\SyntaxError
57
-     * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)".
58
-     */
59 53
     public function testGetArgumentsWithWrongNamedArgumentNames()
60 54
     {
55
+        $this->expectException(SyntaxError::class);
56
+        $this->expectExceptionMessage('Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)".');
57
+
61 58
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
62 59
         $this->getArguments($node, ['date', ['Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => '']]);
63 60
     }
64 61
 
65
-    /**
66
-     * @expectedException        \Twig\Error\SyntaxError
67
-     * @expectedExceptionMessage Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length".
68
-     */
69 62
     public function testResolveArgumentsWithMissingValueForOptionalArgument()
70 63
     {
64
+        $this->expectException(SyntaxError::class);
65
+        $this->expectExceptionMessage('Argument "case_sensitivity" could not be assigned for function "substr_compare(main_str, str, offset, length, case_sensitivity)" because it is mapped to an internal PHP function which cannot determine default value for optional argument "length".');
66
+
71 67
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'substr_compare']);
72 68
         $this->getArguments($node, ['substr_compare', ['abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true]]);
73 69
     }
... ...
@@ -85,12 +81,11 @@ class CallTest extends TestCase
85 81
         $this->assertEquals(['arg1'], $this->getArguments($node, [__CLASS__.'::customStaticFunction', ['arg1' => 'arg1']]));
86 82
     }
87 83
 
88
-    /**
89
-     * @expectedException        \LogicException
90
-     * @expectedExceptionMessage The last parameter of "Twig\Tests\Node\Expression\CallTest::customFunctionWithArbitraryArguments" for function "foo" must be an array with default value, eg. "array $arg = []".
91
-     */
92 84
     public function testResolveArgumentsWithMissingParameterForArbitraryArguments()
93 85
     {
86
+        $this->expectException(\LogicException::class);
87
+        $this->expectExceptionMessage('The last parameter of "Twig\\Tests\\Node\\Expression\\CallTest::customFunctionWithArbitraryArguments" for function "foo" must be an array with default value, eg. "array $arg = []".');
88
+
94 89
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
95 90
         $this->getArguments($node, [[$this, 'customFunctionWithArbitraryArguments'], []]);
96 91
     }
... ...
@@ -115,22 +110,20 @@ class CallTest extends TestCase
115 110
     {
116 111
     }
117 112
 
118
-    /**
119
-     * @expectedException              \LogicException
120
-     * @expectedExceptionMessageRegExp #^The last parameter of "Twig\\Tests\\Node\\Expression\\custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\. "array \$arg \= \[\]"\.$#
121
-     */
122 113
     public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
123 114
     {
115
+        $this->expectException(\LogicException::class);
116
+        $this->expectExceptionMessageRegExp('#^The last parameter of "Twig\\\\Tests\\\\Node\\\\Expression\\\\custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\\. "array \\$arg \\= \\[\\]"\\.$#');
117
+
124 118
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
125 119
         $node->getArguments('Twig\Tests\Node\Expression\custom_Twig_Tests_Node_Expression_CallTest_function', []);
126 120
     }
127 121
 
128
-    /**
129
-     * @expectedException              \LogicException
130
-     * @expectedExceptionMessageRegExp #^The last parameter of "Twig\\Tests\\Node\\Expression\\CallableTestClass\:\:__invoke" for function "foo" must be an array with default value, eg\. "array \$arg \= \[\]"\.$#
131
-     */
132 122
     public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
133 123
     {
124
+        $this->expectException(\LogicException::class);
125
+        $this->expectExceptionMessageRegExp('#^The last parameter of "Twig\\\\Tests\\\\Node\\\\Expression\\\\CallableTestClass\\:\\:__invoke" for function "foo" must be an array with default value, eg\\. "array \\$arg \\= \\[\\]"\\.$#');
126
+
134 127
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
135 128
         $node->getArguments(new CallableTestClass(), []);
136 129
     }
... ...
@@ -12,6 +12,7 @@ namespace Twig\Tests\Node\Expression;
12 12
  */
13 13
 
14 14
 use Twig\Environment;
15
+use Twig\Error\SyntaxError;
15 16
 use Twig\Loader\ArrayLoader;
16 17
 use Twig\Loader\LoaderInterface;
17 18
 use Twig\Node\Expression\ConstantExpression;
... ...
@@ -106,12 +107,11 @@ class FilterTest extends NodeTestCase
106 107
         return $tests;
107 108
     }
108 109
 
109
-    /**
110
-     * @expectedException        \Twig\Error\SyntaxError
111
-     * @expectedExceptionMessage Unknown argument "foobar" for filter "date(format, timezone)" at line 1.
112
-     */
113 110
     public function testCompileWithWrongNamedArgumentName()
114 111
     {
112
+        $this->expectException(SyntaxError::class);
113
+        $this->expectExceptionMessage('Unknown argument "foobar" for filter "date(format, timezone)" at line 1.');
114
+
115 115
         $date = new ConstantExpression(0, 1);
116 116
         $node = $this->createFilter($date, 'date', [
117 117
             'foobar' => new ConstantExpression('America/Chicago', 1),
... ...
@@ -121,12 +121,11 @@ class FilterTest extends NodeTestCase
121 121
         $compiler->compile($node);
122 122
     }
123 123
 
124
-    /**
125
-     * @expectedException        \Twig\Error\SyntaxError
126
-     * @expectedExceptionMessage Value for argument "from" is required for filter "replace" at line 1.
127
-     */
128 124
     public function testCompileWithMissingNamedArgument()
129 125
     {
126
+        $this->expectException(SyntaxError::class);
127
+        $this->expectExceptionMessage('Value for argument "from" is required for filter "replace" at line 1.');
128
+
130 129
         $value = new ConstantExpression(0, 1);
131 130
         $node = $this->createFilter($value, 'replace', [
132 131
             'to' => new ConstantExpression('foo', 1),
... ...
@@ -13,6 +13,7 @@ namespace Twig\Tests;
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15 15
 use Twig\Environment;
16
+use Twig\Error\SyntaxError;
16 17
 use Twig\Loader\LoaderInterface;
17 18
 use Twig\Node\Node;
18 19
 use Twig\Node\SetNode;
... ...
@@ -25,12 +26,11 @@ use Twig\TokenStream;
25 26
 
26 27
 class ParserTest extends TestCase
27 28
 {
28
-    /**
29
-     * @expectedException        \Twig\Error\SyntaxError
30
-     * @expectedExceptionMessage Unknown "foo" tag. Did you mean "for" at line 1?
31
-     */
32 29
     public function testUnknownTag()
33 30
     {
31
+        $this->expectException(SyntaxError::class);
32
+        $this->expectExceptionMessage('Unknown "foo" tag. Did you mean "for" at line 1?');
33
+
34 34
         $stream = new TokenStream([
35 35
             new Token(Token::BLOCK_START_TYPE, '', 1),
36 36
             new Token(Token::NAME_TYPE, 'foo', 1),
... ...
@@ -41,12 +41,11 @@ class ParserTest extends TestCase
41 41
         $parser->parse($stream);
42 42
     }
43 43
 
44
-    /**
45
-     * @expectedException        \Twig\Error\SyntaxError
46
-     * @expectedExceptionMessage Unknown "foobar" tag at line 1.
47
-     */
48 44
     public function testUnknownTagWithoutSuggestions()
49 45
     {
46
+        $this->expectException(SyntaxError::class);
47
+        $this->expectExceptionMessage('Unknown "foobar" tag at line 1.');
48
+
50 49
         $stream = new TokenStream([
51 50
             new Token(Token::BLOCK_START_TYPE, '', 1),
52 51
             new Token(Token::NAME_TYPE, 'foobar', 1),
... ...
@@ -89,10 +88,11 @@ class ParserTest extends TestCase
89 88
 
90 89
     /**
91 90
      * @dataProvider getFilterBodyNodesDataThrowsException
92
-     * @expectedException \Twig\Error\SyntaxError
93 91
      */
94 92
     public function testFilterBodyNodesThrowsException($input)
95 93
     {
94
+        $this->expectException(SyntaxError::class);
95
+
96 96
         $parser = $this->getParser();
97 97
 
98 98
         $m = new \ReflectionMethod($parser, 'filterBodyNodes');
... ...
@@ -24,11 +24,10 @@ use Twig\Template;
24 24
 
25 25
 class TemplateTest extends TestCase
26 26
 {
27
-    /**
28
-     * @expectedException \LogicException
29
-     */
30 27
     public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
31 28
     {
29
+        $this->expectException(\LogicException::class);
30
+
32 31
         $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
33 32
         $template = new TemplateForTest($twig);
34 33
         $template->displayBlock('foo', [], ['foo' => [new \stdClass(), 'foo']]);
... ...
@@ -109,7 +108,7 @@ class TemplateTest extends TestCase
109 108
                 $this->addToAssertionCount(1);
110 109
             }
111 110
 
112
-            $this->assertContains('is not allowed', $e->getMessage());
111
+            $this->assertStringContainsString('is not allowed', $e->getMessage());
113 112
         }
114 113
     }
115 114
 
... ...
@@ -123,12 +122,11 @@ class TemplateTest extends TestCase
123 122
         ];
124 123
     }
125 124
 
126
-    /**
127
-     * @expectedException \Twig\Error\RuntimeError
128
-     * @expectedExceptionMessage Block "unknown" on template "index.twig" does not exist in "index.twig".
129
-     */
130 125
     public function testRenderBlockWithUndefinedBlock()
131 126
     {
127
+        $this->expectException(RuntimeError::class);
128
+        $this->expectExceptionMessage('Block "unknown" on template "index.twig" does not exist in "index.twig".');
129
+
132 130
         $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
133 131
         $template = new TemplateForTest($twig, 'index.twig');
134 132
         try {
... ...
@@ -140,23 +138,21 @@ class TemplateTest extends TestCase
140 138
         }
141 139
     }
142 140
 
143
-    /**
144
-     * @expectedException \Twig\Error\RuntimeError
145
-     * @expectedExceptionMessage Block "unknown" on template "index.twig" does not exist in "index.twig".
146
-     */
147 141
     public function testDisplayBlockWithUndefinedBlock()
148 142
     {
143
+        $this->expectException(RuntimeError::class);
144
+        $this->expectExceptionMessage('Block "unknown" on template "index.twig" does not exist in "index.twig".');
145
+
149 146
         $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
150 147
         $template = new TemplateForTest($twig, 'index.twig');
151 148
         $template->displayBlock('unknown', []);
152 149
     }
153 150
 
154
-    /**
155
-     * @expectedException \Twig\Error\RuntimeError
156
-     * @expectedExceptionMessage Block "foo" should not call parent() in "index.twig" as the block does not exist in the parent template "parent.twig"
157
-     */
158 151
     public function testDisplayBlockWithUndefinedParentBlock()
159 152
     {
153
+        $this->expectException(RuntimeError::class);
154
+        $this->expectExceptionMessage('Block "foo" should not call parent() in "index.twig" as the block does not exist in the parent template "parent.twig"');
155
+
160 156
         $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
161 157
         $template = new TemplateForTest($twig, 'parent.twig');
162 158
         $template->displayBlock('foo', [], ['foo' => [new TemplateForTest($twig, 'index.twig'), 'block_foo']], false);
... ...
@@ -210,13 +206,9 @@ class TemplateTest extends TestCase
210 206
         if ($defined) {
211 207
             $this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
212 208
         } else {
213
-            if (method_exists($this, 'expectException')) {
214
-                $this->expectException(RuntimeError::class);
215
-                if (null !== $exceptionMessage) {
216
-                    $this->expectExceptionMessage($exceptionMessage);
217
-                }
218
-            } else {
219
-                $this->setExpectedException(RuntimeError::class, $exceptionMessage);
209
+            $this->expectException(RuntimeError::class);
210
+            if (null !== $exceptionMessage) {
211
+                $this->expectExceptionMessage($exceptionMessage);
220 212
             }
221 213
             $this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
222 214
         }
... ...
@@ -390,12 +382,10 @@ class TemplateTest extends TestCase
390 382
         return $tests;
391 383
     }
392 384
 
393
-    /**
394
-     * @expectedException \Twig\Error\RuntimeError
395
-     */
396 385
     public function testGetIsMethods()
397 386
     {
398
-        $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['strict_variables' => true]);
387
+        $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
388
+
399 389
         $getIsObject = new TemplateGetIsMethods();
400 390
         $template = new TemplateForTest($twig, 'index.twig');
401 391
         // first time should not create a cache for "get"
... ...
@@ -12,6 +12,7 @@ namespace Twig\Tests;
12 12
  */
13 13
 
14 14
 use PHPUnit\Framework\TestCase;
15
+use Twig\Error\SyntaxError;
15 16
 use Twig\Token;
16 17
 use Twig\TokenStream;
17 18
 
... ...
@@ -45,12 +46,11 @@ class TokenStreamTest extends TestCase
45 46
         $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token');
46 47
     }
47 48
 
48
-    /**
49
-     * @expectedException        \Twig\Error\SyntaxError
50
-     * @expectedExceptionMessage Unexpected end of template
51
-     */
52 49
     public function testEndOfTemplateNext()
53 50
     {
51
+        $this->expectException(SyntaxError::class);
52
+        $this->expectExceptionMessage('Unexpected end of template');
53
+
54 54
         $stream = new TokenStream([
55 55
             new Token(Token::BLOCK_START_TYPE, 1, 1),
56 56
         ]);
... ...
@@ -59,12 +59,11 @@ class TokenStreamTest extends TestCase
59 59
         }
60 60
     }
61 61
 
62
-    /**
63
-     * @expectedException        \Twig\Error\SyntaxError
64
-     * @expectedExceptionMessage Unexpected end of template
65
-     */
66 62
     public function testEndOfTemplateLook()
67 63
     {
64
+        $this->expectException(SyntaxError::class);
65
+        $this->expectExceptionMessage('Unexpected end of template');
66
+
68 67
         $stream = new TokenStream([
69 68
             new Token(Token::BLOCK_START_TYPE, 1, 1),
70 69
         ]);