Browse code

Merge branch '1.x' into 2.x

* 1.x:
Update to PhpUnitBridge and fix deprecations

Fabien Potencier authored on 08/08/2019 08:19:01
Showing 19 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": "^3.4.19|^4.1.8|^5.0",
32
+        "symfony/phpunit-bridge": "^4.4@dev|^5.0",
33 33
         "symfony/debug": "^3.4|^4.2",
34 34
         "symfony/mime": "^4.3",
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');
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');
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');
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');
27
+        $this->expectExceptionMessage($expectedExceptionMessage);
32 28
 
33 29
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
34 30
         $env->addExtension($extension);
... ...
@@ -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()
... ...
@@ -24,14 +24,14 @@ use Twig\Source;
24 24
 class ExpressionParserTest extends TestCase
25 25
 {
26 26
     /**
27
-     * @expectedException \Twig\Error\SyntaxError
28 27
      * @dataProvider getFailingTestsForAssignment
29 28
      */
30 29
     public function testCanOnlyAssignToNames($template)
31 30
     {
31
+        $this->expectException('\Twig\Error\SyntaxError');
32
+
32 33
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
33 34
         $parser = new Parser($env);
34
-
35 35
         $parser->parse($env->tokenize(new Source($template, 'index')));
36 36
     }
37 37
 
... ...
@@ -67,14 +67,14 @@ class ExpressionParserTest extends TestCase
67 67
     }
68 68
 
69 69
     /**
70
-     * @expectedException \Twig\Error\SyntaxError
71 70
      * @dataProvider getFailingTestsForArray
72 71
      */
73 72
     public function testArraySyntaxError($template)
74 73
     {
74
+        $this->expectException('\Twig\Error\SyntaxError');
75
+
75 76
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
76 77
         $parser = new Parser($env);
77
-
78 78
         $parser->parse($env->tokenize(new Source($template, 'index')));
79 79
     }
80 80
 
... ...
@@ -162,11 +162,10 @@ class ExpressionParserTest extends TestCase
162 162
         ];
163 163
     }
164 164
 
165
-    /**
166
-     * @expectedException \Twig\Error\SyntaxError
167
-     */
168 165
     public function testStringExpressionDoesNotConcatenateTwoConsecutiveStrings()
169 166
     {
167
+        $this->expectException('\Twig\Error\SyntaxError');
168
+
170 169
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false, 'optimizations' => 0]);
171 170
         $stream = $env->tokenize(new Source('{{ "a" "b" }}', 'index'));
172 171
         $parser = new Parser($env);
... ...
@@ -234,34 +233,31 @@ class ExpressionParserTest extends TestCase
234 233
         ];
235 234
     }
236 235
 
237
-    /**
238
-     * @expectedException \Twig\Error\SyntaxError
239
-     */
240 236
     public function testAttributeCallDoesNotSupportNamedArguments()
241 237
     {
238
+        $this->expectException('\Twig\Error\SyntaxError');
239
+
242 240
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
243 241
         $parser = new Parser($env);
244 242
 
245 243
         $parser->parse($env->tokenize(new Source('{{ foo.bar(name="Foo") }}', 'index')));
246 244
     }
247 245
 
248
-    /**
249
-     * @expectedException \Twig\Error\SyntaxError
250
-     */
251 246
     public function testMacroCallDoesNotSupportNamedArguments()
252 247
     {
248
+        $this->expectException('\Twig\Error\SyntaxError');
249
+
253 250
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
254 251
         $parser = new Parser($env);
255 252
 
256 253
         $parser->parse($env->tokenize(new Source('{% from _self import foo %}{% macro foo() %}{% endmacro %}{{ foo(name="Foo") }}', 'index')));
257 254
     }
258 255
 
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 256
     public function testMacroDefinitionDoesNotSupportNonNameVariableName()
264 257
     {
258
+        $this->expectException('\Twig\Error\SyntaxError');
259
+        $this->expectExceptionMessage('An argument must be a name. Unexpected token "string" of value "a" ("name" expected) in "index" at line 1.');
260
+
265 261
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
266 262
         $parser = new Parser($env);
267 263
 
... ...
@@ -269,12 +265,13 @@ class ExpressionParserTest extends TestCase
269 265
     }
270 266
 
