Skip to content

Commit 066402a

Browse files
OskarStarknicolas-grekas
authored andcommitted
Use createMock() and use import instead of FQCN
1 parent 66e8566 commit 066402a

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Tests/ExpressionLanguageTest.php

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

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Cache\CacheItemInterface;
16+
use Psr\Cache\CacheItemPoolInterface;
1517
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
1618
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1719
use Symfony\Component\ExpressionLanguage\ParsedExpression;
20+
use Symfony\Component\ExpressionLanguage\SyntaxError;
1821
use Symfony\Component\ExpressionLanguage\Tests\Fixtures\TestProvider;
1922

2023
class ExpressionLanguageTest extends TestCase
2124
{
2225
public function testCachedParse()
2326
{
24-
$cacheMock = $this->getMockBuilder(\Psr\Cache\CacheItemPoolInterface::class)->getMock();
25-
$cacheItemMock = $this->getMockBuilder(\Psr\Cache\CacheItemInterface::class)->getMock();
27+
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
28+
$cacheItemMock = $this->createMock(CacheItemInterface::class);
2629
$savedParsedExpression = null;
2730
$expressionLanguage = new ExpressionLanguage($cacheMock);
2831

@@ -107,7 +110,7 @@ public function testShortCircuitOperatorsCompile($expression, array $names, $exp
107110

108111
public function testParseThrowsInsteadOfNotice()
109112
{
110-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
113+
$this->expectException(SyntaxError::class);
111114
$this->expectExceptionMessage('Unexpected end of expression around position 6 for expression `node.`.');
112115
$expressionLanguage = new ExpressionLanguage();
113116
$expressionLanguage->parse('node.', ['node']);
@@ -155,8 +158,8 @@ public function testStrictEquality()
155158

156159
public function testCachingWithDifferentNamesOrder()
157160
{
158-
$cacheMock = $this->getMockBuilder(\Psr\Cache\CacheItemPoolInterface::class)->getMock();
159-
$cacheItemMock = $this->getMockBuilder(\Psr\Cache\CacheItemInterface::class)->getMock();
161+
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
162+
$cacheItemMock = $this->createMock(CacheItemInterface::class);
160163
$expressionLanguage = new ExpressionLanguage($cacheMock);
161164
$savedParsedExpression = null;
162165

Tests/LexerTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\ExpressionLanguage\Lexer;
16+
use Symfony\Component\ExpressionLanguage\SyntaxError;
1617
use Symfony\Component\ExpressionLanguage\Token;
1718
use Symfony\Component\ExpressionLanguage\TokenStream;
1819

@@ -39,15 +40,15 @@ public function testTokenize($tokens, $expression)
3940

4041
public function testTokenizeThrowsErrorWithMessage()
4142
{
42-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
43+
$this->expectException(SyntaxError::class);
4344
$this->expectExceptionMessage('Unexpected character "\'" around position 33 for expression `service(faulty.expression.example\').dummyMethod()`.');
4445
$expression = "service(faulty.expression.example').dummyMethod()";
4546
$this->lexer->tokenize($expression);
4647
}
4748

4849
public function testTokenizeThrowsErrorOnUnclosedBrace()
4950
{
50-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
51+
$this->expectException(SyntaxError::class);
5152
$this->expectExceptionMessage('Unclosed "(" around position 7 for expression `service(unclosed.expression.dummyMethod()`.');
5253
$expression = 'service(unclosed.expression.dummyMethod()';
5354
$this->lexer->tokenize($expression);

Tests/ParserTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
use Symfony\Component\ExpressionLanguage\Lexer;
1616
use Symfony\Component\ExpressionLanguage\Node;
1717
use Symfony\Component\ExpressionLanguage\Parser;
18+
use Symfony\Component\ExpressionLanguage\SyntaxError;
1819

1920
class ParserTest extends TestCase
2021
{
2122
public function testParseWithInvalidName()
2223
{
23-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
24+
$this->expectException(SyntaxError::class);
2425
$this->expectExceptionMessage('Variable "foo" is not valid around position 1 for expression `foo`.');
2526
$lexer = new Lexer();
2627
$parser = new Parser([]);
@@ -29,7 +30,7 @@ public function testParseWithInvalidName()
2930

3031
public function testParseWithZeroInNames()
3132
{
32-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
33+
$this->expectException(SyntaxError::class);
3334
$this->expectExceptionMessage('Variable "foo" is not valid around position 1 for expression `foo`.');
3435
$lexer = new Lexer();
3536
$parser = new Parser([]);
@@ -197,7 +198,7 @@ private function createGetAttrNode($node, $item, $type)
197198
*/
198199
public function testParseWithInvalidPostfixData($expr, $names = [])
199200
{
200-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
201+
$this->expectException(SyntaxError::class);
201202
$lexer = new Lexer();
202203
$parser = new Parser([]);
203204
$parser->parse($lexer->tokenize($expr), $names);
@@ -227,7 +228,7 @@ public function getInvalidPostfixData()
227228

228229
public function testNameProposal()
229230
{
230-
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
231+
$this->expectException(SyntaxError::class);
231232
$this->expectExceptionMessage('Did you mean "baz"?');
232233
$lexer = new Lexer();
233234
$parser = new Parser([]);

0 commit comments

Comments
 (0)