Skip to content

[Translation] deprecate the ProviderFactoryTestCase #58352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions UPGRADE-7.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ String
Translation
-----------

* Deprecate `ProviderFactoryTestCase`, extend `AbstractTransportFactoryTestCase` instead

The `testIncompleteDsnException()` test is no longer provided by default. If you make use of it by implementing the `incompleteDsnProvider()` data providers,
you now need to use the `IncompleteDsnTestTrait`.

* Deprecate passing an escape character to `CsvFileLoader::setCsvControl()`

TwigBridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@

namespace Symfony\Component\Translation\Bridge\Crowdin\Tests;

use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Translation\Bridge\Crowdin\CrowdinProviderFactory;
use Symfony\Component\Translation\Dumper\XliffFileDumper;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\ProviderFactoryInterface;
use Symfony\Component\Translation\Test\ProviderFactoryTestCase;
use Symfony\Component\Translation\Test\AbstractProviderFactoryTestCase;
use Symfony\Component\Translation\Test\IncompleteDsnTestTrait;

class CrowdinProviderFactoryTest extends ProviderFactoryTestCase
class CrowdinProviderFactoryTest extends AbstractProviderFactoryTestCase
{
use IncompleteDsnTestTrait;

public static function supportsProvider(): iterable
{
yield [true, 'crowdin://PROJECT_ID:API_TOKEN@default'];
Expand Down Expand Up @@ -48,6 +55,6 @@ public static function incompleteDsnProvider(): iterable

public function createFactory(): ProviderFactoryInterface
{
return new CrowdinProviderFactory($this->getClient(), $this->getLogger(), $this->getDefaultLocale(), $this->getLoader(), $this->getXliffFileDumper());
return new CrowdinProviderFactory(new MockHttpClient(), new NullLogger(), 'en', $this->createMock(LoaderInterface::class), $this->createMock(XliffFileDumper::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"php": ">=8.2",
"symfony/config": "^6.4|^7.0",
"symfony/http-client": "^6.4|^7.0",
"symfony/translation": "^6.4|^7.0"
"symfony/translation": "^7.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Translation\\Bridge\\Crowdin\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@

namespace Symfony\Component\Translation\Bridge\Loco\Tests;

use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\ProviderFactoryInterface;
use Symfony\Component\Translation\Test\ProviderFactoryTestCase;
use Symfony\Component\Translation\Test\AbstractProviderFactoryTestCase;
use Symfony\Component\Translation\Test\IncompleteDsnTestTrait;
use Symfony\Component\Translation\TranslatorBagInterface;

class LocoProviderFactoryTest extends ProviderFactoryTestCase
class LocoProviderFactoryTest extends AbstractProviderFactoryTestCase
{
use IncompleteDsnTestTrait;

public static function supportsProvider(): iterable
{
yield [true, 'loco://API_KEY@default'];
Expand Down Expand Up @@ -48,6 +55,6 @@ public static function incompleteDsnProvider(): iterable

public function createFactory(): ProviderFactoryInterface
{
return new LocoProviderFactory($this->getClient(), $this->getLogger(), $this->getDefaultLocale(), $this->getLoader(), $this->getTranslatorBag());
return new LocoProviderFactory(new MockHttpClient(), new NullLogger(), 'en', $this->createMock(LoaderInterface::class), $this->createMock(TranslatorBagInterface::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@

namespace Symfony\Component\Translation\Bridge\Loco\Tests;

use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Translation\Bridge\Loco\LocoProviderFactory;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\ProviderFactoryInterface;

class LocoProviderFactoryWithoutTranslatorBagTest extends LocoProviderFactoryTest
{
public function createFactory(): ProviderFactoryInterface
{
return new LocoProviderFactory($this->getClient(), $this->getLogger(), $this->getDefaultLocale(), $this->getLoader(), null);
return new LocoProviderFactory(new MockHttpClient(), new NullLogger(), 'en', $this->createMock(LoaderInterface::class), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/config": "^6.4|^7.0",
"symfony/translation": "^6.4|^7.0"
"symfony/translation": "^7.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Translation\\Bridge\\Loco\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@

namespace Symfony\Component\Translation\Bridge\Lokalise\Tests;

use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\JsonMockResponse;
use Symfony\Component\Translation\Bridge\Lokalise\LokaliseProviderFactory;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\Dsn;
use Symfony\Component\Translation\Provider\ProviderFactoryInterface;
use Symfony\Component\Translation\Test\ProviderFactoryTestCase;
use Symfony\Component\Translation\Test\AbstractProviderFactoryTestCase;
use Symfony\Component\Translation\Test\IncompleteDsnTestTrait;

class LokaliseProviderFactoryTest extends ProviderFactoryTestCase
class LokaliseProviderFactoryTest extends AbstractProviderFactoryTestCase
{
use IncompleteDsnTestTrait;

public static function supportsProvider(): iterable
{
yield [true, 'lokalise://PROJECT_ID:API_KEY@default'];
Expand Down Expand Up @@ -48,7 +53,7 @@ public function testBaseUri()
{
$response = new JsonMockResponse(['files' => []]);
$httpClient = new MockHttpClient([$response]);
$factory = new LokaliseProviderFactory($httpClient, $this->getLogger(), $this->getDefaultLocale(), $this->getLoader());
$factory = new LokaliseProviderFactory($httpClient, new NullLogger(), 'en', $this->createMock(LoaderInterface::class));
$provider = $factory->create(new Dsn('lokalise://PROJECT_ID:API_KEY@default'));

// Make a real HTTP request.
Expand All @@ -59,6 +64,6 @@ public function testBaseUri()

public function createFactory(): ProviderFactoryInterface
{
return new LokaliseProviderFactory($this->getClient(), $this->getLogger(), $this->getDefaultLocale(), $this->getLoader());
return new LokaliseProviderFactory(new MockHttpClient(), new NullLogger(), 'en', $this->createMock(LoaderInterface::class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"php": ">=8.2",
"symfony/config": "^6.4|^7.0",
"symfony/http-client": "^6.4|^7.0",
"symfony/translation": "^6.4|^7.0"
"symfony/translation": "^7.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Translation\\Bridge\\Lokalise\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,79 +12,31 @@
namespace Symfony\Component\Translation\Bridge\Phrase\Tests;

use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\Translation\Bridge\Phrase\PhraseProviderFactory;
use Symfony\Component\Translation\Dumper\XliffFileDumper;
use Symfony\Component\Translation\Exception\IncompleteDsnException;
use Symfony\Component\Translation\Exception\MissingRequiredOptionException;
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Translation\Provider\Dsn;
use Symfony\Component\Translation\Test\AbstractProviderFactoryTestCase;
use Symfony\Component\Translation\Test\IncompleteDsnTestTrait;

/**
* @author wicliff <wicliff.wolda@gmail.com>
*/
class PhraseProviderFactoryTest extends TestCase
class PhraseProviderFactoryTest extends AbstractProviderFactoryTestCase
{
use IncompleteDsnTestTrait;

private MockObject&MockHttpClient $httpClient;
private MockObject&LoggerInterface $logger;
private MockObject&LoaderInterface $loader;
private MockObject&XliffFileDumper $xliffFileDumper;
private MockObject&CacheItemPoolInterface $cache;
private string $defaultLocale;

/**
* @dataProvider supportsProvider
*/
public function testSupports(bool $expected, string $dsn)
{
$factory = $this->createFactory();

$this->assertSame($expected, $factory->supports(new Dsn($dsn)));
}

/**
* @dataProvider createProvider
*/
public function testCreate(string $expected, string $dsn)
{
$factory = $this->createFactory();
$provider = $factory->create(new Dsn($dsn));

$this->assertSame($expected, (string) $provider);
}

/**
* @dataProvider unsupportedSchemeProvider
*/
public function testUnsupportedSchemeException(string $dsn, string $message)
{
$factory = $this->createFactory();
$dsn = new Dsn($dsn);

$this->expectException(UnsupportedSchemeException::class);
$this->expectExceptionMessage($message);

$factory->create($dsn);
}

/**
* @dataProvider incompleteDsnProvider
*/
public function testIncompleteDsnException(string $dsn, string $message)
{
$factory = $this->createFactory();
$dsn = new Dsn($dsn);

$this->expectException(IncompleteDsnException::class);
$this->expectExceptionMessage($message);

$factory->create($dsn);
}

public function testRequiredUserAgentOption()
{
$factory = $this->createFactory();
Expand Down Expand Up @@ -144,7 +96,7 @@ public static function supportsProvider(): \Generator
yield 'not supported' => [false, 'unsupported://PROJECT_ID:API_TOKEN@default?userAgent=myProject'];
}

private function createFactory(): PhraseProviderFactory
public function createFactory(): PhraseProviderFactory
{
return new PhraseProviderFactory(
$this->getHttpClient(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"psr/cache": "^3.0",
"symfony/http-client": "^6.4|^7.0",
"symfony/mime": "^6.4|^7.0",
"symfony/translation": "^6.4|^7.0"
"symfony/translation": "^7.2"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Translation\\Bridge\\Phrase\\": "" },
Expand Down
5 changes: 5 additions & 0 deletions src/Symfony/Component/Translation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ CHANGELOG
7.2
---

* Deprecate `ProviderFactoryTestCase`, extend `AbstractTransportFactoryTestCase` instead

The `testIncompleteDsnException()` test is no longer provided by default. If you make use of it by implementing the `incompleteDsnProvider()` data providers,
you now need to use the `IncompleteDsnTestTrait`.

* Make `ProviderFactoryTestCase` and `ProviderTestCase` compatible with PHPUnit 10+
* Add `lint:translations` command
* Deprecate passing an escape character to `CsvFileLoader::setCsvControl()`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Translation\Test;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Translation\Exception\UnsupportedSchemeException;
use Symfony\Component\Translation\Provider\Dsn;
use Symfony\Component\Translation\Provider\ProviderFactoryInterface;

abstract class AbstractProviderFactoryTestCase extends TestCase
{
abstract public function createFactory(): ProviderFactoryInterface;

/**
* @return iterable<array{0: bool, 1: string}>
*/
abstract public static function supportsProvider(): iterable;

/**
* @return iterable<array{0: string, 1: string}>
*/
abstract public static function createProvider(): iterable;

/**
* @return iterable<array{0: string, 1?: string|null}>
*/
abstract public static function unsupportedSchemeProvider(): iterable;

/**
* @dataProvider supportsProvider
*/
#[DataProvider('supportsProvider')]

Check failure on line 42 in src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php:42:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)

Check failure on line 42 in src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php:42:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)
public function testSupports(bool $expected, string $dsn)
{
$factory = $this->createFactory();

$this->assertSame($expected, $factory->supports(new Dsn($dsn)));
}

/**
* @dataProvider createProvider
*/
#[DataProvider('createProvider')]

Check failure on line 53 in src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php:53:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)

Check failure on line 53 in src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php:53:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)
public function testCreate(string $expected, string $dsn)
{
$factory = $this->createFactory();
$provider = $factory->create(new Dsn($dsn));

$this->assertSame($expected, (string) $provider);
}

/**
* @dataProvider unsupportedSchemeProvider
*/
#[DataProvider('unsupportedSchemeProvider')]

Check failure on line 65 in src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php:65:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)

Check failure on line 65 in src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/AbstractProviderFactoryTestCase.php:65:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)
public function testUnsupportedSchemeException(string $dsn, ?string $message = null)
{
$factory = $this->createFactory();

$dsn = new Dsn($dsn);

$this->expectException(UnsupportedSchemeException::class);
if (null !== $message) {
$this->expectExceptionMessage($message);
}

$factory->create($dsn);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\Translation\Test;

use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\Translation\Exception\IncompleteDsnException;
use Symfony\Component\Translation\Provider\Dsn;

trait IncompleteDsnTestTrait
{
/**
* @return iterable<array{0: string, 1?: string|null}>
*/
abstract public static function incompleteDsnProvider(): iterable;

/**
* @dataProvider incompleteDsnProvider
*/
#[DataProvider('incompleteDsnProvider')]

Check failure on line 28 in src/Symfony/Component/Translation/Test/IncompleteDsnTestTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/IncompleteDsnTestTrait.php:28:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)

Check failure on line 28 in src/Symfony/Component/Translation/Test/IncompleteDsnTestTrait.php

View workflow job for this annotation

GitHub Actions / Psalm

UndefinedAttributeClass

src/Symfony/Component/Translation/Test/IncompleteDsnTestTrait.php:28:7: UndefinedAttributeClass: Attribute class PHPUnit\Framework\Attributes\DataProvider does not exist (see https://psalm.dev/241)
public function testIncompleteDsnException(string $dsn, ?string $message = null)
{
$factory = $this->createFactory();

$dsn = new Dsn($dsn);

$this->expectException(IncompleteDsnException::class);
if (null !== $message) {
$this->expectExceptionMessage($message);
}

$factory->create($dsn);
}
}
Loading
Loading