271 267
     /**
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 268
      * @dataProvider             getMacroDefinitionDoesNotSupportNonConstantDefaultValues
275 269
      */
276 270
     public function testMacroDefinitionDoesNotSupportNonConstantDefaultValues($template)
277 271
     {
272
+        $this->expectException('\Twig\Error\SyntaxError');
273
+        $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');
274
+
278 275
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
279 276
         $parser = new Parser($env);
280 277
 
... ...
@@ -317,72 +314,66 @@ class ExpressionParserTest extends TestCase
317 314
         ];
318 315
     }
319 316
 
320
-    /**
321
-     * @expectedException        \Twig\Error\SyntaxError
322
-     * @expectedExceptionMessage Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?
323
-     */
324 317
     public function testUnknownFunction()
325 318
     {
319
+        $this->expectException('\Twig\Error\SyntaxError');
320
+        $this->expectExceptionMessage('Unknown "cycl" function. Did you mean "cycle" in "index" at line 1?');
321
+
326 322
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
327 323
         $parser = new Parser($env);
328 324
 
329 325
         $parser->parse($env->tokenize(new Source('{{ cycl() }}', 'index')));
330 326
     }
331 327
 
332
-    /**
333
-     * @expectedException        \Twig\Error\SyntaxError
334
-     * @expectedExceptionMessage Unknown "foobar" function in "index" at line 1.
335
-     */
336 328
     public function testUnknownFunctionWithoutSuggestions()
337 329
     {
330
+        $this->expectException('\Twig\Error\SyntaxError');
331
+        $this->expectExceptionMessage('Unknown "foobar" function in "index" at line 1.');
332
+
338 333
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
339 334
         $parser = new Parser($env);
340 335
 
341 336
         $parser->parse($env->tokenize(new Source('{{ foobar() }}', 'index')));
342 337
     }
343 338
 
344
-    /**
345
-     * @expectedException        \Twig\Error\SyntaxError
346
-     * @expectedExceptionMessage Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?
347
-     */
348 339
     public function testUnknownFilter()
349 340
     {
341
+        $this->expectException('\Twig\Error\SyntaxError');
342
+        $this->expectExceptionMessage('Unknown "lowe" filter. Did you mean "lower" in "index" at line 1?');
343
+
350 344
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
351 345
         $parser = new Parser($env);
352 346
 
353 347
         $parser->parse($env->tokenize(new Source('{{ 1|lowe }}', 'index')));
354 348
     }
355 349
 
356
-    /**
357
-     * @expectedException        \Twig\Error\SyntaxError
358
-     * @expectedExceptionMessage Unknown "foobar" filter in "index" at line 1.
359
-     */
360 350
     public function testUnknownFilterWithoutSuggestions()
361 351
     {
352
+        $this->expectException('\Twig\Error\SyntaxError');
353
+        $this->expectExceptionMessage('Unknown "foobar" filter in "index" at line 1.');
354
+
362 355
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
363 356
         $parser = new Parser($env);
364 357
 
365 358
         $parser->parse($env->tokenize(new Source('{{ 1|foobar }}', 'index')));
366 359
     }
367 360
 
368
-    /**
369
-     * @expectedException        \Twig\Error\SyntaxError
370
-     * @expectedExceptionMessage Unknown "nul" test. Did you mean "null" in "index" at line 1
371
-     */
372 361
     public function testUnknownTest()
373 362
     {
363
+        $this->expectException('\Twig\Error\SyntaxError');
364
+        $this->expectExceptionMessage('Unknown "nul" test. Did you mean "null" in "index" at line 1');
365
+
374 366
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
375 367
         $parser = new Parser($env);
376 368
         $stream = $env->tokenize(new Source('{{ 1 is nul }}', 'index'));
377 369
         $parser->parse($stream);
378 370
     }
379 371
 
380
-    /**
381
-     * @expectedException        \Twig\Error\SyntaxError
382
-     * @expectedExceptionMessage Unknown "foobar" test in "index" at line 1.
383
-     */
384 372
     public function testUnknownTestWithoutSuggestions()
385 373
     {
374
+        $this->expectException('\Twig\Error\SyntaxError');
375
+        $this->expectExceptionMessage('Unknown "foobar" test in "index" at line 1.');
376
+
386 377
         $env = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['cache' => false, 'autoescape' => false]);
