Skip to content

Commit

Permalink
Merge branch '5.1' into 5.2
Browse files Browse the repository at this point in the history
* 5.1:
  Use createMock() and use import instead of FQCN
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
2 parents 080877a + 13a16b1 commit 7bf30a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
13 changes: 8 additions & 5 deletions Tests/ExpressionLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,20 @@
namespace Symfony\Component\ExpressionLanguage\Tests;

use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\ExpressionLanguage\ParsedExpression;
use Symfony\Component\ExpressionLanguage\SyntaxError;
use Symfony\Component\ExpressionLanguage\Tests\Fixtures\TestProvider;

class ExpressionLanguageTest extends TestCase
{
public function testCachedParse()
{
$cacheMock = $this->getMockBuilder(\Psr\Cache\CacheItemPoolInterface::class)->getMock();
$cacheItemMock = $this->getMockBuilder(\Psr\Cache\CacheItemInterface::class)->getMock();
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
$cacheItemMock = $this->createMock(CacheItemInterface::class);
$savedParsedExpression = null;
$expressionLanguage = new ExpressionLanguage($cacheMock);

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

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

public function testCachingWithDifferentNamesOrder()
{
$cacheMock = $this->getMockBuilder(\Psr\Cache\CacheItemPoolInterface::class)->getMock();
$cacheItemMock = $this->getMockBuilder(\Psr\Cache\CacheItemInterface::class)->getMock();
$cacheMock = $this->createMock(CacheItemPoolInterface::class);
$cacheItemMock = $this->createMock(CacheItemInterface::class);
$expressionLanguage = new ExpressionLanguage($cacheMock);
$savedParsedExpression = null;

Expand Down
5 changes: 3 additions & 2 deletions Tests/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\ExpressionLanguage\Lexer;
use Symfony\Component\ExpressionLanguage\SyntaxError;
use Symfony\Component\ExpressionLanguage\Token;
use Symfony\Component\ExpressionLanguage\TokenStream;

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

public function testTokenizeThrowsErrorWithMessage()
{
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unexpected character "\'" around position 33 for expression `service(faulty.expression.example\').dummyMethod()`.');
$expression = "service(faulty.expression.example').dummyMethod()";
$this->lexer->tokenize($expression);
}

public function testTokenizeThrowsErrorOnUnclosedBrace()
{
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Unclosed "(" around position 7 for expression `service(unclosed.expression.dummyMethod()`.');
$expression = 'service(unclosed.expression.dummyMethod()';
$this->lexer->tokenize($expression);
Expand Down
8 changes: 4 additions & 4 deletions Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ParserTest extends TestCase
{
public function testParseWithInvalidName()
{
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Variable "foo" is not valid around position 1 for expression `foo`.');
$lexer = new Lexer();
$parser = new Parser([]);
Expand All @@ -30,7 +30,7 @@ public function testParseWithInvalidName()

public function testParseWithZeroInNames()
{
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Variable "foo" is not valid around position 1 for expression `foo`.');
$lexer = new Lexer();
$parser = new Parser([]);
Expand Down Expand Up @@ -198,7 +198,7 @@ private function createGetAttrNode($node, $item, $type)
*/
public function testParseWithInvalidPostfixData($expr, $names = [])
{
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
$this->expectException(SyntaxError::class);
$lexer = new Lexer();
$parser = new Parser([]);
$parser->parse($lexer->tokenize($expr), $names);
Expand Down Expand Up @@ -228,7 +228,7 @@ public function getInvalidPostfixData()

public function testNameProposal()
{
$this->expectException(\Symfony\Component\ExpressionLanguage\SyntaxError::class);
$this->expectException(SyntaxError::class);
$this->expectExceptionMessage('Did you mean "baz"?');
$lexer = new Lexer();
$parser = new Parser([]);
Expand Down

0 comments on commit 7bf30a4

Please sign in to comment.