Skip to content

Commit

Permalink
Use ::class
Browse files Browse the repository at this point in the history
  • Loading branch information
franmomu committed Mar 13, 2020
1 parent 3290fbe commit 8960af2
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 38 deletions.
3 changes: 2 additions & 1 deletion Tests/Model/FileSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use JMS\TranslationBundle\Model\FileSource;
use PHPUnit\Framework\TestCase;
use JMS\TranslationBundle\Model\SourceInterface;

class FileSourceTest extends TestCase
{
Expand Down Expand Up @@ -104,7 +105,7 @@ public function getEqualityTests()
false,
];

$source = $this->createMock('JMS\TranslationBundle\Model\SourceInterface');
$source = $this->createMock(SourceInterface::class);
$source
->expects($this->once())
->method('equals')
Expand Down
5 changes: 3 additions & 2 deletions Tests/Model/Message/XliffMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\Message\XliffMessage;
use JMS\TranslationBundle\Tests\Model\MessageTest;
use JMS\TranslationBundle\Model\SourceInterface;

class XliffMessageTest extends MessageTest
{
Expand Down Expand Up @@ -108,13 +109,13 @@ public function testMerge()
$messageWrite = new XliffMessage('foo');
$messageWrite->setDesc('foo');
$messageWrite->setMeaning('foo');
$messageWrite->addSource($s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
$messageWrite->addSource($s1 = $this->createMock(SourceInterface::class));

$messageRead = new XliffMessage('foo');
$messageRead->setDesc('bar');
$messageRead->setApproved(true);
$messageRead->setState(XliffMessage::STATE_TRANSLATED);
$messageRead->addSource($s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
$messageRead->addSource($s2 = $this->createMock(SourceInterface::class));

$messageRead2 = new Message('foo');
$messageRead2->setDesc('bar');
Expand Down
5 changes: 3 additions & 2 deletions Tests/Model/MessageCatalogueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use PHPUnit\Framework\TestCase;
use JMS\TranslationBundle\Model\MessageCollection;

class MessageCatalogueTest extends TestCase
{
Expand Down Expand Up @@ -76,7 +77,7 @@ public function testGetDomain()
$catalogue->add(new Message('foo'));

$col = $catalogue->getDomain('messages');
$this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCollection', $col);
$this->assertInstanceOf(MessageCollection::class, $col);
$this->assertEquals(['foo'], array_keys($col->all()));
}

Expand All @@ -95,7 +96,7 @@ public function testGetDomains()
$cat->add(new Message('foo', 'foo'));

$this->assertEquals(['messages', 'foo'], array_keys($domains = $cat->getDomains()));
$this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCollection', $domains['foo']);
$this->assertInstanceOf(MessageCollection::class, $domains['foo']);
}

public function testMerge()
Expand Down
8 changes: 4 additions & 4 deletions Tests/Model/MessageCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function testAdd()

public function testAddMerges()
{
$m2 = $this->createMock('JMS\TranslationBundle\Model\Message');
$m2 = $this->createMock(Message::class);

$m1 = $this->createMock('JMS\TranslationBundle\Model\Message');
$m1 = $this->createMock(Message::class);
$m1->expects($this->once())
->method('merge')
->with($m2);
Expand Down Expand Up @@ -77,12 +77,12 @@ public function testSet()

public function testSetDoesNotMerge()
{
$m2 = $this->createMock('JMS\TranslationBundle\Model\Message');
$m2 = $this->createMock(Message::class);
$m2
->method('getId')
->willReturn('foo');

$m1 = $this->createMock('JMS\TranslationBundle\Model\Message');
$m1 = $this->createMock(Message::class);
$m1->expects($this->never())
->method('merge');
$m1
Expand Down
21 changes: 11 additions & 10 deletions Tests/Model/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
use JMS\TranslationBundle\Model\FileSource;
use JMS\TranslationBundle\Model\Message;
use PHPUnit\Framework\TestCase;
use JMS\TranslationBundle\Model\SourceInterface;

class MessageTest extends TestCase
{
public function testCreate()
{
$message = Message::create('id', 'foo');

$this->assertInstanceOf('JMS\TranslationBundle\Model\Message', $message);
$this->assertInstanceOf(Message::class, $message);
$this->assertEquals('id', $message->getId());
$this->assertEquals('foo', $message->getDomain());
}
Expand All @@ -39,7 +40,7 @@ public function testForThisFile()
{
$message = Message::forThisFile('foo', 'bar');

$this->assertInstanceOf('JMS\TranslationBundle\Model\Message', $message);
$this->assertInstanceOf(Message::class, $message);
$this->assertEquals('foo', $message->getId());
$this->assertEquals('bar', $message->getDomain());

Expand Down Expand Up @@ -82,9 +83,9 @@ public function testGetSources()
$message = new Message('foo');
$this->assertEquals([], $message->getSources());

$this->assertSame($message, $message->addSource($source = $this->createMock('JMS\TranslationBundle\Model\SourceInterface')));
$this->assertSame($message, $message->addSource($source = $this->createMock(SourceInterface::class)));
$this->assertSame([$source], $message->getSources());
$this->assertSame($message, $message->setSources([$source2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface')]));
$this->assertSame($message, $message->setSources([$source2 = $this->createMock(SourceInterface::class)]));
$this->assertSame([$source2], $message->getSources());
}

Expand All @@ -93,11 +94,11 @@ public function testMerge()
$message = new Message('foo');
$message->setDesc('foo');
$message->setMeaning('foo');
$message->addSource($s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
$message->addSource($s1 = $this->createMock(SourceInterface::class));

$message2 = new Message('foo');
$message2->setDesc('bar');
$message2->addSource($s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
$message2->addSource($s2 = $this->createMock(SourceInterface::class));

$message->merge($message2);

Expand All @@ -111,11 +112,11 @@ public function testMergeRememberDesc()
$message = new Message('foo_id');
$message->setDesc('foo_desc');
$message->setMeaning('foo_meaning');
$message->addSource($s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
$message->addSource($s1 = $this->createMock(SourceInterface::class));

$message2 = new Message('foo_id');
$message2->setMeaning('bar_meaning');
$message2->addSource($s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface'));
$message2->addSource($s2 = $this->createMock(SourceInterface::class));

$message->merge($message2);

Expand Down Expand Up @@ -179,9 +180,9 @@ public function hasSource()
{
$message = new Message('foo');

$s2 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface');
$s2 = $this->createMock(SourceInterface::class);

$s1 = $this->createMock('JMS\TranslationBundle\Model\SourceInterface');
$s1 = $this->createMock(SourceInterface::class);
$s1
->expects($this->once())
->method('equals')
Expand Down
3 changes: 2 additions & 1 deletion Tests/Translation/Dumper/ArrayStructureDumperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use JMS\TranslationBundle\Model\Message;
use JMS\TranslationBundle\Model\MessageCatalogue;
use PHPUnit\Framework\TestCase;
use JMS\TranslationBundle\Translation\Dumper\ArrayStructureDumper;

class ArrayStructureDumperTest extends TestCase
{
Expand Down Expand Up @@ -50,6 +51,6 @@ public function testPathWithSubPath()

private function getDumper()
{
return $this->getMockForAbstractClass('JMS\TranslationBundle\Translation\Dumper\ArrayStructureDumper');
return $this->getMockForAbstractClass(ArrayStructureDumper::class);
}
}
11 changes: 7 additions & 4 deletions Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
use PhpParser\Parser;
use PhpParser\ParserFactory;
use PHPUnit\Framework\TestCase;
use JMS\TranslationBundle\Annotation\Ignore;
use JMS\TranslationBundle\Annotation\Meaning;
use JMS\TranslationBundle\Annotation\Desc;

abstract class BasePhpFileExtractorTest extends TestCase
{
Expand All @@ -43,7 +46,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
}

$lexer = new Lexer();
if (class_exists('PhpParser\ParserFactory')) {
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
Expand All @@ -64,9 +67,9 @@ final protected function getDocParser()
{
$docParser = new DocParser();
$docParser->setImports([
'desc' => 'JMS\TranslationBundle\Annotation\Desc',
'meaning' => 'JMS\TranslationBundle\Annotation\Meaning',
'ignore' => 'JMS\TranslationBundle\Annotation\Ignore',
'desc' => Desc::class,
'meaning' => Meaning::class,
'ignore' => Ignore::class,
]);
$docParser->setIgnoreNotImportedAnnotations(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function extract($file, ?TranslationContainerExtractor $extractor = null
}

$lexer = new Lexer();
if (class_exists('PhpParser\ParserFactory')) {
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function extract($file, ?ValidationExtractor $extractor = null)
}

$lexer = new Lexer();
if (class_exists('PhpParser\ParserFactory')) {
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
Expand Down
9 changes: 6 additions & 3 deletions Tests/Translation/Extractor/FileExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use Twig\Loader\FilesystemLoader;
use JMS\TranslationBundle\Annotation\Ignore;
use JMS\TranslationBundle\Annotation\Meaning;
use JMS\TranslationBundle\Annotation\Desc;

class FileExtractorTest extends TestCase
{
Expand Down Expand Up @@ -106,9 +109,9 @@ private function extract($directory)

$docParser = new DocParser();
$docParser->setImports([
'desc' => 'JMS\TranslationBundle\Annotation\Desc',
'meaning' => 'JMS\TranslationBundle\Annotation\Meaning',
'ignore' => 'JMS\TranslationBundle\Annotation\Ignore',
'desc' => Desc::class,
'meaning' => Meaning::class,
'ignore' => Ignore::class,
]);
$docParser->setIgnoreNotImportedAnnotations(true);

Expand Down
7 changes: 4 additions & 3 deletions Tests/Translation/ExtractorManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Psr\Log\NullLogger;
use Twig\Environment;
use Twig\Loader\ArrayLoader;
use JMS\TranslationBundle\Translation\ExtractorInterface;

class ExtractorManagerTest extends TestCase
{
Expand All @@ -42,14 +43,14 @@ public function testSetEnabledCustomExtractorsThrowsExceptionWhenAliasInvalid()

public function testOnlySomeExtractorsEnabled()
{
$foo = $this->createMock('JMS\TranslationBundle\Translation\ExtractorInterface');
$foo = $this->createMock(ExtractorInterface::class);
$foo
->expects($this->never())
->method('extract');

$catalogue = new MessageCatalogue();
$catalogue->add(new Message('foo'));
$bar = $this->createMock('JMS\TranslationBundle\Translation\ExtractorInterface');
$bar = $this->createMock(ExtractorInterface::class);
$bar
->expects($this->once())
->method('extract')
Expand All @@ -66,7 +67,7 @@ public function testOnlySomeExtractorsEnabled()

public function testReset()
{
$foo = $this->createMock('JMS\TranslationBundle\Translation\ExtractorInterface');
$foo = $this->createMock(ExtractorInterface::class);
$logger = new NullLogger();

$extractor = new FileExtractor(new Environment(new ArrayLoader([])), $logger, []);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Translation/FileWriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@
use JMS\TranslationBundle\Model\MessageCatalogue;
use JMS\TranslationBundle\Translation\FileWriter;
use PHPUnit\Framework\TestCase;
use JMS\TranslationBundle\Translation\Dumper\DumperInterface;

class FileWriterTest extends TestCase
{
public function testCatalogueIsSortedBeforeBeingDumped()
{
$dumper = $this->createMock('JMS\TranslationBundle\Translation\Dumper\DumperInterface');
$dumper = $this->createMock(DumperInterface::class);

$self = $this;
$dumper
Expand Down
5 changes: 3 additions & 2 deletions Tests/Translation/Loader/SymfonyLoaderAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use JMS\TranslationBundle\Translation\Loader\SymfonyLoaderAdapter;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\MessageCatalogue;
use Symfony\Component\Translation\Loader\LoaderInterface;

class SymfonyLoaderAdapterTest extends TestCase
{
Expand All @@ -31,15 +32,15 @@ public function testLoad()
$symfonyCatalogue = new MessageCatalogue('en');
$symfonyCatalogue->add(['foo' => 'bar']);

$symfonyLoader = $this->createMock('Symfony\Component\Translation\Loader\LoaderInterface');
$symfonyLoader = $this->createMock(LoaderInterface::class);
$symfonyLoader->expects($this->once())
->method('load')
->with('foo', 'en', 'messages')
->willReturn($symfonyCatalogue);

$adapter = new SymfonyLoaderAdapter($symfonyLoader);
$bundleCatalogue = $adapter->load('foo', 'en', 'messages');
$this->assertInstanceOf('JMS\TranslationBundle\Model\MessageCatalogue', $bundleCatalogue);
$this->assertInstanceOf(\JMS\TranslationBundle\Model\MessageCatalogue::class, $bundleCatalogue);
$this->assertEquals('en', $bundleCatalogue->getLocale());
$this->assertTrue($bundleCatalogue->hasDomain('messages'));
$this->assertTrue($bundleCatalogue->getDomain('messages')->has('foo'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use PhpParser\NodeVisitor;
use Psr\Log\LoggerInterface;
use Twig\Node\Node as TwigNode;
use Symfony\Component\Security\Core\Exception\AuthenticationException;

class AuthenticationMessagesExtractor implements LoggerAwareInterface, FileVisitorInterface, NodeVisitor
{
Expand Down Expand Up @@ -137,7 +138,7 @@ public function enterNode(Node $node)
}
$ref = new \ReflectionClass($name);

if (!$ref->isSubclassOf('Symfony\Component\Security\Core\Exception\AuthenticationException')
if (!$ref->isSubclassOf(AuthenticationException::class)
&& $ref->name !== 'Symfony\Component\Security\Core\Exception\AuthenticationException') {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion Translation/Extractor/FileExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v
$this->visitors = $visitors;
$this->setLogger($logger);
$lexer = new Lexer();
if (class_exists('PhpParser\ParserFactory')) {
if (class_exists(ParserFactory::class)) {
$factory = new ParserFactory();
$this->phpParser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
} else {
Expand Down
3 changes: 2 additions & 1 deletion Twig/Node/Transchoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Twig\Compiler;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\ArrayExpression;
use JMS\TranslationBundle\Twig\TranslationExtension;

class Transchoice extends AbstractExpression
{
Expand All @@ -34,7 +35,7 @@ public function compile(Compiler $compiler)
$compiler->raw(
sprintf(
'$this->env->getExtension(\'%s\')->%s(',
'JMS\TranslationBundle\Twig\TranslationExtension',
TranslationExtension::class,
'transchoiceWithDefault'
)
);
Expand Down

0 comments on commit 8960af2

Please sign in to comment.