Skip to content

Commit 3f75681

Browse files
committed
Fix deprecated phpunit annotation
1 parent 7cd0095 commit 3f75681

File tree

4 files changed

+33
-44
lines changed

4 files changed

+33
-44
lines changed

Tests/ExpressionFunctionTest.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\ExpressionLanguage\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
1617

1718
/**
@@ -21,21 +22,19 @@
2122
*/
2223
class ExpressionFunctionTest extends TestCase
2324
{
24-
/**
25-
* @expectedException \InvalidArgumentException
26-
* @expectedExceptionMessage PHP function "fn_does_not_exist" does not exist.
27-
*/
25+
use ForwardCompatTestTrait;
26+
2827
public function testFunctionDoesNotExist()
2928
{
29+
$this->expectException('InvalidArgumentException');
30+
$this->expectExceptionMessage('PHP function "fn_does_not_exist" does not exist.');
3031
ExpressionFunction::fromPhp('fn_does_not_exist');
3132
}
3233

33-
/**
34-
* @expectedException \InvalidArgumentException
35-
* @expectedExceptionMessage An expression function name must be defined when PHP function "Symfony\Component\ExpressionLanguage\Tests\fn_namespaced" is namespaced.
36-
*/
3734
public function testFunctionNamespaced()
3835
{
36+
$this->expectException('InvalidArgumentException');
37+
$this->expectExceptionMessage('An expression function name must be defined when PHP function "Symfony\Component\ExpressionLanguage\Tests\fn_namespaced" is namespaced.');
3938
ExpressionFunction::fromPhp('Symfony\Component\ExpressionLanguage\Tests\fn_namespaced');
4039
}
4140
}

Tests/ExpressionLanguageTest.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@
1212
namespace Symfony\Component\ExpressionLanguage\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
1617
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1718
use Symfony\Component\ExpressionLanguage\ParsedExpression;
1819
use Symfony\Component\ExpressionLanguage\Tests\Fixtures\TestProvider;
1920

