Skip to content

Commit 3b8b070

Browse files
[Tests] Migrate tests to static data providers
1 parent aee6adf commit 3b8b070

File tree

39 files changed

+639
-286
lines changed

39 files changed

+639
-286
lines changed

src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php

+22-25
Original file line numberDiff line numberDiff line change
@@ -49,66 +49,63 @@ public static function requiredType()
4949
yield [Types::DATETIMETZ_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE)];
5050
}
5151

52-
/**
53-
* @dataProvider requiredProvider
54-
*/
55-
public function testRequiredGuesser($classMetadata, $expected)
56-
{
57-
$this->assertEquals($expected, $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
58-
}
59-
60-
public function requiredProvider()
52+
public function testRequiredGuesserSimpleFieldNotNullable()
6153
{
62-
$return = [];
63-
64-
// Simple field, not nullable
6554
$classMetadata = $this->createMock(ClassMetadata::class);
6655
$classMetadata->fieldMappings['field'] = true;
6756
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(false);
6857

69-
$return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)];
58+
$this->assertEquals(new ValueGuess(true, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
59+
}
7060

71-
// Simple field, nullable
61+
public function testRequiredGuesserSimpleFieldNullable()
62+
{
7263
$classMetadata = $this->createMock(ClassMetadata::class);
7364
$classMetadata->fieldMappings['field'] = true;
7465
$classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(true);
7566

76-
$return[] = [$classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE)];
67+
$this->assertEquals(new ValueGuess(false, Guess::MEDIUM_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
68+
}
7769

78-
// One-to-one, nullable (by default)
70+
public function testRequiredGuesserOneToOneNullable()
71+
{
7972
$classMetadata = $this->createMock(ClassMetadata::class);
8073
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
8174

8275
$mapping = ['joinColumns' => [[]]];
8376
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping);
8477

85-
$return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)];
78+
$this->assertEquals(new ValueGuess(false, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
79+
}
8680

87-
// One-to-one, nullable (explicit)
81+
public function testRequiredGuesserOneToOneExplicitNullable()
82+
{
8883
$classMetadata = $this->createMock(ClassMetadata::class);
8984
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
9085

9186
$mapping = ['joinColumns' => [['nullable' => true]]];
9287
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping);
9388

94-
$return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)];
89+
$this->assertEquals(new ValueGuess(false, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
90+
}
9591

96-
// One-to-one, not nullable
92+
public function testRequiredGuesserOneToOneNotNullable()
93+
{
9794
$classMetadata = $this->createMock(ClassMetadata::class);
9895
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true);
9996

10097
$mapping = ['joinColumns' => [['nullable' => false]]];
10198
$classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping);
10299