387 378
         $parser = new Parser($env);
388 379
 
... ...
@@ -97,11 +97,9 @@ class CoreTest extends TestCase
97 97
         $this->assertSame($instance, twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), $instance));
98 98
     }
99 99
 
100
-    /**
101
-     * @expectedException \Twig\Error\RuntimeError
102
-     */
103 100
     public function testRandomFunctionOfEmptyArrayThrowsException()
104 101
     {
102
+        $this->expectException('\Twig\Error\RuntimeError');
105 103
         twig_random(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()), []);
106 104
     }
107 105
 
... ...
@@ -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('\Twig\Sandbox\SecurityError');
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
     }
... ...
@@ -237,12 +237,11 @@ class LexerTest extends TestCase
237 237
         $this->addToAssertionCount(1);
238 238
     }
239 239
 
240
-    /**
241
-     * @expectedException \Twig\Error\SyntaxError
242
-     * @expectedExceptionMessage Unclosed """
243
-     */
244 240
     public function testStringWithUnterminatedInterpolation()
245 241
     {
242
+        $this->expectException('\Twig\Error\SyntaxError');
243
+        $this->expectExceptionMessage('Unclosed """');
244
+
246 245
         $template = '{{ "bar #{x" }}';
247 246
 
248 247
         $lexer = new Lexer(new Environment($this->getMockBuilder(LoaderInterface::class)->getMock()));
... ...
@@ -307,12 +306,11 @@ class LexerTest extends TestCase
307 306
         $this->addToAssertionCount(1);
308 307
     }
309 308
 
310
-    /**
311
-     * @expectedException \Twig\Error\SyntaxError
312
-     * @expectedExceptionMessage Unclosed "variable" in "index" at line 3
313
-     */
314 309
     public function testUnterminatedVariable()