2021
class ExpressionLanguageTest extends TestCase
2122
{
23+
use ForwardCompatTestTrait;
24+
2225
public function testCachedParse()
2326
{
2427
$cacheMock = $this->getMockBuilder('Psr\Cache\CacheItemPoolInterface')->getMock();
@@ -94,12 +97,10 @@ public function testCachedParseWithDeprecatedParserCacheInterface()
9497
$this->assertSame($savedParsedExpression, $parsedExpression);
9598
}
9699

97-
/**
98-
* @expectedException \InvalidArgumentException
99-
* @expectedExceptionMessage Cache argument has to implement Psr\Cache\CacheItemPoolInterface.
100-
*/
101100
public function testWrongCacheImplementation()
102101
{
102+
$this->expectException('InvalidArgumentException');
103+
$this->expectExceptionMessage('Cache argument has to implement Psr\Cache\CacheItemPoolInterface.');
103104
$cacheMock = $this->getMockBuilder('Psr\Cache\CacheItemSpoolInterface')->getMock();
104105
$expressionLanguage = new ExpressionLanguage($cacheMock);
105106
}
@@ -146,12 +147,10 @@ public function testShortCircuitOperatorsCompile($expression, array $names, $exp
146147
$this->assertSame($expected, $result);
147148
}
148149

149-
/**
150-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
151-
* @expectedExceptionMessage Unexpected end of expression around position 6 for expression `node.`.
152-
*/
153150
public function testParseThrowsInsteadOfNotice()
154151
{
152+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
153+
$this->expectExceptionMessage('Unexpected end of expression around position 6 for expression `node.`.');
155154
$expressionLanguage = new ExpressionLanguage();
156155
$expressionLanguage->parse('node.', ['node']);
157156
}
@@ -240,42 +239,40 @@ public function testCachingWithDifferentNamesOrder()
240239

241240
/**
242241
* @dataProvider getRegisterCallbacks
243-
* @expectedException \LogicException
244242
*/
245243
public function testRegisterAfterParse($registerCallback)
246244
{
245+
$this->expectException('LogicException');
247246
$el = new ExpressionLanguage();
248247
$el->parse('1 + 1', []);
249248
$registerCallback($el);
250249
}
251250

252251
/**
253252
* @dataProvider getRegisterCallbacks
254-
* @expectedException \LogicException
255253
*/
256254
public function testRegisterAfterEval($registerCallback)
257255
{
256+
$this->expectException('LogicException');
258257
$el = new ExpressionLanguage();
259258
$el->evaluate('1 + 1');
260259
$registerCallback($el);
261260
}
262261

263-
/**
264-
* @expectedException \RuntimeException
265-
* @expectedExceptionMessageRegExp /Unable to call method "\w+" of object "\w+"./
266-
*/
267262
public function testCallBadCallable()
268263
{
264+
$this->expectException('RuntimeException');
265+
$this->expectExceptionMessageRegExp('/Unable to call method "\w+" of object "\w+"./');
269266
$el = new ExpressionLanguage();
270267
$el->evaluate('foo.myfunction()', ['foo' => new \stdClass()]);
271268
}
272269

273270
/**
274271
* @dataProvider getRegisterCallbacks
275-
* @expectedException \LogicException
276272
*/
277273
public function testRegisterAfterCompile($registerCallback)
278274
{
275+
$this->expectException('LogicException');
279276
$el = new ExpressionLanguage();
280277
$el->compile('1 + 1');
281278
$registerCallback($el);

Tests/LexerTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,22 +40,18 @@ public function testTokenize($tokens, $expression)
4040
$this->assertEquals(new TokenStream($tokens, $expression), $this->lexer->tokenize($expression));
4141
}
4242

43-
/**
44-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
45-
* @expectedExceptionMessage Unexpected character "'" around position 33 for expression `service(faulty.expression.example').dummyMethod()`.
46-
*/
4743
public function testTokenizeThrowsErrorWithMessage()
4844
{
45+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
46+
$this->expectExceptionMessage('Unexpected character "\'" around position 33 for expression `service(faulty.expression.example\').dummyMethod()`.');
4947
$expression = "service(faulty.expression.example').dummyMethod()";
5048
$this->lexer->tokenize($expression);
5149
}
5250

53-
/**
54-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
55-
* @expectedExceptionMessage Unclosed "(" around position 7 for expression `service(unclosed.expression.dummyMethod()`.
56-
*/
5751
public function testTokenizeThrowsErrorOnUnclosedBrace()
5852
{
53+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
54+
$this->expectExceptionMessage('Unclosed "(" around position 7 for expression `service(unclosed.expression.dummyMethod()`.');
5955
$expression = 'service(unclosed.expression.dummyMethod()';
6056
$this->lexer->tokenize($expression);
6157
}

Tests/ParserTest.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,28 @@
1212
namespace Symfony\Component\ExpressionLanguage\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Symfony\Bridge\PhpUnit\ForwardCompatTestTrait;
1516
use Symfony\Component\ExpressionLanguage\Lexer;
1617
use Symfony\Component\ExpressionLanguage\Node;
1718
use Symfony\Component\ExpressionLanguage\Parser;
1819

1920
class ParserTest extends TestCase
2021
{
21-
/**
22-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
23-
* @expectedExceptionMessage Variable "foo" is not valid around position 1 for expression `foo`.
24-
*/
22+
use ForwardCompatTestTrait;
23+
2524
public function testParseWithInvalidName()
2625
{
26+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
27+
$this->expectExceptionMessage('Variable "foo" is not valid around position 1 for expression `foo`.');
2728
$lexer = new Lexer();
2829
$parser = new Parser([]);
2930
$parser->parse($lexer->tokenize('foo'));
3031
}
3132

32-
/**
33-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
34-
* @expectedExceptionMessage Variable "foo" is not valid around position 1 for expression `foo`.
35-
*/
3633
public function testParseWithZeroInNames()
3734
{
35+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
36+
$this->expectExceptionMessage('Variable "foo" is not valid around position 1 for expression `foo`.');
3837
$lexer = new Lexer();
3938
$parser = new Parser([]);
4039
$parser->parse($lexer->tokenize('foo'), [0]);
@@ -165,10 +164,10 @@ private function createGetAttrNode($node, $item, $type)
165164

166165
/**
167166
* @dataProvider getInvalidPostfixData
168-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
169167
*/
170168
public function testParseWithInvalidPostfixData($expr, $names = [])
171169
{
170+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
172171
$lexer = new Lexer();
173172
$parser = new Parser([]);
174173
$parser->parse($lexer->tokenize($expr), $names);
@@ -196,12 +195,10 @@ public function getInvalidPostfixData()
196195
];
197196
}
198197

199-
/**
200-
* @expectedException \Symfony\Component\ExpressionLanguage\SyntaxError
201-
* @expectedExceptionMessage Did you mean "baz"?
202-
*/
203198
public function testNameProposal()
204199
{
200+
$this->expectException('Symfony\Component\ExpressionLanguage\SyntaxError');
201+
$this->expectExceptionMessage('Did you mean "baz"?');
205202
$lexer = new Lexer();
206203
$parser = new Parser([]);
207204

0 commit comments

Comments
 (0)