103-
$return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)];
100+
$this->assertEquals(new ValueGuess(true, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
101+
}
104102

105-
// One-to-many, no clue
103+
public function testRequiredGuesserOneToMany()
104+
{
106105
$classMetadata = $this->createMock(ClassMetadata::class);
107106
$classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(false);
108107

109-
$return[] = [$classMetadata, null];
110-
111-
return $return;
108+
$this->assertNull($this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field'));
112109
}
113110

114111
private function getGuesser(ClassMetadata $classMetadata)

src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php

+94-52
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller;
1313

14+
use PHPUnit\Framework\MockObject\MockObject;
1415
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
1516
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1617
use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController;
@@ -366,6 +367,99 @@ public function provideCspVariants()
366367
* @dataProvider defaultPanelProvider
367368
*/
368369
public function testDefaultPanel(string $expectedPanel, Profile $profile)
370+
{
371+
$this->assertDefaultPanel($expectedPanel, $profile);
372+
}
373+
374+
public static function defaultPanelProvider(): \Generator
375+
{
376+
// Test default behavior
377+
$profile = new Profile('xxxxxx');
378+
$profile->addCollector($requestDataCollector = new RequestDataCollector());
379+
yield [$requestDataCollector->getName(), $profile];
380+
381+
// Test exception
382+
$profile = new Profile('xxxxxx');
383+
$profile->addCollector($exceptionDataCollector = new ExceptionDataCollector());
384+
$exceptionDataCollector->collect(new Request(), new Response(), new \DomainException());
385+
yield [$exceptionDataCollector->getName(), $profile];
386+
}
387+
388+
private function createController($profiler, $twig, $withCSP, array $templates = []): ProfilerController
389+
{
390+
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
391+
392+
if ($withCSP) {
393+
$nonceGenerator = $this->createMock(NonceGenerator::class);
394+
$nonceGenerator->method('generate')->willReturn('dummy_nonce');
395+
396+
return new ProfilerController($urlGenerator, $profiler, $twig, $templates, new ContentSecurityPolicyHandler($nonceGenerator));
397+
}
398+
399+
return new ProfilerController($urlGenerator, $profiler, $twig, $templates);
400+
}
401+
402+
public function testDumpPanelExceptionPriority()
403+
{
404+
$exceptionDataCollector = new ExceptionDataCollector();
405+
$exceptionDataCollector->collect(new Request(), new Response(), new \DomainException());
406+
407+
$dumpDataCollector = $this->createDumpDataCollector();
408+
409+
$profile = new Profile('xxxxxx');
410+
$profile->setCollectors([$exceptionDataCollector, $dumpDataCollector]);
411+
412+
$this->assertDefaultPanel($exceptionDataCollector->getName(), $profile);
413+
}
414+
415+
public function testDumpPanelWhenDefinedAfterwards()
416+
{
417+
$exceptionDataCollector = new ExceptionDataCollector();
418+
$exceptionDataCollector->collect(new Request(), new Response(), new \DomainException());
419+
420+
$dumpDataCollector = $this->createDumpDataCollector();
421+
$dumpDataCollector
422+
->expects($this->atLeastOnce())
423+
->method('getDumpsCount')
424+
->willReturn(1)
425+
;
426+
427+
$profile = new Profile('xxxxxx');
428+
$profile->setCollectors([$dumpDataCollector, $exceptionDataCollector]);
429+
430+
$this->assertDefaultPanel($exceptionDataCollector->getName(), $profile);
431+
}
432+
433+
public function testDumpPanel()
434+
{
435+
$dumpDataCollector = $this->createDumpDataCollector();
436+
$dumpDataCollector
437+
->expects($this->atLeastOnce())
438+
->method('getDumpsCount')
439+
->willReturn(1)
440+
;
441+
442+
$profile = new Profile('xxxxxx');
443+
$profile->addCollector($dumpDataCollector);
444+
445+
$this->assertDefaultPanel($dumpDataCollector->getName(), $profile);
446+
}
447+
448+
/**
449+
* @return MockObject<DumpDataCollector>
450+
*/
451+
private function createDumpDataCollector(): MockObject
452+
{
453+
$dumpDataCollector = $this->createMock(DumpDataCollector::class);
454+
$dumpDataCollector
455+
->expects($this->atLeastOnce())
456+
->method('getName')
457+
->willReturn('dump');
458+
459+
return $dumpDataCollector;
460+
}
461+
462+
private function assertDefaultPanel(string $expectedPanel, Profile $profile)
369463
{
370464
$profiler = $this->createMock(Profiler::class);
371465
$profiler
@@ -415,56 +509,4 @@ public function testDefaultPanel(string $expectedPanel, Profile $profile)
415509
}, $collectorsNames))
416510
->panelAction(new Request(), $profile->getToken());
417511
}
418-
419-
public function defaultPanelProvider(): \Generator
420-
{
421-
// Test default behavior
422-
$profile = new Profile('xxxxxx');
423-
$profile->addCollector($requestDataCollector = new RequestDataCollector());
424-
yield [$requestDataCollector->getName(), $profile];
425-
426-
// Test exception
427-
$profile = new Profile('xxxxxx');
428-
$profile->addCollector($exceptionDataCollector = new ExceptionDataCollector());
429-
$exceptionDataCollector->collect(new Request(), new Response(), new \DomainException());
430-
yield [$exceptionDataCollector->getName(), $profile];
431-
432-
// Test exception priority
433-
$dumpDataCollector = $this->createMock(DumpDataCollector::class);
434-
$dumpDataCollector
435-
->expects($this->atLeastOnce())
436-
->method('getName')
437-
->willReturn('dump');
438-
$dumpDataCollector
439-
->expects($this->atLeastOnce())
440-
->method('getDumpsCount')
441-
->willReturn(1);
442-
$profile = new Profile('xxxxxx');
443-
$profile->setCollectors([$exceptionDataCollector, $dumpDataCollector]);
444-
yield [$exceptionDataCollector->getName(), $profile];
445-
446-
// Test exception priority when defined afterwards
447-
$profile = new Profile('xxxxxx');
448-
$profile->setCollectors([$dumpDataCollector, $exceptionDataCollector]);
449-
yield [$exceptionDataCollector->getName(), $profile];
450-
451-
// Test dump
452-
$profile = new Profile('xxxxxx');
453-
$profile->addCollector($dumpDataCollector);
454-
yield [$dumpDataCollector->getName(), $profile];
455-
}
456-
457-
private function createController($profiler, $twig, $withCSP, array $templates = []): ProfilerController
458-
{
459-
$urlGenerator = $this->createMock(UrlGeneratorInterface::class);
460-
461-
if ($withCSP) {
462-
$nonceGenerator = $this->createMock(NonceGenerator::class);
463-
$nonceGenerator->method('generate')->willReturn('dummy_nonce');
464-
465-
return new ProfilerController($urlGenerator, $profiler, $twig, $templates, new ContentSecurityPolicyHandler($nonceGenerator));
466-
}
467-
468-
return new ProfilerController($urlGenerator, $profiler, $twig, $templates);
469-
}
470512
}