315 310
     {
311
+        $this->expectException('\Twig\Error\SyntaxError');
312
+        $this->expectExceptionMessage('Unclosed "variable" in "index" at line 3');
313
+
316 314
         $template = '
317 315
 
318 316
 {{
... ...
@@ -326,12 +324,11 @@ bar
326 324
         $lexer->tokenize(new Source($template, 'index'));
327 325
     }
328 326
 
329
-    /**
330
-     * @expectedException \Twig\Error\SyntaxError
331
-     * @expectedExceptionMessage Unclosed "block" in "index" at line 3
332
-     */
333 327
     public function testUnterminatedBlock()
334 328
     {
329
+        $this->expectException('\Twig\Error\SyntaxError');
330
+        $this->expectExceptionMessage('Unclosed "block" in "index" at line 3');
331
+
335 332
         $template = '
336 333
 
337 334
 {%
... ...
@@ -21,6 +21,8 @@ class ArrayTest extends TestCase
21 21
      */
22 22
     public function testGetSourceContextWhenTemplateDoesNotExist()
23 23
     {
24
+        $this->expectException('\Twig\Error\LoaderError');
25
+
24 26
         $loader = new ArrayLoader([]);
25 27
 
26 28
         $loader->getSourceContext('foo');
... ...
@@ -55,11 +57,10 @@ class ArrayTest extends TestCase
55 57
         $this->assertEquals('foo:__bar', $loader->getCacheKey('foo'));
56 58
     }
57 59
 
58
-    /**
59
-     * @expectedException \Twig\Error\LoaderError
60
-     */
61 60
     public function testGetCacheKeyWhenTemplateDoesNotExist()
62 61
     {
62
+        $this->expectException('\Twig\Error\LoaderError');
63
+
63 64
         $loader = new ArrayLoader([]);
64 65
 
65 66
         $loader->getCacheKey('foo');
... ...
@@ -79,11 +80,10 @@ class ArrayTest extends TestCase
79 80
         $this->assertTrue($loader->isFresh('foo', time()));
80 81
     }
81 82
 
82
-    /**
83
-     * @expectedException \Twig\Error\LoaderError
84
-     */
85 83
     public function testIsFreshWhenTemplateDoesNotExist()
86 84
     {
85
+        $this->expectException('\Twig\Error\LoaderError');
86
+
87 87
         $loader = new ArrayLoader([]);
88 88
 
89 89
         $loader->isFresh('foo', time());
... ...
@@ -40,11 +40,10 @@ class ChainTest extends TestCase
40 40
         $this->assertNotEquals('baz', $loader->getSourceContext('errors/base.html')->getCode());
41 41
     }
42 42
 
43
-    /**
44
-     * @expectedException \Twig\Error\LoaderError
45
-     */
46 43
     public function testGetSourceContextWhenTemplateDoesNotExist()
47 44
     {
45
+        $this->expectException('\Twig\Error\LoaderError');
46
+
48 47
         $loader = new ChainLoader([]);
49 48
 
50 49
         $loader->getSourceContext('foo');
... ...
@@ -61,11 +60,10 @@ class ChainTest extends TestCase
61 60
         $this->assertEquals('bar:foo', $loader->getCacheKey('bar'));
62 61
     }
63 62
 
64
-    /**
65
-     * @expectedException \Twig\Error\LoaderError
66
-     */
67 63
     public function testGetCacheKeyWhenTemplateDoesNotExist()
68 64
     {
65
+        $this->expectException('\Twig\Error\LoaderError');
66
+
69 67
         $loader = new ChainLoader([]);
70 68
 
71 69
         $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
 
... ...
@@ -22,52 +22,47 @@ class CallTest extends TestCase
22 22
         $this->assertEquals(['U', null], $this->getArguments($node, ['date', ['format' => 'U', 'timestamp' => null]]));
23 23
     }
24 24
 
25
-    /**
26
-     * @expectedException        \Twig\Error\SyntaxError
27
-     * @expectedExceptionMessage Positional arguments cannot be used after named arguments for function "date".
28
-     */
29 25
     public function testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
30 26
     {
27
+        $this->expectException('\Twig\Error\SyntaxError');
28
+        $this->expectExceptionMessage('Positional arguments cannot be used after named arguments for function "date".');
29
+
31 30
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
32 31
         $this->getArguments($node, ['date', ['timestamp' => 123456, 'Y-m-d']]);
33 32
     }
34 33
 
35
-    /**
36
-     * @expectedException        \Twig\Error\SyntaxError
37
-     * @expectedExceptionMessage Argument "format" is defined twice for function "date".
38
-     */
39 34
     public function testGetArgumentsWhenArgumentIsDefinedTwice()
40 35
     {
36
+        $this->expectException('\Twig\Error\SyntaxError');
37
+        $this->expectExceptionMessage('Argument "format" is defined twice for function "date".');
38
+
41 39
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
42 40
         $this->getArguments($node, ['date', ['Y-m-d', 'format' => 'U']]);
43 41
     }
44 42
 
45
-    /**
46
-     * @expectedException        \Twig\Error\SyntaxError
47
-     * @expectedExceptionMessage Unknown argument "unknown" for function "date(format, timestamp)".
48
-     */
49 43
     public function testGetArgumentsWithWrongNamedArgumentName()
50 44
     {
45
+        $this->expectException('\Twig\Error\SyntaxError');
46
+        $this->expectExceptionMessage('Unknown argument "unknown" for function "date(format, timestamp)".');
47
+
51 48
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
52 49
         $this->getArguments($node, ['date', ['Y-m-d', 'timestamp' => null, 'unknown' => '']]);
53 50
     }
54 51
 
55
-    /**
56
-     * @expectedException        \Twig\Error\SyntaxError
57
-     * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)".
58
-     */
59 52
     public function testGetArgumentsWithWrongNamedArgumentNames()
60 53
     {
54
+        $this->expectException('\Twig\Error\SyntaxError');
55
+        $this->expectExceptionMessage('Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)".');
56
+
61 57
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'date']);
62 58
         $this->getArguments($node, ['date', ['Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => '']]);
63 59
     }
64 60
 
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 61
     public function testResolveArgumentsWithMissingValueForOptionalArgument()
70 62
     {
63
+        $this->expectException('\Twig\Error\SyntaxError');
64
+        $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".');
65
+
71 66
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'substr_compare']);
72 67
         $this->getArguments($node, ['substr_compare', ['abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true]]);
73 68
     }
... ...
@@ -85,12 +80,11 @@ class CallTest extends TestCase
85 80
         $this->assertEquals(['arg1'], $this->getArguments($node, [__CLASS__.'::customStaticFunction', ['arg1' => 'arg1']]));
86 81
     }
87 82
 
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 83
     public function testResolveArgumentsWithMissingParameterForArbitraryArguments()
93 84
     {
85
+        $this->expectException('\LogicException');
86
+        $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 = []".');
87
+
94 88
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
95 89
         $this->getArguments($node, [[$this, 'customFunctionWithArbitraryArguments'], []]);
96 90
     }
... ...
@@ -115,22 +109,20 @@ class CallTest extends TestCase
115 109
     {
116 110
     }
117 111
 
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 112
     public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
123 113
     {
114
+        $this->expectException('\LogicException');
115
+        $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 \\= \\[\\]"\\.$#');
116
+
124 117
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
125 118
         $node->getArguments('Twig\Tests\Node\Expression\custom_Twig_Tests_Node_Expression_CallTest_function', []);
126 119
     }
127 120
 
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 121
     public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
133 122
     {
123
+        $this->expectException('\LogicException');
124
+        $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 \\= \\[\\]"\\.$#');
125
+
134 126
         $node = new Node_Expression_Call([], ['type' => 'function', 'name' => 'foo', 'is_variadic' => true]);
135 127
         $node->getArguments(new CallableTestClass(), []);
136 128
     }
... ...
@@ -106,12 +106,11 @@ class FilterTest extends NodeTestCase
106 106
         return $tests;
107 107
     }
108 108
 
109
-    /**
110
-     * @expectedException        \Twig\Error\SyntaxError
111
-     * @expectedExceptionMessage Unknown argument "foobar" for filter "date(format, timezone)" at line 1.
112
-     */
113 109
     public function testCompileWithWrongNamedArgumentName()
114 110
     {
111
+        $this->expectException('\Twig\Error\SyntaxError');
112
+        $this->expectExceptionMessage('Unknown argument "foobar" for filter "date(format, timezone)" at line 1.');
113
+
115 114
         $date = new ConstantExpression(0, 1);
116 115
         $node = $this->createFilter($date, 'date', [
117 116
             'foobar' => new ConstantExpression('America/Chicago', 1),
... ...
@@ -121,12 +120,11 @@ class FilterTest extends NodeTestCase
121 120
         $compiler->compile($node);
122 121
     }
123 122
 
124
-    /**
125
-     * @expectedException        \Twig\Error\SyntaxError
126
-     * @expectedExceptionMessage Value for argument "from" is required for filter "replace" at line 1.
127
-     */
128 123
     public function testCompileWithMissingNamedArgument()
129 124
     {
125
+        $this->expectException('\Twig\Error\SyntaxError');
126
+        $this->expectExceptionMessage('Value for argument "from" is required for filter "replace" at line 1.');
127
+
130 128
         $value = new ConstantExpression(0, 1);
131 129
         $node = $this->createFilter($value, 'replace', [
132 130
             'to' => new ConstantExpression('foo', 1),
... ...
@@ -31,6 +31,9 @@ class ParserTest extends TestCase
31 31
      */
32 32
     public function testUnknownTag()
33 33
     {
34
+        $this->expectException('\Twig\Error\SyntaxError');
35
+        $this->expectExceptionMessage('Unknown "foo" tag. Did you mean "for" at line 1?');
36
+
34 37
         $stream = new TokenStream([
35 38
             new Token(Token::BLOCK_START_TYPE, '', 1),
36 39
             new Token(Token::NAME_TYPE, 'foo', 1),
... ...
@@ -41,12 +44,11 @@ class ParserTest extends TestCase
41 44
         $parser->parse($stream);
42 45
     }
43 46
 
44
-    /**
45
-     * @expectedException        \Twig\Error\SyntaxError
46
-     * @expectedExceptionMessage Unknown "foobar" tag at line 1.
47
-     */
48 47
     public function testUnknownTagWithoutSuggestions()
49 48
     {
49
+        $this->expectException('\Twig\Error\SyntaxError');
50
+        $this->expectExceptionMessage('Unknown "foobar" tag at line 1.');
51
+
50 52
         $stream = new TokenStream([
51 53
             new Token(Token::BLOCK_START_TYPE, '', 1),
52 54
             new Token(Token::NAME_TYPE, 'foobar', 1),
... ...
@@ -89,10 +91,11 @@ class ParserTest extends TestCase
89 91
 
90 92
     /**
91 93
      * @dataProvider getFilterBodyNodesDataThrowsException
92
-     * @expectedException \Twig\Error\SyntaxError
93 94
      */
94 95
     public function testFilterBodyNodesThrowsException($input)
95 96
     {
97
+        $this->expectException('\Twig\Error\SyntaxError');
98
+
96 99
         $parser = $this->getParser();
97 100
 
98 101
         $m = new \ReflectionMethod($parser, 'filterBodyNodes');
... ...
@@ -23,11 +23,10 @@ use Twig\Template;
23 23
 
24 24
 class TemplateTest extends TestCase
25 25
 {
26
-    /**
27
-     * @expectedException \LogicException
28
-     */
29 26
     public function testDisplayBlocksAcceptTemplateOnlyAsBlocks()
30 27
     {
28
+        $this->expectException('\LogicException');
29
+
31 30
         $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock());
32 31
         $template = new TemplateForTest($twig);
33 32
         $template->displayBlock('foo', [], ['foo' => [new \stdClass(), 'foo']]);
... ...
@@ -108,7 +107,7 @@ class TemplateTest extends TestCase
108 107
                 $this->addToAssertionCount(1);
109 108
             }
110 109
 
111
-            $this->assertContains('is not allowed', $e->getMessage());
110
+            $this->assertStringContainsString('is not allowed', $e->getMessage());
112 111
         }
113 112
     }
114 113
 
... ...
@@ -209,13 +208,9 @@ class TemplateTest extends TestCase
209 208
         if ($defined) {
210 209
             $this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
211 210
         } else {
212
-            if (method_exists($this, 'expectException')) {
213
-                $this->expectException(RuntimeError::class);
214
-                if (null !== $exceptionMessage) {
215
-                    $this->expectExceptionMessage($exceptionMessage);
216
-                }
217
-            } else {
218
-                $this->setExpectedException(RuntimeError::class, $exceptionMessage);
211
+            $this->expectException(RuntimeError::class);
212
+            if (null !== $exceptionMessage) {
213
+                $this->expectExceptionMessage($exceptionMessage);
219 214
             }
220 215
             $this->assertEquals($value, twig_get_attribute($twig, $template->getSourceContext(), $object, $item, $arguments, $type));
221 216
         }
... ...
@@ -389,12 +384,10 @@ class TemplateTest extends TestCase
389 384
         return $tests;
390 385
     }
391 386
 
392
-    /**
393
-     * @expectedException \Twig\Error\RuntimeError
394
-     */
395 387
     public function testGetIsMethods()
396 388
     {
397
-        $twig = new Environment($this->getMockBuilder(LoaderInterface::class)->getMock(), ['strict_variables' => true]);
389
+        $this->expectException('\Twig\Error\RuntimeError');
390
+
398 391
         $getIsObject = new TemplateGetIsMethods();
399 392
         $template = new TemplateForTest($twig, 'index.twig');
400 393
         // first time should not create a cache for "get"
... ...
@@ -45,12 +45,11 @@ class TokenStreamTest extends TestCase
45 45
         $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token');
46 46
     }
47 47
 
48
-    /**
49
-     * @expectedException        \Twig\Error\SyntaxError
50
-     * @expectedExceptionMessage Unexpected end of template
51
-     */
52 48
     public function testEndOfTemplateNext()
53 49
     {
50
+        $this->expectException('\Twig\Error\SyntaxError');
51
+        $this->expectExceptionMessage('Unexpected end of template');
52
+
54 53
         $stream = new TokenStream([
55 54
             new Token(Token::BLOCK_START_TYPE, 1, 1),
56 55
         ]);
... ...
@@ -59,12 +58,11 @@ class TokenStreamTest extends TestCase
59 58
         }
60 59
     }
61 60
 
62
-    /**
63
-     * @expectedException        \Twig\Error\SyntaxError
64
-     * @expectedExceptionMessage Unexpected end of template
65
-     */
66 61
     public function testEndOfTemplateLook()
67 62
     {
63
+        $this->expectException('\Twig\Error\SyntaxError');
64
+        $this->expectExceptionMessage('Unexpected end of template');
65
+
68 66
         $stream = new TokenStream([
69 67
             new Token(Token::BLOCK_START_TYPE, 1, 1),
70 68
         ]);