Skip to content

Commit

Permalink
Merge branch '4.4' into 5.1
Browse files Browse the repository at this point in the history
* 4.4:
  Use createMock() and use import instead of FQCN
  • Loading branch information
nicolas-grekas committed Jan 27, 2021
2 parents aaee925 + e1d0c67 commit b16d3e4
Show file tree
Hide file tree
Showing 18 changed files with 78 additions and 51 deletions.
3 changes: 2 additions & 1 deletion Tests/DataCollector/TranslationDataCollectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Symfony\Component\Translation\Tests\DataCollector;

use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\Translation\DataCollector\TranslationDataCollector;
use Symfony\Component\Translation\DataCollectorTranslator;

class TranslationDataCollectorTest extends TestCase
{
protected function setUp(): void
{
if (!class_exists(\Symfony\Component\HttpKernel\DataCollector\DataCollector::class)) {
if (!class_exists(DataCollector::class)) {
$this->markTestSkipped('The "DataCollector" is not available');
}
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/DependencyInjection/TranslationExtractorPassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Translation\DependencyInjection\TranslationExtractorPass;

Expand Down Expand Up @@ -48,7 +49,7 @@ public function testProcessNoDefinitionFound()

public function testProcessMissingAlias()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\RuntimeException::class);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('The alias for the tag "translation.extractor" of service "foo.id" must be set.');
$container = new ContainerBuilder();
$container->register('translation.extractor');
Expand Down
6 changes: 4 additions & 2 deletions Tests/Loader/CsvFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\CsvFileLoader;

class CsvFileLoaderTest extends TestCase
Expand Down Expand Up @@ -41,15 +43,15 @@ public function testLoadDoesNothingIfEmpty()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new CsvFileLoader();
$resource = __DIR__.'/../fixtures/not-exists.csv';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadNonLocalResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new CsvFileLoader();
$resource = 'http://example.com/resources.csv';
$loader->load($resource, 'en', 'domain1');
Expand Down
6 changes: 4 additions & 2 deletions Tests/Loader/IcuDatFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Component\Translation\Tests\Loader;

use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\IcuDatFileLoader;

/**
Expand All @@ -21,7 +23,7 @@ class IcuDatFileLoaderTest extends LocalizedTestCase
{
public function testLoadInvalidResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new IcuDatFileLoader();
$loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted/resources', 'es', 'domain2');
}
Expand Down Expand Up @@ -53,7 +55,7 @@ public function testDatFrenchLoad()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new IcuDatFileLoader();
$loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1');
}
Expand Down
6 changes: 4 additions & 2 deletions Tests/Loader/IcuResFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Component\Translation\Tests\Loader;

use Symfony\Component\Config\Resource\DirectoryResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\IcuResFileLoader;

/**
Expand All @@ -33,14 +35,14 @@ public function testLoad()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new IcuResFileLoader();
$loader->load(__DIR__.'/../fixtures/non-existing.txt', 'en', 'domain1');
}

public function testLoadInvalidResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new IcuResFileLoader();
$loader->load(__DIR__.'/../fixtures/resourcebundle/corrupted', 'en', 'domain1');
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/Loader/IniFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\IniFileLoader;

class IniFileLoaderTest extends TestCase
Expand Down Expand Up @@ -41,7 +42,7 @@ public function testLoadDoesNothingIfEmpty()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new IniFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.ini';
$loader->load($resource, 'en', 'domain1');
Expand Down
6 changes: 4 additions & 2 deletions Tests/Loader/JsonFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\JsonFileLoader;

class JsonFileLoaderTest extends TestCase
Expand Down Expand Up @@ -41,15 +43,15 @@ public function testLoadDoesNothingIfEmpty()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new JsonFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.json';
$loader->load($resource, 'en', 'domain1');
}

public function testParseException()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$this->expectExceptionMessage('Error parsing JSON: Syntax error, malformed JSON');
$loader = new JsonFileLoader();
$resource = __DIR__.'/../fixtures/malformed.json';
Expand Down
6 changes: 4 additions & 2 deletions Tests/Loader/MoFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\MoFileLoader;

class MoFileLoaderTest extends TestCase
Expand Down Expand Up @@ -44,15 +46,15 @@ public function testLoadPlurals()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new MoFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.mo';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadInvalidResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new MoFileLoader();
$resource = __DIR__.'/../fixtures/empty.mo';
$loader->load($resource, 'en', 'domain1');
Expand Down
6 changes: 4 additions & 2 deletions Tests/Loader/PhpFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\PhpFileLoader;

class PhpFileLoaderTest extends TestCase
Expand All @@ -30,15 +32,15 @@ public function testLoad()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new PhpFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.php';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadThrowsAnExceptionIfFileNotLocal()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new PhpFileLoader();
$resource = 'http://example.com/resources.php';
$loader->load($resource, 'en', 'domain1');
Expand Down
3 changes: 2 additions & 1 deletion Tests/Loader/PoFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\PoFileLoader;

class PoFileLoaderTest extends TestCase
Expand Down Expand Up @@ -55,7 +56,7 @@ public function testLoadDoesNothingIfEmpty()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new PoFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.po';
$loader->load($resource, 'en', 'domain1');
Expand Down
10 changes: 6 additions & 4 deletions Tests/Loader/QtFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\QtFileLoader;

class QtFileLoaderTest extends TestCase
Expand All @@ -34,23 +36,23 @@ public function testLoad()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new QtFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.ts';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadNonLocalResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new QtFileLoader();
$resource = 'http://domain1.com/resources.ts';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadInvalidResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new QtFileLoader();
$resource = __DIR__.'/../fixtures/invalid-xml-resources.xlf';
$loader->load($resource, 'en', 'domain1');
Expand All @@ -61,7 +63,7 @@ public function testLoadEmptyResource()
$loader = new QtFileLoader();
$resource = __DIR__.'/../fixtures/empty.xlf';

$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$this->expectExceptionMessage(sprintf('Unable to load "%s".', $resource));

$loader->load($resource, 'en', 'domain1');
Expand Down
14 changes: 8 additions & 6 deletions Tests/Loader/XliffFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\XliffFileLoader;

class XliffFileLoaderTest extends TestCase
Expand Down Expand Up @@ -112,37 +114,37 @@ public function testTargetAttributesAreStoredCorrectly()

public function testLoadInvalidResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new XliffFileLoader();
$loader->load(__DIR__.'/../fixtures/resources.php', 'en', 'domain1');
}

public function testLoadResourceDoesNotValidate()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new XliffFileLoader();
$loader->load(__DIR__.'/../fixtures/non-valid.xlf', 'en', 'domain1');
}

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new XliffFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.xlf';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadThrowsAnExceptionIfFileNotLocal()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new XliffFileLoader();
$resource = 'http://example.com/resources.xlf';
$loader->load($resource, 'en', 'domain1');
}

public function testDocTypeIsNotAllowed()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$this->expectExceptionMessage('Document types are not allowed.');
$loader = new XliffFileLoader();
$loader->load(__DIR__.'/../fixtures/withdoctype.xlf', 'en', 'domain1');
Expand All @@ -153,7 +155,7 @@ public function testParseEmptyFile()
$loader = new XliffFileLoader();
$resource = __DIR__.'/../fixtures/empty.xlf';

$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$this->expectExceptionMessage(sprintf('Unable to load "%s":', $resource));

$loader->load($resource, 'en', 'domain1');
Expand Down
8 changes: 5 additions & 3 deletions Tests/Loader/YamlFileLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\Translation\Exception\InvalidResourceException;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Symfony\Component\Translation\Loader\YamlFileLoader;

class YamlFileLoaderTest extends TestCase
Expand Down Expand Up @@ -41,23 +43,23 @@ public function testLoadDoesNothingIfEmpty()

public function testLoadNonExistingResource()
{
$this->expectException(\Symfony\Component\Translation\Exception\NotFoundResourceException::class);
$this->expectException(NotFoundResourceException::class);
$loader = new YamlFileLoader();
$resource = __DIR__.'/../fixtures/non-existing.yml';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadThrowsAnExceptionIfFileNotLocal()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new YamlFileLoader();
$resource = 'http://example.com/resources.yml';
$loader->load($resource, 'en', 'domain1');
}

public function testLoadThrowsAnExceptionIfNotAnArray()
{
$this->expectException(\Symfony\Component\Translation\Exception\InvalidResourceException::class);
$this->expectException(InvalidResourceException::class);
$loader = new YamlFileLoader();
$resource = __DIR__.'/../fixtures/non-valid.yml';
$loader->load($resource, 'en', 'domain1');
Expand Down
3 changes: 2 additions & 1 deletion Tests/LoggingTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
namespace Symfony\Component\Translation\Tests;

use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\LoggingTranslator;
use Symfony\Component\Translation\Translator;

class LoggingTranslatorTest extends TestCase
{
public function testTransWithNoTranslationIsLogged()
{
$logger = $this->getMockBuilder(\Psr\Log\LoggerInterface::class)->getMock();
$logger = $this->createMock(LoggerInterface::class);
$logger->expects($this->exactly(1))
->method('warning')
->with('Translation not found.')
Expand Down
Loading

0 comments on commit b16d3e4

Please sign in to comment.