src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTestCase.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,27 @@ public function testDescribeApplication(Application $application, $expectedDescr
5353

5454
public static function getDescribeInputArgumentTestData()
5555
{
56-
return static::getDescriptionTestData(ObjectsProvider::getInputArguments());
56+
return self::getDescriptionTestData(ObjectsProvider::getInputArguments());
5757
}
5858

5959
public static function getDescribeInputOptionTestData()
6060
{
61-
return static::getDescriptionTestData(ObjectsProvider::getInputOptions());
61+
return self::getDescriptionTestData(ObjectsProvider::getInputOptions());
6262
}
6363

6464
public static function getDescribeInputDefinitionTestData()
6565
{
66-
return static::getDescriptionTestData(ObjectsProvider::getInputDefinitions());
66+
return self::getDescriptionTestData(ObjectsProvider::getInputDefinitions());
6767
}
6868

6969
public static function getDescribeCommandTestData()
7070
{
71-
return static::getDescriptionTestData(ObjectsProvider::getCommands());
71+
return self::getDescriptionTestData(ObjectsProvider::getCommands());
7272
}
7373

7474
public static function getDescribeApplicationTestData()
7575
{
76-
return static::getDescriptionTestData(ObjectsProvider::getApplications());
76+
return self::getDescriptionTestData(ObjectsProvider::getApplications());
7777
}
7878

7979
abstract protected function getDescriptor();

src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testHtml5ParserWithInvalidHeadedContent(string $content)
5252

5353
public function validHtml5Provider(): iterable
5454
{
55-
$html = static::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
55+
$html = self::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
5656
$BOM = \chr(0xEF).\chr(0xBB).\chr(0xBF);
5757

5858
yield 'BOM first' => [$BOM.$html];
@@ -65,7 +65,7 @@ public function validHtml5Provider(): iterable
6565

6666
public function invalidHtml5Provider(): iterable
6767
{
68-
$html = static::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
68+
$html = self::getDoctype().'<html><body><h1><p>Foo</p></h1></body></html>';
6969

7070
yield 'Text' => ['hello world'.$html];
7171
yield 'Text between comments' => ['<!--c--> test <!--cc-->'.$html];

src/Symfony/Component/ExpressionLanguage/Tests/Node/GetAttrNodeTest.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,39 @@ class GetAttrNodeTest extends AbstractNodeTestCase
2121
public static function getEvaluateData(): array
2222
{
2323
return [
24-
['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]],
25-
['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]],
24+
['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]],
25+
['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]],
2626

27-
['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]],
27+
['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]],
2828

29-
['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]],
30-
['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']],
29+
['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]],
30+
['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']],
3131
];
3232
}
3333

3434
public static function getCompileData(): array
3535
{
3636
return [
37-
['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)],
38-
['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)],
37+
['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
38+
['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
3939

40-
['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]],
40+
['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]],
4141

42-
['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]],
43-
['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)],
42+
['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]],
43+
['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
4444
];
4545
}
4646

4747
public static function getDumpData(): array
4848
{
4949
return [
50-
['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)],
51-
['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)],
50+
['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
51+
['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
5252

53-
['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]],
53+
['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]],
5454

55-
['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]],
56-
['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)],
55+
['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]],
56+
['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)],
5757
];
5858
}
5959

src/Symfony/Component/Filesystem/Tests/PathTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ private static function getPathTests(): \Generator
462462

463463
public function provideMakeAbsoluteTests(): \Generator
464464
{
465-
yield from static::getPathTests();
465+
yield from self::getPathTests();
466466

467467
// collapse dots
468468
yield ['css/./style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css'];
@@ -589,7 +589,7 @@ public function testMakeAbsoluteDoesNotFailIfDifferentRoot(string $basePath, str
589589

590590
public function provideMakeRelativeTests(): \Generator
591591
{
592-
foreach (static::getPathTests() as $set) {
592+
foreach (self::getPathTests() as $set) {
593593
yield [$set[2], $set[1], $set[0]];
594594
}
595595

src/Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ public function getAcceptData()
9393
];
9494

9595
return [
96-
[0, 0, static::toAbsolute($lessThan1)],
97-
[0, 1, static::toAbsolute($lessThanOrEqualTo1)],
96+
[0, 0, self::toAbsolute($lessThan1)],
97+
[0, 1, self::toAbsolute($lessThanOrEqualTo1)],
9898
[2, \PHP_INT_MAX, []],
99-
[1, \PHP_INT_MAX, static::toAbsolute($graterThanOrEqualTo1)],
100-
[1, 1, static::toAbsolute($equalTo1)],
99+
[1, \PHP_INT_MAX, self::toAbsolute($graterThanOrEqualTo1)],
100+
[1, 1, self::toAbsolute($equalTo1)],
101101
];
102102
}
103103
}

0 commit comments

Comments
 (0)