Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use static methods inside data providers #48709

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
Dec 22, 2022
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 @@ -51,7 +51,7 @@ public function testIsFresh(callable $mockContainer, $expected)
$this->assertSame($expected, $this->resourceChecker->isFresh($this->resource, time()));
}

public function isFreshProvider()
public static function isFreshProvider()
{
yield 'not fresh on missing parameter' => [function (MockObject $container) {
$container->method('hasParameter')->with('locales')->willReturn(false);
Expand All @@ -62,11 +62,11 @@ public function isFreshProvider()
}, false];

yield 'fresh on every identical parameters' => [function (MockObject $container) {
$container->expects($this->exactly(2))->method('hasParameter')->willReturn(true);
$container->expects($this->exactly(2))->method('getParameter')
$container->expects(self::exactly(2))->method('hasParameter')->willReturn(true);
$container->expects(self::exactly(2))->method('getParameter')
Copy link
Contributor Author

@OskarStark OskarStark Dec 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these methods are defined as static anyway, shall we fix them through the whole codebase starting from 5.4 @nicolas-grekas ? Automated via rector ofc

Copy link
Member

@nicolas-grekas nicolas-grekas Dec 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to. That wouldn't provide any real added value but would consume a lot of time for sure.

->withConsecutive(
[$this->equalTo('locales')],
[$this->equalTo('default_locale')]
[self::equalTo('locales')],
[self::equalTo('default_locale')]
)
->willReturnMap([
['locales', ['fr', 'en']],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class AbstractCrawlerTest extends TestCase
{
use ExpectDeprecationTrait;

abstract public function getDoctype(): string;
abstract public static function getDoctype(): string;

protected function createCrawler($node = null, string $uri = null, string $baseHref = null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Html5ParserCrawlerTest extends AbstractCrawlerTest
{
public function getDoctype(): string
public static function getDoctype(): string
{
return '<!DOCTYPE html>';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class NativeParserCrawlerTest extends AbstractCrawlerTest
{
public function getDoctype(): string
public static function getDoctype(): string
{
return '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';
}
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Component/Finder/Tests/GitignoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testToRegex(array $gitignoreLines, array $matchingCases, array $
}
}

public function provider(): array
public static function provider(): array
{
$cases = [
[
Expand Down Expand Up @@ -394,7 +394,7 @@ public function provider(): array

public function providerExtended(): array
{
$basicCases = $this->provider();
$basicCases = self::provider();

$cases = [];
foreach ($basicCases as $case) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function getAcceptData()
];

return [
[[new NumberComparator('< 1K'), new NumberComparator('> 0.5K')], $this->toAbsolute($lessThan1KGreaterThan05K)],
[[new NumberComparator('< 1K'), new NumberComparator('> 0.5K')], self::toAbsolute($lessThan1KGreaterThan05K)],
];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getNormalizedIniPostMaxSize(): string
$this->request = null;
}

public function methodExceptGetProvider()
public static function methodExceptGetProvider()
{
return [
['POST'],
Expand All @@ -79,7 +79,7 @@ public function methodProvider()
{
return array_merge([
['GET'],
], $this->methodExceptGetProvider());
], self::methodExceptGetProvider());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public function provideCompletionSuggestions(): iterable

yield 'form_type' => [
[''],
$this->getCoreTypes(),
self::getCoreTypes(),
];

yield 'option for FQCN' => [
Expand Down Expand Up @@ -267,7 +267,7 @@ public function provideCompletionSuggestions(): iterable
];
}

private function getCoreTypes(): array
private static function getCoreTypes(): array
{
$coreExtension = new CoreExtension();
$loadTypesRefMethod = (new \ReflectionObject($coreExtension))->getMethod('loadTypes');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,31 +285,31 @@ public function privateTaggedServicesProvider()
function (ContainerBuilder $container) {
$formTypes = $container->getDefinition('form.extension')->getArgument(0);

$this->assertInstanceOf(Reference::class, $formTypes);
self::assertInstanceOf(Reference::class, $formTypes);

$locator = $container->getDefinition((string) $formTypes);
$expectedLocatorMap = [
'stdClass' => new ServiceClosureArgument(new Reference('my.type')),
];

$this->assertInstanceOf(Definition::class, $locator);
$this->assertEquals($expectedLocatorMap, $locator->getArgument(0));
self::assertInstanceOf(Definition::class, $locator);
self::assertEquals($expectedLocatorMap, $locator->getArgument(0));
},
],
[
'my.type_extension',
Type1TypeExtension::class,
'form.type_extension',
function (ContainerBuilder $container) {
$this->assertEquals(
self::assertEquals(
['Symfony\Component\Form\Extension\Core\Type\FormType' => new IteratorArgument([new Reference('my.type_extension')])],
$container->getDefinition('form.extension')->getArgument(1)
);
},
['extended_type' => 'Symfony\Component\Form\Extension\Core\Type\FormType'],
],
['my.guesser', 'stdClass', 'form.type_guesser', function (ContainerBuilder $container) {
$this->assertEquals(new IteratorArgument([new Reference('my.guesser')]), $container->getDefinition('form.extension')->getArgument(2));
self::assertEquals(new IteratorArgument([new Reference('my.guesser')]), $container->getDefinition('form.extension')->getArgument(2));
}],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function tearDown(): void
$this->dateTimeWithoutSeconds = null;
}

public function allProvider()
public static function allProvider()
{
return [
['UTC', 'UTC', '2010-02-03 04:05:06 UTC', '2010-02-03T04:05:06Z'],
Expand All @@ -51,12 +51,12 @@ public function allProvider()

public function transformProvider()
{
return $this->allProvider();
return self::allProvider();
}

public function reverseTransformProvider()
{
return array_merge($this->allProvider(), [
return array_merge(self::allProvider(), [
// format without seconds, as appears in some browsers
['UTC', 'UTC', '2010-02-03 04:05:00 UTC', '2010-02-03T04:05Z'],
['America/New_York', 'Asia/Hong_Kong', '2010-02-03 04:05:00 America/New_York', '2010-02-03T17:05+08:00'],
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/VarDumper/Tests/Caster/CasterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CasterTest extends TestCase
{
use VarDumperTestTrait;

private $referenceArray = [
private static $referenceArray = [
'null' => null,
'empty' => false,
'public' => 'pub',
Expand All @@ -38,12 +38,12 @@ class CasterTest extends TestCase
public function testFilter($filter, $expectedDiff, $listedProperties = null)
{
if (null === $listedProperties) {
$filteredArray = Caster::filter($this->referenceArray, $filter);
$filteredArray = Caster::filter(self::$referenceArray, $filter);
} else {
$filteredArray = Caster::filter($this->referenceArray, $filter, $listedProperties);
$filteredArray = Caster::filter(self::$referenceArray, $filter, $listedProperties);
}

$this->assertSame($expectedDiff, array_diff_assoc($this->referenceArray, $filteredArray));
$this->assertSame($expectedDiff, array_diff_assoc(self::$referenceArray, $filteredArray));
}

public function provideFilter()
Expand Down Expand Up @@ -126,7 +126,7 @@ public function provideFilter()
],
[
Caster::EXCLUDE_NOT_IMPORTANT | Caster::EXCLUDE_VERBOSE,
$this->referenceArray,
self::$referenceArray,
['public', "\0*\0protected"],
],
[
Expand Down