From 3b8b07037b49411d4c78529ec3dfd422c7c011a7 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 7 Feb 2023 21:09:05 +0100 Subject: [PATCH] [Tests] Migrate tests to static data providers --- .../Tests/Form/DoctrineOrmTypeGuesserTest.php | 47 +++--- .../Controller/ProfilerControllerTest.php | 146 +++++++++++------- .../Descriptor/AbstractDescriptorTestCase.php | 10 +- .../Tests/Html5ParserCrawlerTest.php | 4 +- .../Tests/Node/GetAttrNodeTest.php | 30 ++-- .../Component/Filesystem/Tests/PathTest.php | 4 +- .../Iterator/DepthRangeFilterIteratorTest.php | 8 +- .../ExcludeDirectoryFilterIteratorTest.php | 6 +- .../Iterator/FileTypeFilterIteratorTest.php | 4 +- .../Tests/Iterator/SortableIteratorTest.php | 14 +- .../Tests/Store/MongoDbStoreFactoryTest.php | 38 +++++ .../Store/RedisProxyStoreFactoryTest.php | 34 ++++ .../Lock/Tests/Store/StoreFactoryTest.php | 16 +- .../Tests/Store/ZookeeperStoreFactoryTest.php | 45 ++++++ .../Strategy/AffirmativeStrategyTest.php | 10 +- .../Strategy/ConsensusStrategyTest.php | 18 +-- .../Strategy/PriorityStrategyTest.php | 20 +-- .../Strategy/UnanimousStrategyTest.php | 10 +- .../PasswordMigratingListenerTest.php | 73 +++++++-- .../Tests/Fixtures/DummyAuthenticator.php | 53 +++++++ .../Http/Tests/Fixtures/DummyToken.php | 101 ++++++++++++ .../AbstractComparisonValidatorTestCase.php | 34 ++-- .../Constraints/DivisibleByValidatorTest.php | 12 +- .../Constraints/EqualToValidatorTest.php | 10 +- .../GreaterThanOrEqualValidatorTest.php | 10 +- ...idatorWithPositiveOrZeroConstraintTest.php | 6 +- .../Constraints/GreaterThanValidatorTest.php | 10 +- ...hanValidatorWithPositiveConstraintTest.php | 6 +- .../Constraints/IdenticalToValidatorTest.php | 19 +-- .../LessThanOrEqualValidatorTest.php | 10 +- ...idatorWithNegativeOrZeroConstraintTest.php | 6 +- .../Constraints/LessThanValidatorTest.php | 10 +- ...hanValidatorWithNegativeConstraintTest.php | 6 +- .../Constraints/NotEqualToValidatorTest.php | 10 +- .../NotIdenticalToValidatorTest.php | 19 +-- .../Tests/Dumper/GraphvizDumperTest.php | 24 +-- .../Tests/Dumper/MermaidDumperTest.php | 18 +-- .../Tests/Dumper/PlantUmlDumperTest.php | 16 +- .../Workflow/Tests/WorkflowBuilderTrait.php | 8 +- 39 files changed, 639 insertions(+), 286 deletions(-) create mode 100644 src/Symfony/Component/Lock/Tests/Store/MongoDbStoreFactoryTest.php create mode 100644 src/Symfony/Component/Lock/Tests/Store/RedisProxyStoreFactoryTest.php create mode 100644 src/Symfony/Component/Lock/Tests/Store/ZookeeperStoreFactoryTest.php create mode 100644 src/Symfony/Component/Security/Http/Tests/Fixtures/DummyAuthenticator.php create mode 100644 src/Symfony/Component/Security/Http/Tests/Fixtures/DummyToken.php diff --git a/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php b/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php index b4ffee5561826..f211f291f873a 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Form/DoctrineOrmTypeGuesserTest.php @@ -49,66 +49,63 @@ public static function requiredType() yield [Types::DATETIMETZ_MUTABLE, new TypeGuess('Symfony\Component\Form\Extension\Core\Type\DateTimeType', [], Guess::HIGH_CONFIDENCE)]; } - /** - * @dataProvider requiredProvider - */ - public function testRequiredGuesser($classMetadata, $expected) - { - $this->assertEquals($expected, $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); - } - - public function requiredProvider() + public function testRequiredGuesserSimpleFieldNotNullable() { - $return = []; - - // Simple field, not nullable $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->fieldMappings['field'] = true; $classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(false); - $return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(true, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // Simple field, nullable + public function testRequiredGuesserSimpleFieldNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->fieldMappings['field'] = true; $classMetadata->expects($this->once())->method('isNullable')->with('field')->willReturn(true); - $return[] = [$classMetadata, new ValueGuess(false, Guess::MEDIUM_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(false, Guess::MEDIUM_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-one, nullable (by default) + public function testRequiredGuesserOneToOneNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true); $mapping = ['joinColumns' => [[]]]; $classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping); - $return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(false, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-one, nullable (explicit) + public function testRequiredGuesserOneToOneExplicitNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true); $mapping = ['joinColumns' => [['nullable' => true]]]; $classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping); - $return[] = [$classMetadata, new ValueGuess(false, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(false, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-one, not nullable + public function testRequiredGuesserOneToOneNotNullable() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(true); $mapping = ['joinColumns' => [['nullable' => false]]]; $classMetadata->expects($this->once())->method('getAssociationMapping')->with('field')->willReturn($mapping); - $return[] = [$classMetadata, new ValueGuess(true, Guess::HIGH_CONFIDENCE)]; + $this->assertEquals(new ValueGuess(true, Guess::HIGH_CONFIDENCE), $this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); + } - // One-to-many, no clue + public function testRequiredGuesserOneToMany() + { $classMetadata = $this->createMock(ClassMetadata::class); $classMetadata->expects($this->once())->method('isAssociationWithSingleJoinColumn')->with('field')->willReturn(false); - $return[] = [$classMetadata, null]; - - return $return; + $this->assertNull($this->getGuesser($classMetadata)->guessRequired('TestEntity', 'field')); } private function getGuesser(ClassMetadata $classMetadata) diff --git a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php index 86de485e031d1..f071aaad74d0c 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php +++ b/src/Symfony/Bundle/WebProfilerBundle/Tests/Controller/ProfilerControllerTest.php @@ -11,6 +11,7 @@ namespace Symfony\Bundle\WebProfilerBundle\Tests\Controller; +use PHPUnit\Framework\MockObject\MockObject; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; use Symfony\Bundle\WebProfilerBundle\Controller\ProfilerController; @@ -366,6 +367,99 @@ public function provideCspVariants() * @dataProvider defaultPanelProvider */ public function testDefaultPanel(string $expectedPanel, Profile $profile) + { + $this->assertDefaultPanel($expectedPanel, $profile); + } + + public static function defaultPanelProvider(): \Generator + { + // Test default behavior + $profile = new Profile('xxxxxx'); + $profile->addCollector($requestDataCollector = new RequestDataCollector()); + yield [$requestDataCollector->getName(), $profile]; + + // Test exception + $profile = new Profile('xxxxxx'); + $profile->addCollector($exceptionDataCollector = new ExceptionDataCollector()); + $exceptionDataCollector->collect(new Request(), new Response(), new \DomainException()); + yield [$exceptionDataCollector->getName(), $profile]; + } + + private function createController($profiler, $twig, $withCSP, array $templates = []): ProfilerController + { + $urlGenerator = $this->createMock(UrlGeneratorInterface::class); + + if ($withCSP) { + $nonceGenerator = $this->createMock(NonceGenerator::class); + $nonceGenerator->method('generate')->willReturn('dummy_nonce'); + + return new ProfilerController($urlGenerator, $profiler, $twig, $templates, new ContentSecurityPolicyHandler($nonceGenerator)); + } + + return new ProfilerController($urlGenerator, $profiler, $twig, $templates); + } + + public function testDumpPanelExceptionPriority() + { + $exceptionDataCollector = new ExceptionDataCollector(); + $exceptionDataCollector->collect(new Request(), new Response(), new \DomainException()); + + $dumpDataCollector = $this->createDumpDataCollector(); + + $profile = new Profile('xxxxxx'); + $profile->setCollectors([$exceptionDataCollector, $dumpDataCollector]); + + $this->assertDefaultPanel($exceptionDataCollector->getName(), $profile); + } + + public function testDumpPanelWhenDefinedAfterwards() + { + $exceptionDataCollector = new ExceptionDataCollector(); + $exceptionDataCollector->collect(new Request(), new Response(), new \DomainException()); + + $dumpDataCollector = $this->createDumpDataCollector(); + $dumpDataCollector + ->expects($this->atLeastOnce()) + ->method('getDumpsCount') + ->willReturn(1) + ; + + $profile = new Profile('xxxxxx'); + $profile->setCollectors([$dumpDataCollector, $exceptionDataCollector]); + + $this->assertDefaultPanel($exceptionDataCollector->getName(), $profile); + } + + public function testDumpPanel() + { + $dumpDataCollector = $this->createDumpDataCollector(); + $dumpDataCollector + ->expects($this->atLeastOnce()) + ->method('getDumpsCount') + ->willReturn(1) + ; + + $profile = new Profile('xxxxxx'); + $profile->addCollector($dumpDataCollector); + + $this->assertDefaultPanel($dumpDataCollector->getName(), $profile); + } + + /** + * @return MockObject + */ + private function createDumpDataCollector(): MockObject + { + $dumpDataCollector = $this->createMock(DumpDataCollector::class); + $dumpDataCollector + ->expects($this->atLeastOnce()) + ->method('getName') + ->willReturn('dump'); + + return $dumpDataCollector; + } + + private function assertDefaultPanel(string $expectedPanel, Profile $profile) { $profiler = $this->createMock(Profiler::class); $profiler @@ -415,56 +509,4 @@ public function testDefaultPanel(string $expectedPanel, Profile $profile) }, $collectorsNames)) ->panelAction(new Request(), $profile->getToken()); } - - public function defaultPanelProvider(): \Generator - { - // Test default behavior - $profile = new Profile('xxxxxx'); - $profile->addCollector($requestDataCollector = new RequestDataCollector()); - yield [$requestDataCollector->getName(), $profile]; - - // Test exception - $profile = new Profile('xxxxxx'); - $profile->addCollector($exceptionDataCollector = new ExceptionDataCollector()); - $exceptionDataCollector->collect(new Request(), new Response(), new \DomainException()); - yield [$exceptionDataCollector->getName(), $profile]; - - // Test exception priority - $dumpDataCollector = $this->createMock(DumpDataCollector::class); - $dumpDataCollector - ->expects($this->atLeastOnce()) - ->method('getName') - ->willReturn('dump'); - $dumpDataCollector - ->expects($this->atLeastOnce()) - ->method('getDumpsCount') - ->willReturn(1); - $profile = new Profile('xxxxxx'); - $profile->setCollectors([$exceptionDataCollector, $dumpDataCollector]); - yield [$exceptionDataCollector->getName(), $profile]; - - // Test exception priority when defined afterwards - $profile = new Profile('xxxxxx'); - $profile->setCollectors([$dumpDataCollector, $exceptionDataCollector]); - yield [$exceptionDataCollector->getName(), $profile]; - - // Test dump - $profile = new Profile('xxxxxx'); - $profile->addCollector($dumpDataCollector); - yield [$dumpDataCollector->getName(), $profile]; - } - - private function createController($profiler, $twig, $withCSP, array $templates = []): ProfilerController - { - $urlGenerator = $this->createMock(UrlGeneratorInterface::class); - - if ($withCSP) { - $nonceGenerator = $this->createMock(NonceGenerator::class); - $nonceGenerator->method('generate')->willReturn('dummy_nonce'); - - return new ProfilerController($urlGenerator, $profiler, $twig, $templates, new ContentSecurityPolicyHandler($nonceGenerator)); - } - - return new ProfilerController($urlGenerator, $profiler, $twig, $templates); - } } diff --git a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTestCase.php b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTestCase.php index 6e0caab542fb7..83d99969f5462 100644 --- a/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTestCase.php +++ b/src/Symfony/Component/Console/Tests/Descriptor/AbstractDescriptorTestCase.php @@ -53,27 +53,27 @@ public function testDescribeApplication(Application $application, $expectedDescr public static function getDescribeInputArgumentTestData() { - return static::getDescriptionTestData(ObjectsProvider::getInputArguments()); + return self::getDescriptionTestData(ObjectsProvider::getInputArguments()); } public static function getDescribeInputOptionTestData() { - return static::getDescriptionTestData(ObjectsProvider::getInputOptions()); + return self::getDescriptionTestData(ObjectsProvider::getInputOptions()); } public static function getDescribeInputDefinitionTestData() { - return static::getDescriptionTestData(ObjectsProvider::getInputDefinitions()); + return self::getDescriptionTestData(ObjectsProvider::getInputDefinitions()); } public static function getDescribeCommandTestData() { - return static::getDescriptionTestData(ObjectsProvider::getCommands()); + return self::getDescriptionTestData(ObjectsProvider::getCommands()); } public static function getDescribeApplicationTestData() { - return static::getDescriptionTestData(ObjectsProvider::getApplications()); + return self::getDescriptionTestData(ObjectsProvider::getApplications()); } abstract protected function getDescriptor(); diff --git a/src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php b/src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php index 9cfb6a6db18e2..7907a3a3e2cac 100644 --- a/src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php +++ b/src/Symfony/Component/DomCrawler/Tests/Html5ParserCrawlerTest.php @@ -52,7 +52,7 @@ public function testHtml5ParserWithInvalidHeadedContent(string $content) public function validHtml5Provider(): iterable { - $html = static::getDoctype().'

Foo

'; + $html = self::getDoctype().'

Foo

'; $BOM = \chr(0xEF).\chr(0xBB).\chr(0xBF); yield 'BOM first' => [$BOM.$html]; @@ -65,7 +65,7 @@ public function validHtml5Provider(): iterable public function invalidHtml5Provider(): iterable { - $html = static::getDoctype().'

Foo

'; + $html = self::getDoctype().'

Foo

'; yield 'Text' => ['hello world'.$html]; yield 'Text between comments' => [' test '.$html]; diff --git a/src/Symfony/Component/ExpressionLanguage/Tests/Node/GetAttrNodeTest.php b/src/Symfony/Component/ExpressionLanguage/Tests/Node/GetAttrNodeTest.php index df8eceaae912e..6d81a2b606a60 100644 --- a/src/Symfony/Component/ExpressionLanguage/Tests/Node/GetAttrNodeTest.php +++ b/src/Symfony/Component/ExpressionLanguage/Tests/Node/GetAttrNodeTest.php @@ -21,39 +21,39 @@ class GetAttrNodeTest extends AbstractNodeTestCase public static function getEvaluateData(): array { return [ - ['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], - ['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], + ['b', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], + ['a', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b']]], - ['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['bar', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']], + ['baz', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['a', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL), ['foo' => ['b' => 'a', 'b'], 'index' => 'b']], ]; } public static function getCompileData(): array { return [ - ['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['$foo->foo', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['$foo->foo(["b" => "a", 0 => "b"])', new GetAttrNode(new NameNode('foo'), new ConstantNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['$foo[$index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], ]; } public static function getDumpData(): array { return [ - ['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo[0]', new GetAttrNode(new NameNode('foo'), new ConstantNode(0), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo["b"]', new GetAttrNode(new NameNode('foo'), new ConstantNode('b'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], - ['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], + ['foo.foo', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), self::getArrayNode(), GetAttrNode::PROPERTY_CALL), ['foo' => new Obj()]], - ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), static::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], - ['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), static::getArrayNode(), GetAttrNode::ARRAY_CALL)], + ['foo.foo({"b": "a", 0: "b"})', new GetAttrNode(new NameNode('foo'), new NameNode('foo'), self::getArrayNode(), GetAttrNode::METHOD_CALL), ['foo' => new Obj()]], + ['foo[index]', new GetAttrNode(new NameNode('foo'), new NameNode('index'), self::getArrayNode(), GetAttrNode::ARRAY_CALL)], ]; } diff --git a/src/Symfony/Component/Filesystem/Tests/PathTest.php b/src/Symfony/Component/Filesystem/Tests/PathTest.php index 2f7a0a7a6c2f2..dd12c784539e2 100644 --- a/src/Symfony/Component/Filesystem/Tests/PathTest.php +++ b/src/Symfony/Component/Filesystem/Tests/PathTest.php @@ -462,7 +462,7 @@ private static function getPathTests(): \Generator public function provideMakeAbsoluteTests(): \Generator { - yield from static::getPathTests(); + yield from self::getPathTests(); // collapse dots yield ['css/./style.css', '/webmozart/symfony', '/webmozart/symfony/css/style.css']; @@ -589,7 +589,7 @@ public function testMakeAbsoluteDoesNotFailIfDifferentRoot(string $basePath, str public function provideMakeRelativeTests(): \Generator { - foreach (static::getPathTests() as $set) { + foreach (self::getPathTests() as $set) { yield [$set[2], $set[1], $set[0]]; } diff --git a/src/Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php index a66e50287e74f..c971ee9bb63b5 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/DepthRangeFilterIteratorTest.php @@ -93,11 +93,11 @@ public function getAcceptData() ]; return [ - [0, 0, static::toAbsolute($lessThan1)], - [0, 1, static::toAbsolute($lessThanOrEqualTo1)], + [0, 0, self::toAbsolute($lessThan1)], + [0, 1, self::toAbsolute($lessThanOrEqualTo1)], [2, \PHP_INT_MAX, []], - [1, \PHP_INT_MAX, static::toAbsolute($graterThanOrEqualTo1)], - [1, 1, static::toAbsolute($equalTo1)], + [1, \PHP_INT_MAX, self::toAbsolute($graterThanOrEqualTo1)], + [1, 1, self::toAbsolute($equalTo1)], ]; } } diff --git a/src/Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php index 572029a17f8fa..5299c93ed28c4 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/ExcludeDirectoryFilterIteratorTest.php @@ -99,9 +99,9 @@ public function getAcceptData() ]; return [ - [['foo'], static::toAbsolute($foo)], - [['fo'], static::toAbsolute($fo)], - [['toto/'], static::toAbsolute($toto)], + [['foo'], self::toAbsolute($foo)], + [['fo'], self::toAbsolute($fo)], + [['toto/'], self::toAbsolute($toto)], ]; } } diff --git a/src/Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php index be7beb1d146ad..5a16774a66343 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/FileTypeFilterIteratorTest.php @@ -57,8 +57,8 @@ public function getAcceptData() ]; return [ - [FileTypeFilterIterator::ONLY_FILES, static::toAbsolute($onlyFiles)], - [FileTypeFilterIterator::ONLY_DIRECTORIES, static::toAbsolute($onlyDirectories)], + [FileTypeFilterIterator::ONLY_FILES, self::toAbsolute($onlyFiles)], + [FileTypeFilterIterator::ONLY_DIRECTORIES, self::toAbsolute($onlyDirectories)], ]; } } diff --git a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php index 049961452b183..c6f8c30796103 100644 --- a/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php +++ b/src/Symfony/Component/Finder/Tests/Iterator/SortableIteratorTest.php @@ -247,13 +247,13 @@ public function getAcceptData() ]; return [ - [SortableIterator::SORT_BY_NAME, static::toAbsolute($sortByName)], - [SortableIterator::SORT_BY_TYPE, static::toAbsolute($sortByType)], - [SortableIterator::SORT_BY_ACCESSED_TIME, static::toAbsolute($sortByAccessedTime)], - [SortableIterator::SORT_BY_CHANGED_TIME, static::toAbsolute($sortByChangedTime)], - [SortableIterator::SORT_BY_MODIFIED_TIME, static::toAbsolute($sortByModifiedTime)], - [SortableIterator::SORT_BY_NAME_NATURAL, static::toAbsolute($sortByNameNatural)], - [function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, static::toAbsolute($customComparison)], + [SortableIterator::SORT_BY_NAME, self::toAbsolute($sortByName)], + [SortableIterator::SORT_BY_TYPE, self::toAbsolute($sortByType)], + [SortableIterator::SORT_BY_ACCESSED_TIME, self::toAbsolute($sortByAccessedTime)], + [SortableIterator::SORT_BY_CHANGED_TIME, self::toAbsolute($sortByChangedTime)], + [SortableIterator::SORT_BY_MODIFIED_TIME, self::toAbsolute($sortByModifiedTime)], + [SortableIterator::SORT_BY_NAME_NATURAL, self::toAbsolute($sortByNameNatural)], + [function (\SplFileInfo $a, \SplFileInfo $b) { return strcmp($a->getRealPath(), $b->getRealPath()); }, self::toAbsolute($customComparison)], ]; } } diff --git a/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreFactoryTest.php b/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreFactoryTest.php new file mode 100644 index 0000000000000..8256381c45b32 --- /dev/null +++ b/src/Symfony/Component/Lock/Tests/Store/MongoDbStoreFactoryTest.php @@ -0,0 +1,38 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Lock\Tests\Store; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Lock\Store\MongoDbStore; +use Symfony\Component\Lock\Store\StoreFactory; + +/** + * @author Alexandre Daubois + * + * @requires extension mongo + */ +class MongoDbStoreFactoryTest extends TestCase +{ + public function testCreateMongoDbCollectionStore() + { + $store = StoreFactory::createStore($this->createMock(\MongoDB\Collection::class)); + + $this->assertInstanceOf(MongoDbStore::class, $store); + } + + public function testCreateMongoDbCollectionStoreAsDsn() + { + $store = StoreFactory::createStore('mongodb://localhost/test?collection=lock'); + + $this->assertInstanceOf(MongoDbStore::class, $store); + } +} diff --git a/src/Symfony/Component/Lock/Tests/Store/RedisProxyStoreFactoryTest.php b/src/Symfony/Component/Lock/Tests/Store/RedisProxyStoreFactoryTest.php new file mode 100644 index 0000000000000..b1e26e06a9753 --- /dev/null +++ b/src/Symfony/Component/Lock/Tests/Store/RedisProxyStoreFactoryTest.php @@ -0,0 +1,34 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Lock\Tests\Store; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Cache\Traits\RedisProxy; +use Symfony\Component\Lock\Store\RedisStore; +use Symfony\Component\Lock\Store\StoreFactory; + +/** + * @author Alexandre Daubois + */ +class RedisProxyStoreFactoryTest extends TestCase +{ + public function testCreateStore() + { + if (!class_exists(RedisProxy::class)) { + $this->markTestSkipped(); + } + + $store = StoreFactory::createStore($this->createMock(RedisProxy::class)); + + $this->assertInstanceOf(RedisStore::class, $store); + } +} diff --git a/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php b/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php index daf3430fe4be3..6d2319c8d760e 100644 --- a/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php +++ b/src/Symfony/Component/Lock/Tests/Store/StoreFactoryTest.php @@ -15,19 +15,16 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\Adapter\MemcachedAdapter; -use Symfony\Component\Cache\Traits\RedisProxy; use Symfony\Component\Lock\Store\DoctrineDbalPostgreSqlStore; use Symfony\Component\Lock\Store\DoctrineDbalStore; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\InMemoryStore; use Symfony\Component\Lock\Store\MemcachedStore; -use Symfony\Component\Lock\Store\MongoDbStore; use Symfony\Component\Lock\Store\PdoStore; use Symfony\Component\Lock\Store\PostgreSqlStore; use Symfony\Component\Lock\Store\RedisStore; use Symfony\Component\Lock\Store\SemaphoreStore; use Symfony\Component\Lock\Store\StoreFactory; -use Symfony\Component\Lock\Store\ZookeeperStore; /** * @author Jérémy Derussé @@ -44,26 +41,15 @@ public function testCreateStore($connection, string $expectedStoreClass) $this->assertInstanceOf($expectedStoreClass, $store); } - public function validConnections() + public static function validConnections(): \Generator { if (class_exists(\Redis::class)) { yield [new \Redis(), RedisStore::class]; } - if (class_exists(RedisProxy::class)) { - yield [$this->createMock(RedisProxy::class), RedisStore::class]; - } yield [new \Predis\Client(), RedisStore::class]; if (class_exists(\Memcached::class)) { yield [new \Memcached(), MemcachedStore::class]; } - if (class_exists(\MongoDB\Collection::class)) { - yield [$this->createMock(\MongoDB\Collection::class), MongoDbStore::class]; - yield ['mongodb://localhost/test?collection=lock', MongoDbStore::class]; - } - if (class_exists(\Zookeeper::class)) { - yield [$this->createMock(\Zookeeper::class), ZookeeperStore::class]; - yield ['zookeeper://localhost:2181', ZookeeperStore::class]; - } if (\extension_loaded('sysvsem')) { yield ['semaphore', SemaphoreStore::class]; } diff --git a/src/Symfony/Component/Lock/Tests/Store/ZookeeperStoreFactoryTest.php b/src/Symfony/Component/Lock/Tests/Store/ZookeeperStoreFactoryTest.php new file mode 100644 index 0000000000000..97357b8485c20 --- /dev/null +++ b/src/Symfony/Component/Lock/Tests/Store/ZookeeperStoreFactoryTest.php @@ -0,0 +1,45 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Lock\Tests\Store; + +use PHPUnit\Framework\TestCase; +use Symfony\Component\Lock\Store\StoreFactory; +use Symfony\Component\Lock\Store\ZookeeperStore; + +/** + * @author Alexandre Daubois + * + * @requires extension zookeeper + */ +class ZookeeperStoreFactoryTest extends TestCase +{ + public function testCreateZooKeeperStore() + { + $store = StoreFactory::createStore($this->createMock(\Zookeeper::class)); + + $this->assertInstanceOf(ZookeeperStore::class, $store); + } + + public function testCreateZooKeeperStoreAsDsn() + { + $store = StoreFactory::createStore('zookeeper://localhost:2181'); + + $this->assertInstanceOf(ZookeeperStore::class, $store); + } + + public function testCreateZooKeeperStoreWithMultipleHosts() + { + $store = StoreFactory::createStore('zookeeper://localhost01,localhost02:2181'); + + $this->assertInstanceOf(ZookeeperStore::class, $store); + } +} diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/AffirmativeStrategyTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/AffirmativeStrategyTest.php index c37252a9ccf32..055809dc70432 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/AffirmativeStrategyTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/AffirmativeStrategyTest.php @@ -20,13 +20,13 @@ public function provideStrategyTests(): iterable { $strategy = new AffirmativeStrategy(); - yield [$strategy, static::getVoters(1, 0, 0), true]; - yield [$strategy, static::getVoters(1, 2, 0), true]; - yield [$strategy, static::getVoters(0, 1, 0), false]; - yield [$strategy, static::getVoters(0, 0, 1), false]; + yield [$strategy, self::getVoters(1, 0, 0), true]; + yield [$strategy, self::getVoters(1, 2, 0), true]; + yield [$strategy, self::getVoters(0, 1, 0), false]; + yield [$strategy, self::getVoters(0, 0, 1), false]; $strategy = new AffirmativeStrategy(true); - yield [$strategy, static::getVoters(0, 0, 1), true]; + yield [$strategy, self::getVoters(0, 0, 1), true]; } } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/ConsensusStrategyTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/ConsensusStrategyTest.php index 1da1af8d19272..69a3f789ee00b 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/ConsensusStrategyTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/ConsensusStrategyTest.php @@ -20,21 +20,21 @@ public function provideStrategyTests(): iterable { $strategy = new ConsensusStrategy(); - yield [$strategy, static::getVoters(1, 0, 0), true]; - yield [$strategy, static::getVoters(1, 2, 0), false]; - yield [$strategy, static::getVoters(2, 1, 0), true]; - yield [$strategy, static::getVoters(0, 0, 1), false]; + yield [$strategy, self::getVoters(1, 0, 0), true]; + yield [$strategy, self::getVoters(1, 2, 0), false]; + yield [$strategy, self::getVoters(2, 1, 0), true]; + yield [$strategy, self::getVoters(0, 0, 1), false]; - yield [$strategy, static::getVoters(2, 2, 0), true]; - yield [$strategy, static::getVoters(2, 2, 1), true]; + yield [$strategy, self::getVoters(2, 2, 0), true]; + yield [$strategy, self::getVoters(2, 2, 1), true]; $strategy = new ConsensusStrategy(true); - yield [$strategy, static::getVoters(0, 0, 1), true]; + yield [$strategy, self::getVoters(0, 0, 1), true]; $strategy = new ConsensusStrategy(false, false); - yield [$strategy, static::getVoters(2, 2, 0), false]; - yield [$strategy, static::getVoters(2, 2, 1), false]; + yield [$strategy, self::getVoters(2, 2, 0), false]; + yield [$strategy, self::getVoters(2, 2, 1), false]; } } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/PriorityStrategyTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/PriorityStrategyTest.php index 6aeade0ebe5a3..15c4adc6453f4 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/PriorityStrategyTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/PriorityStrategyTest.php @@ -22,23 +22,23 @@ public function provideStrategyTests(): iterable $strategy = new PriorityStrategy(); yield [$strategy, [ - static::getVoter(VoterInterface::ACCESS_ABSTAIN), - static::getVoter(VoterInterface::ACCESS_GRANTED), - static::getVoter(VoterInterface::ACCESS_DENIED), - static::getVoter(VoterInterface::ACCESS_DENIED), + self::getVoter(VoterInterface::ACCESS_ABSTAIN), + self::getVoter(VoterInterface::ACCESS_GRANTED), + self::getVoter(VoterInterface::ACCESS_DENIED), + self::getVoter(VoterInterface::ACCESS_DENIED), ], true]; yield [$strategy, [ - static::getVoter(VoterInterface::ACCESS_ABSTAIN), - static::getVoter(VoterInterface::ACCESS_DENIED), - static::getVoter(VoterInterface::ACCESS_GRANTED), - static::getVoter(VoterInterface::ACCESS_GRANTED), + self::getVoter(VoterInterface::ACCESS_ABSTAIN), + self::getVoter(VoterInterface::ACCESS_DENIED), + self::getVoter(VoterInterface::ACCESS_GRANTED), + self::getVoter(VoterInterface::ACCESS_GRANTED), ], false]; - yield [$strategy, static::getVoters(0, 0, 2), false]; + yield [$strategy, self::getVoters(0, 0, 2), false]; $strategy = new PriorityStrategy(true); - yield [$strategy, static::getVoters(0, 0, 2), true]; + yield [$strategy, self::getVoters(0, 0, 2), true]; } } diff --git a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/UnanimousStrategyTest.php b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/UnanimousStrategyTest.php index b9ed86e3667f1..29382d0961964 100644 --- a/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/UnanimousStrategyTest.php +++ b/src/Symfony/Component/Security/Core/Tests/Authorization/Strategy/UnanimousStrategyTest.php @@ -20,14 +20,14 @@ public function provideStrategyTests(): iterable { $strategy = new UnanimousStrategy(); - yield [$strategy, static::getVoters(1, 0, 0), true]; - yield [$strategy, static::getVoters(1, 0, 1), true]; - yield [$strategy, static::getVoters(1, 1, 0), false]; + yield [$strategy, self::getVoters(1, 0, 0), true]; + yield [$strategy, self::getVoters(1, 0, 1), true]; + yield [$strategy, self::getVoters(1, 1, 0), false]; - yield [$strategy, static::getVoters(0, 0, 2), false]; + yield [$strategy, self::getVoters(0, 0, 2), false]; $strategy = new UnanimousStrategy(true); - yield [$strategy, static::getVoters(0, 0, 2), true]; + yield [$strategy, self::getVoters(0, 0, 2), true]; } } diff --git a/src/Symfony/Component/Security/Http/Tests/EventListener/PasswordMigratingListenerTest.php b/src/Symfony/Component/Security/Http/Tests/EventListener/PasswordMigratingListenerTest.php index 9f8e218e70714..afdfd86cfd0b7 100644 --- a/src/Symfony/Component/Security/Http/Tests/EventListener/PasswordMigratingListenerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/EventListener/PasswordMigratingListenerTest.php @@ -15,13 +15,11 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\PasswordHasher\Hasher\PasswordHasherFactoryInterface; use Symfony\Component\PasswordHasher\PasswordHasherInterface; -use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\User\InMemoryUser; use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface; use Symfony\Component\Security\Core\User\PasswordUpgraderInterface; use Symfony\Component\Security\Core\User\UserInterface; use Symfony\Component\Security\Core\User\UserProviderInterface; -use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\PasswordUpgradeBadge; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; @@ -29,6 +27,8 @@ use Symfony\Component\Security\Http\Authenticator\Passport\UserPassportInterface; use Symfony\Component\Security\Http\Event\LoginSuccessEvent; use Symfony\Component\Security\Http\EventListener\PasswordMigratingListener; +use Symfony\Component\Security\Http\Tests\Fixtures\DummyAuthenticator; +use Symfony\Component\Security\Http\Tests\Fixtures\DummyToken; class PasswordMigratingListenerTest extends TestCase { @@ -58,13 +58,13 @@ public function testUnsupportedEvents($event) $this->listener->onLoginSuccess($event); } - public function provideUnsupportedEvents() + public static function provideUnsupportedEvents() { // no password upgrade badge - yield [$this->createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->createMock(UserInterface::class); })))]; + yield [self::createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->createMock(UserInterface::class); })))]; // blank password - yield [$this->createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return $this->createMock(TestPasswordAuthenticatedUser::class); }), [new PasswordUpgradeBadge('', $this->createPasswordUpgrader())]))]; + yield [self::createEvent(new SelfValidatingPassport(new UserBadge('test', function () { return new DummyTestPasswordAuthenticatedUser(); }), [new PasswordUpgradeBadge('', self::createPasswordUpgrader())]))]; } /** @@ -96,7 +96,7 @@ public function testUnsupportedPassport() public function testUpgradeWithUpgrader() { - $passwordUpgrader = $this->createPasswordUpgrader(); + $passwordUpgrader = $this->getMockForAbstractClass(TestMigratingUserProvider::class); $passwordUpgrader->expects($this->once()) ->method('upgradePassword') ->with($this->user, 'new-hash') @@ -133,14 +133,14 @@ public function testUserWithoutPassword() $this->listener->onLoginSuccess($event); } - private function createPasswordUpgrader() + private static function createPasswordUpgrader() { - return $this->getMockForAbstractClass(TestMigratingUserProvider::class); + return new DummyTestMigratingUserProvider(); } - private function createEvent(PassportInterface $passport) + private static function createEvent(PassportInterface $passport) { - return new LoginSuccessEvent($this->createMock(AuthenticatorInterface::class), $passport, $this->createMock(TokenInterface::class), new Request(), null, 'main'); + return new LoginSuccessEvent(new DummyAuthenticator(), $passport, new DummyToken(), new Request(), null, 'main'); } } @@ -151,9 +151,62 @@ abstract public function upgradePassword(PasswordAuthenticatedUserInterface $use abstract public function loadUserByIdentifier(string $identifier): UserInterface; } +class DummyTestMigratingUserProvider extends TestMigratingUserProvider +{ + public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void + { + } + + public function loadUserByIdentifier(string $identifier): UserInterface + { + } + + public function refreshUser(UserInterface $user) + { + } + + public function supportsClass(string $class) + { + } + + public function loadUserByUsername(string $username) + { + } +} + abstract class TestPasswordAuthenticatedUser implements UserInterface, PasswordAuthenticatedUserInterface { abstract public function getPassword(): ?string; abstract public function getSalt(): ?string; } + +class DummyTestPasswordAuthenticatedUser extends TestPasswordAuthenticatedUser +{ + public function getPassword(): ?string + { + return null; + } + + public function getSalt(): ?string + { + return null; + } + + public function getRoles(): array + { + return []; + } + + public function eraseCredentials() + { + } + + public function getUsername() + { + } + + public function getUserIdentifier(): string + { + } +} diff --git a/src/Symfony/Component/Security/Http/Tests/Fixtures/DummyAuthenticator.php b/src/Symfony/Component/Security/Http/Tests/Fixtures/DummyAuthenticator.php new file mode 100644 index 0000000000000..0b221813faebc --- /dev/null +++ b/src/Symfony/Component/Security/Http/Tests/Fixtures/DummyAuthenticator.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Http\Tests\Fixtures; + +use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\Exception\AuthenticationException; +use Symfony\Component\Security\Http\Authenticator\AuthenticatorInterface; +use Symfony\Component\Security\Http\Authenticator\Passport\Passport; +use Symfony\Component\Security\Http\Authenticator\Passport\PassportInterface; + +/** + * @author Alexandre Daubois + */ +class DummyAuthenticator implements AuthenticatorInterface +{ + public function supports(Request $request): ?bool + { + return null; + } + + public function authenticate(Request $request): Passport + { + } + + public function createToken(Passport $passport, string $firewallName): TokenInterface + { + } + + public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response + { + return null; + } + + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response + { + return null; + } + + public function createAuthenticatedToken(PassportInterface $passport, string $firewallName): TokenInterface + { + } +} diff --git a/src/Symfony/Component/Security/Http/Tests/Fixtures/DummyToken.php b/src/Symfony/Component/Security/Http/Tests/Fixtures/DummyToken.php new file mode 100644 index 0000000000000..0e921dbf7ead2 --- /dev/null +++ b/src/Symfony/Component/Security/Http/Tests/Fixtures/DummyToken.php @@ -0,0 +1,101 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Http\Tests\Fixtures; + +use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\User\UserInterface; + +/** + * @author Alexandre Daubois + */ +class DummyToken implements TokenInterface +{ + public function serialize() + { + } + + public function unserialize($data) + { + } + + public function __toString(): string + { + } + + public function getRoleNames(): array + { + } + + public function getCredentials(): mixed + { + } + + public function getUser(): ?UserInterface + { + } + + public function setUser($user) + { + } + + public function isAuthenticated(): bool + { + } + + public function setAuthenticated(bool $isAuthenticated) + { + } + + public function eraseCredentials(): void + { + } + + public function getAttributes(): array + { + } + + public function setAttributes(array $attributes): void + { + } + + public function hasAttribute(string $name): bool + { + } + + public function getAttribute(string $name): mixed + { + } + + public function setAttribute(string $name, $value): void + { + } + + public function getUsername(): string + { + } + + public function getUserIdentifier(): string + { + } + + public function __serialize(): array + { + } + + public function __unserialize(array $data): void + { + } + + public function __call(string $name, array $arguments) + { + } +} diff --git a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php index 4544e46687e48..0df1bae15e02b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/AbstractComparisonValidatorTestCase.php @@ -69,7 +69,7 @@ protected static function addPhp5Dot5Comparisons(array $comparisons) return $result; } - public function provideInvalidConstraintOptions() + public static function provideInvalidConstraintOptions() { return [ [null], @@ -112,15 +112,16 @@ public function testValidComparisonToValue($dirtyValue, $comparisonValue) $this->assertNoViolation(); } - public function provideAllValidComparisons(): array + public static function provideAllValidComparisons(): array { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); - $comparisons = self::addPhp5Dot5Comparisons($this->provideValidComparisons()); + $comparisons = self::addPhp5Dot5Comparisons(static::provideValidComparisons()); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } @@ -166,9 +167,9 @@ public function testInvalidValuePath() $this->validator->validate(5, $constraint); } - abstract public function provideValidComparisons(): array; + abstract public static function provideValidComparisons(): array; - abstract public function provideValidComparisonsToPropertyPath(): array; + abstract public static function provideValidComparisonsToPropertyPath(): array; /** * @dataProvider provideAllInvalidComparisons @@ -233,9 +234,9 @@ public function testThrowsOnInvalidStringDates(AbstractComparison $constraint, $ $this->validator->validate($value, $constraint); } - public function throwsOnInvalidStringDatesProvider(): array + public static function throwsOnInvalidStringDatesProvider(): array { - $constraint = $this->createConstraint([ + $constraint = static::createConstraint([ 'value' => 'foo', ]); @@ -273,27 +274,28 @@ public function testCompareWithNullValueAtPropertyAt($dirtyValue, $dirtyValueAsS } } - public function provideAllInvalidComparisons(): array + public static function provideAllInvalidComparisons(): array { // The provider runs before setUp(), so we need to manually fix // the default timezone - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); - $comparisons = self::addPhp5Dot5Comparisons($this->provideInvalidComparisons()); + $comparisons = self::addPhp5Dot5Comparisons(static::provideInvalidComparisons()); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } - abstract public function provideInvalidComparisons(): array; + abstract public static function provideInvalidComparisons(): array; - abstract public function provideComparisonsToNullValueAtPropertyPath(); + abstract public static function provideComparisonsToNullValueAtPropertyPath(); /** * @param array|null $options Options for the constraint */ - abstract protected function createConstraint(array $options = null): Constraint; + abstract protected static function createConstraint(array $options = null): Constraint; protected function getErrorCode(): ?string { diff --git a/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php index 4ce2723c0d845..0074d0a9f4a6d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/DivisibleByValidatorTest.php @@ -26,7 +26,7 @@ protected function createValidator() return new DivisibleByValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new DivisibleBy($options); } @@ -39,7 +39,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [-7, 1], @@ -68,7 +68,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [25], @@ -78,7 +78,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -112,8 +112,8 @@ public function throwsOnNonNumericValuesProvider() ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { - $this->markTestSkipped('DivisibleByValidator rejects null values.'); + self::markTestSkipped('DivisibleByValidator rejects null values.'); } } diff --git a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php index db825543fb075..628bd2534ff28 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/EqualToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new EqualToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new EqualTo($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [3, 3], @@ -55,7 +55,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -65,7 +65,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -77,7 +77,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', false], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php index 7484e9ff5d050..fd3622e870125 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new GreaterThanOrEqualValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new GreaterThanOrEqual($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [3, 2], @@ -58,7 +58,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -69,7 +69,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -80,7 +80,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php index 3aea5554dafb6..d6c6682fabf92 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest.php @@ -21,7 +21,7 @@ */ class GreaterThanOrEqualValidatorWithPositiveOrZeroConstraintTest extends GreaterThanOrEqualValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new PositiveOrZero(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [0, 0], @@ -45,7 +45,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [-1, '-1', 0, '0', 'int'], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php index 7c6b693d326e5..5f68e6fe2723c 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new GreaterThanValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new GreaterThan($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [2, 1], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [6], @@ -64,7 +64,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -82,7 +82,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php index a16320c0044a4..3b31ff4d0be35 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/GreaterThanValidatorWithPositiveConstraintTest.php @@ -21,7 +21,7 @@ */ class GreaterThanValidatorWithPositiveConstraintTest extends GreaterThanValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new Positive(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [2, 0], @@ -42,7 +42,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [0, '0', 0, '0', 'int'], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php index 98c467bc7627e..f9cc83b515b40 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/IdenticalToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new IdenticalToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new IdenticalTo($options); } @@ -35,15 +35,16 @@ protected function getErrorCode(): ?string return IdenticalTo::NOT_IDENTICAL_ERROR; } - public function provideAllValidComparisons(): array + public static function provideAllValidComparisons(): array { - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); // Don't call addPhp5Dot5Comparisons() automatically, as it does // not take care of identical objects - $comparisons = $this->provideValidComparisons(); + $comparisons = self::provideValidComparisons(); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } @@ -51,7 +52,7 @@ public function provideAllValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { $date = new \DateTime('2000-01-01'); $object = new ComparisonTest_Class(2); @@ -73,7 +74,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [5], @@ -83,7 +84,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [1, '1', 2, '2', 'int'], @@ -95,7 +96,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', false], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php index 73c9a1d154f17..6072f6f2275e9 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new LessThanOrEqualValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new LessThanOrEqual($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -60,7 +60,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [4], @@ -71,7 +71,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [2, '2', 1, '1', 'int'], @@ -83,7 +83,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php index 24a2a3c9c53e9..c5874ed5b5368 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest.php @@ -21,7 +21,7 @@ */ class LessThanOrEqualValidatorWithNegativeOrZeroConstraintTest extends LessThanOrEqualValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NegativeOrZero(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [0, 0], @@ -43,7 +43,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [2, '2', 0, '0', 'int'], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php index 7241203fcb3d7..acc815a04530b 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new LessThanValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new LessThan($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [4], @@ -64,7 +64,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [3, '3', 2, '2', 'int'], @@ -81,7 +81,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php index aba9f78c4b8e3..5e7173c304f40 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/LessThanValidatorWithNegativeConstraintTest.php @@ -21,7 +21,7 @@ */ class LessThanValidatorWithNegativeConstraintTest extends LessThanValidatorTest { - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new Negative(); } @@ -29,7 +29,7 @@ protected function createConstraint(array $options = null): Constraint /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [-1, 0], @@ -42,7 +42,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [0, '0', 0, '0', 'int'], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php index 47cdcac966b62..465458b07c0d4 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotEqualToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new NotEqualToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NotEqualTo($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -54,7 +54,7 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [0], @@ -64,7 +64,7 @@ public function provideValidComparisonsToPropertyPath(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { return [ [3, '3', 3, '3', 'int'], @@ -77,7 +77,7 @@ public function provideInvalidComparisons(): array ]; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php index 41660bda517a8..49cff99122d9d 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/NotIdenticalToValidatorTest.php @@ -25,7 +25,7 @@ protected function createValidator() return new NotIdenticalToValidator(); } - protected function createConstraint(array $options = null): Constraint + protected static function createConstraint(array $options = null): Constraint { return new NotIdenticalTo($options); } @@ -38,7 +38,7 @@ protected function getErrorCode(): ?string /** * {@inheritdoc} */ - public function provideValidComparisons(): array + public static function provideValidComparisons(): array { return [ [1, 2], @@ -57,22 +57,23 @@ public function provideValidComparisons(): array /** * {@inheritdoc} */ - public function provideValidComparisonsToPropertyPath(): array + public static function provideValidComparisonsToPropertyPath(): array { return [ [0], ]; } - public function provideAllInvalidComparisons(): array + public static function provideAllInvalidComparisons(): array { - $this->setDefaultTimezone('UTC'); + $timezone = date_default_timezone_get(); + date_default_timezone_set('UTC'); // Don't call addPhp5Dot5Comparisons() automatically, as it does // not take care of identical objects - $comparisons = $this->provideInvalidComparisons(); + $comparisons = self::provideInvalidComparisons(); - $this->restoreDefaultTimezone(); + date_default_timezone_set($timezone); return $comparisons; } @@ -80,7 +81,7 @@ public function provideAllInvalidComparisons(): array /** * {@inheritdoc} */ - public function provideInvalidComparisons(): array + public static function provideInvalidComparisons(): array { $date = new \DateTime('2000-01-01'); $object = new ComparisonTest_Class(2); @@ -95,7 +96,7 @@ public function provideInvalidComparisons(): array return $comparisons; } - public function provideComparisonsToNullValueAtPropertyPath() + public static function provideComparisonsToNullValueAtPropertyPath() { return [ [5, '5', true], diff --git a/src/Symfony/Component/Workflow/Tests/Dumper/GraphvizDumperTest.php b/src/Symfony/Component/Workflow/Tests/Dumper/GraphvizDumperTest.php index fcedde01577c8..f18868fcc3b41 100644 --- a/src/Symfony/Component/Workflow/Tests/Dumper/GraphvizDumperTest.php +++ b/src/Symfony/Component/Workflow/Tests/Dumper/GraphvizDumperTest.php @@ -47,28 +47,28 @@ public function testDumpWithMarking($definition, $marking, $expected) $this->assertEquals($expected, $dump); } - public function provideWorkflowDefinitionWithMarking() + public static function provideWorkflowDefinitionWithMarking() { yield [ - $this->createComplexWorkflowDefinition(), + self::createComplexWorkflowDefinition(), new Marking(['b' => 1]), - $this->createComplexWorkflowDefinitionDumpWithMarking(), + self::createComplexWorkflowDefinitionDumpWithMarking(), ]; yield [ - $this->createSimpleWorkflowDefinition(), + self::createSimpleWorkflowDefinition(), new Marking(['c' => 1, 'd' => 1]), - $this->createSimpleWorkflowDumpWithMarking(), + self::createSimpleWorkflowDumpWithMarking(), ]; } - public function provideWorkflowDefinitionWithoutMarking() + public static function provideWorkflowDefinitionWithoutMarking() { - yield [$this->createComplexWorkflowDefinition(), $this->provideComplexWorkflowDumpWithoutMarking()]; - yield [$this->createSimpleWorkflowDefinition(), $this->provideSimpleWorkflowDumpWithoutMarking()]; + yield [self::createComplexWorkflowDefinition(), self::provideComplexWorkflowDumpWithoutMarking()]; + yield [self::createSimpleWorkflowDefinition(), self::provideSimpleWorkflowDumpWithoutMarking()]; } - public function createComplexWorkflowDefinitionDumpWithMarking() + public static function createComplexWorkflowDefinitionDumpWithMarking() { return 'digraph workflow { ratio="compress" rankdir="LR" @@ -106,7 +106,7 @@ public function createComplexWorkflowDefinitionDumpWithMarking() '; } - public function createSimpleWorkflowDumpWithMarking() + public static function createSimpleWorkflowDumpWithMarking() { return 'digraph workflow { ratio="compress" rankdir="LR" @@ -126,7 +126,7 @@ public function createSimpleWorkflowDumpWithMarking() '; } - public function provideComplexWorkflowDumpWithoutMarking() + public static function provideComplexWorkflowDumpWithoutMarking() { return 'digraph workflow { ratio="compress" rankdir="LR" @@ -164,7 +164,7 @@ public function provideComplexWorkflowDumpWithoutMarking() '; } - public function provideSimpleWorkflowDumpWithoutMarking() + public static function provideSimpleWorkflowDumpWithoutMarking() { return 'digraph workflow { ratio="compress" rankdir="LR" diff --git a/src/Symfony/Component/Workflow/Tests/Dumper/MermaidDumperTest.php b/src/Symfony/Component/Workflow/Tests/Dumper/MermaidDumperTest.php index 4eaebe1e452b3..93c1e339486ee 100644 --- a/src/Symfony/Component/Workflow/Tests/Dumper/MermaidDumperTest.php +++ b/src/Symfony/Component/Workflow/Tests/Dumper/MermaidDumperTest.php @@ -71,11 +71,11 @@ public function testDumpWorkflowWithMarking(Definition $definition, Marking $mar $this->assertEquals($expected, $dump); } - public function provideWorkflowDefinitionWithoutMarking(): array + public static function provideWorkflowDefinitionWithoutMarking(): array { return [ [ - $this->createComplexWorkflowDefinition(), + self::createComplexWorkflowDefinition(), "graph LR\n" ."a0([\"a\"])\n" ."b1((\"b\"))\n" @@ -108,7 +108,7 @@ public function provideWorkflowDefinitionWithoutMarking(): array .'transition5-->g6', ], [ - $this->createWorkflowWithSameNameTransition(), + self::createWorkflowWithSameNameTransition(), "graph LR\n" ."a0([\"a\"])\n" ."b1((\"b\"))\n" @@ -128,7 +128,7 @@ public function provideWorkflowDefinitionWithoutMarking(): array .'transition3-->a0', ], [ - $this->createSimpleWorkflowDefinition(), + self::createSimpleWorkflowDefinition(), "graph LR\n" ."a0([\"a\"])\n" ."b1((\"b\"))\n" @@ -146,7 +146,7 @@ public function provideWorkflowDefinitionWithoutMarking(): array ]; } - public function provideWorkflowWithReservedWords() + public static function provideWorkflowWithReservedWords() { $builder = new DefinitionBuilder(); @@ -177,11 +177,11 @@ public function provideWorkflowWithReservedWords() ]; } - public function provideStatemachine(): array + public static function provideStatemachine(): array { return [ [ - $this->createComplexStateMachineDefinition(), + self::createComplexStateMachineDefinition(), "graph LR\n" ."a0([\"a\"])\n" ."b1((\"b\"))\n" @@ -196,7 +196,7 @@ public function provideStatemachine(): array ]; } - public function provideWorkflowWithMarking(): array + public static function provideWorkflowWithMarking(): array { $marking = new Marking(); $marking->mark('b'); @@ -204,7 +204,7 @@ public function provideWorkflowWithMarking(): array return [ [ - $this->createSimpleWorkflowDefinition(), + self::createSimpleWorkflowDefinition(), $marking, "graph LR\n" ."a0([\"a\"])\n" diff --git a/src/Symfony/Component/Workflow/Tests/Dumper/PlantUmlDumperTest.php b/src/Symfony/Component/Workflow/Tests/Dumper/PlantUmlDumperTest.php index 0c750fc750255..6af7809ae0ad5 100644 --- a/src/Symfony/Component/Workflow/Tests/Dumper/PlantUmlDumperTest.php +++ b/src/Symfony/Component/Workflow/Tests/Dumper/PlantUmlDumperTest.php @@ -36,14 +36,14 @@ public function testDumpWorkflowWithoutMarking($definition, $marking, $expectedF $this->assertStringEqualsFile($file, $dump); } - public function provideWorkflowDefinitionWithoutMarking() + public static function provideWorkflowDefinitionWithoutMarking() { - yield [$this->createSimpleWorkflowDefinition(), null, 'simple-workflow-nomarking', 'SimpleDiagram']; - yield [$this->createComplexWorkflowDefinition(), null, 'complex-workflow-nomarking', 'ComplexDiagram']; + yield [self::createSimpleWorkflowDefinition(), null, 'simple-workflow-nomarking', 'SimpleDiagram']; + yield [self::createComplexWorkflowDefinition(), null, 'complex-workflow-nomarking', 'ComplexDiagram']; $marking = new Marking(['b' => 1]); - yield [$this->createSimpleWorkflowDefinition(), $marking, 'simple-workflow-marking', 'SimpleDiagram']; + yield [self::createSimpleWorkflowDefinition(), $marking, 'simple-workflow-marking', 'SimpleDiagram']; $marking = new Marking(['c' => 1, 'e' => 1]); - yield [$this->createComplexWorkflowDefinition(), $marking, 'complex-workflow-marking', 'ComplexDiagram']; + yield [self::createComplexWorkflowDefinition(), $marking, 'complex-workflow-marking', 'ComplexDiagram']; } /** @@ -59,11 +59,11 @@ public function testDumpStateMachineWithoutMarking($definition, $marking, $expec $this->assertStringEqualsFile($file, $dump); } - public function provideStateMachineDefinitionWithoutMarking() + public static function provideStateMachineDefinitionWithoutMarking() { - yield [$this->createComplexStateMachineDefinition(), null, 'complex-state-machine-nomarking', 'SimpleDiagram']; + yield [static::createComplexStateMachineDefinition(), null, 'complex-state-machine-nomarking', 'SimpleDiagram']; $marking = new Marking(['c' => 1, 'e' => 1]); - yield [$this->createComplexStateMachineDefinition(), $marking, 'complex-state-machine-marking', 'SimpleDiagram']; + yield [static::createComplexStateMachineDefinition(), $marking, 'complex-state-machine-marking', 'SimpleDiagram']; } public function testDumpWorkflowWithSpacesInTheStateNamesAndDescription() diff --git a/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php b/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php index bf254f009969a..0c6db39009f8f 100644 --- a/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php +++ b/src/Symfony/Component/Workflow/Tests/WorkflowBuilderTrait.php @@ -17,7 +17,7 @@ trait WorkflowBuilderTrait { - private function createComplexWorkflowDefinition() + private static function createComplexWorkflowDefinition() { $places = range('a', 'g'); @@ -52,7 +52,7 @@ private function createComplexWorkflowDefinition() // +----+ +----+ +----+ +----+ } - private function createSimpleWorkflowDefinition() + private static function createSimpleWorkflowDefinition() { $places = range('a', 'c'); @@ -87,7 +87,7 @@ private function createSimpleWorkflowDefinition() // +---+ +----+ +---+ +----+ +---+ } - private function createWorkflowWithSameNameTransition() + private static function createWorkflowWithSameNameTransition() { $places = range('a', 'c'); @@ -115,7 +115,7 @@ private function createWorkflowWithSameNameTransition() // +--------------------------------------------------------------------+ } - private function createComplexStateMachineDefinition() + private static function createComplexStateMachineDefinition() { $places = ['a', 'b', 'c', 'd'];