Skip to content

Make more data providers static #58323

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 20, 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
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function testCanUseParam()
/**
* @see testCanOnlySetOneParameter
*/
private static function provideMultipleParameters(): iterable
public static function provideMultipleParameters(): iterable
{
yield [['service' => 'id', 'expression' => 'expr']];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testConstructorShouldThrowExceptionForMissingOptions(array $opti
new MongoDbSessionHandler($this->manager, $options);
}

public function provideInvalidOptions()
public static function provideInvalidOptions(): iterable
{
yield 'empty' => [[]];
yield 'collection missing' => [['database' => 'foo']];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function testConstraintSuccess(string $requestUrl, ?string $location, str
self::assertTrue($constraint->evaluate($response, '', true));
}

public function provideSuccessCases(): iterable
public static function provideSuccessCases(): iterable
{
yield ['http://example.com', 'http://example.com', 'http://example.com'];
yield ['http://example.com', 'http://example.com', '//example.com'];
Expand Down Expand Up @@ -112,7 +112,7 @@ public function testConstraintFailure(string $requestUrl, ?string $location, str
$constraint->evaluate($response);
}

public function provideFailureCases(): iterable
public static function provideFailureCases(): iterable
{
yield ['http://example.com', null, 'http://example.com'];
yield ['http://example.com', null, '//example.com'];
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/Mime/Tests/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function testEnsureValidity(array $headers, ?string $exceptionClass, ?str
$m->ensureValidity();
}

public function ensureValidityProvider()
public static function ensureValidityProvider(): array
{
return [
'Valid address fields' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public function testAccessTokenHeaderRegex(string $input, ?string $expectedToken
$this->assertEquals($expectedToken, $token);
}

public function provideAccessTokenHeaderRegex(): array
public static function provideAccessTokenHeaderRegex(): array
{
return [
['Bearer token', 'token'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ class PhraseProviderTest extends TestCase
/**
* @dataProvider toStringProvider
*/
public function testToString(ProviderInterface $provider, string $expected)
public function testToString(?string $endpoint, string $expected)
{
$provider = $this->createProvider(endpoint: $endpoint);

self::assertSame($expected, (string) $provider);
}

Expand Down Expand Up @@ -332,7 +334,7 @@ public function testGetCacheItem(mixed $cachedValue, bool $hasMatchHeader)
$provider->read(['messages'], ['en_GB']);
}

public function cacheItemProvider(): \Generator
public static function cacheItemProvider(): \Generator
{
yield 'null value' => [
'cached_value' => null,
Expand All @@ -347,7 +349,7 @@ public function cacheItemProvider(): \Generator
];
}

public function cacheKeyProvider(): \Generator
public static function cacheKeyProvider(): \Generator
{
yield 'sortorder one' => [
'options' => [
Expand Down Expand Up @@ -787,7 +789,7 @@ public function testWriteProviderExceptions(int $statusCode, string $expectedExc
$provider->write($bag);
}

public function writeProvider(): \Generator
public static function writeProvider(): \Generator
{
$expectedEnglishXliff = <<<'XLIFF'
<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -869,84 +871,66 @@ public function writeProvider(): \Generator
];
}

public function toStringProvider(): \Generator
public static function toStringProvider(): \Generator
{
yield 'default endpoint' => [
'provider' => $this->createProvider(httpClient: $this->getHttpClient()->withOptions([
'base_uri' => 'https://api.phrase.com/api/v2/projects/PROJECT_ID/',
'headers' => [
'Authorization' => 'token API_TOKEN',
'User-Agent' => 'myProject',
],
])),
'endpoint' => null,
'expected' => 'phrase://api.phrase.com',
];

yield 'custom endpoint' => [
'provider' => $this->createProvider(httpClient: $this->getHttpClient()->withOptions([
'base_uri' => 'https://api.us.app.phrase.com/api/v2/projects/PROJECT_ID/',
'headers' => [
'Authorization' => 'token API_TOKEN',
'User-Agent' => 'myProject',
],
]), endpoint: 'api.us.app.phrase.com'),
'endpoint' => 'api.us.app.phrase.com',
'expected' => 'phrase://api.us.app.phrase.com',
];

yield 'custom endpoint with port' => [
'provider' => $this->createProvider(httpClient: $this->getHttpClient()->withOptions([
'base_uri' => 'https://api.us.app.phrase.com:8080/api/v2/projects/PROJECT_ID/',
'headers' => [
'Authorization' => 'token API_TOKEN',
'User-Agent' => 'myProject',
],
]), endpoint: 'api.us.app.phrase.com:8080'),
'endpoint' => 'api.us.app.phrase.com:8080',
'expected' => 'phrase://api.us.app.phrase.com:8080',
];
}

public function deleteExceptionsProvider(): array
public static function deleteExceptionsProvider(): array
{
return $this->getExceptionResponses(
return self::getExceptionResponses(
exceptionMessage: 'Unable to delete key in phrase.',
loggerMessage: 'Unable to delete key "key.to.delete" in phrase: "provider error".',
statusCode: 500
);
}

public function writeExceptionsProvider(): array
public static function writeExceptionsProvider(): array
{
return $this->getExceptionResponses(
return self::getExceptionResponses(
exceptionMessage: 'Unable to upload translations to phrase.',
loggerMessage: 'Unable to upload translations for domain "messages" to phrase: "provider error".'
);
}

public function createLocalesExceptionsProvider(): array
public static function createLocalesExceptionsProvider(): array
{
return $this->getExceptionResponses(
return self::getExceptionResponses(
exceptionMessage: 'Unable to create locale phrase.',
loggerMessage: 'Unable to create locale "nl-NL" in phrase: "provider error".'
);
}

public function initLocalesExceptionsProvider(): array
public static function initLocalesExceptionsProvider(): array
{
return $this->getExceptionResponses(
return self::getExceptionResponses(
exceptionMessage: 'Unable to get locales from phrase.',
loggerMessage: 'Unable to get locales from phrase: "provider error".'
);
}

public function readProviderExceptionsProvider(): array
public static function readProviderExceptionsProvider(): array
{
return $this->getExceptionResponses(
return self::getExceptionResponses(
exceptionMessage: 'Unable to get translations from phrase.',
loggerMessage: 'Unable to get translations for locale "en_GB" from phrase: "provider error".'
);
}

public function readProvider(): \Generator
public static function readProvider(): \Generator
{
$bag = new TranslatorBag();
$catalogue = new MessageCatalogue('en_GB', [
Expand Down Expand Up @@ -1045,7 +1029,7 @@ public function readProvider(): \Generator
];
}

private function getExceptionResponses(string $exceptionMessage, string $loggerMessage, int $statusCode = 400): array
private static function getExceptionResponses(string $exceptionMessage, string $loggerMessage, int $statusCode = 400): array
{
return [
'bad request' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ public function testInvalidHSLA($cssColor)
->assertRaised();
}

public function getInvalidHSLA(): array
public static function getInvalidHSLA(): array
{
return [['hsla(1000, 1000%, 20000%, 999)'], ['hsla(-100, -10%, -2%, 999)'], ['hsla(a, b, c, d)'], ['hsla(a, b%, c%, d)'], ['hsla( 9 99% , 99 9% , 9 %']];
}
Expand Down