diff --git a/phpunit b/phpunit index 7df0a0099f7b6..f606e15485c8c 100755 --- a/phpunit +++ b/phpunit @@ -6,7 +6,11 @@ if (!file_exists(__DIR__.'/vendor/symfony/phpunit-bridge/bin/simple-phpunit')) { exit(1); } if (!getenv('SYMFONY_PHPUNIT_VERSION')) { - putenv('SYMFONY_PHPUNIT_VERSION=11.5'); + if (\PHP_VERSION_ID >= 80300) { + putenv('SYMFONY_PHPUNIT_VERSION=12.0'); + } else { + putenv('SYMFONY_PHPUNIT_VERSION=11.5'); + } } if (!getenv('SYMFONY_PATCH_TYPE_DECLARATIONS')) { putenv('SYMFONY_PATCH_TYPE_DECLARATIONS=deprecations=1'); diff --git a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaListenerTest.php b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaListenerTest.php index e429dca192f6d..6ccfd1e222271 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaListenerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/DoctrineDbalCacheAdapterSchemaListenerTest.php @@ -35,7 +35,7 @@ public function testPostGenerateSchema() $dbalAdapter = $this->createMock(DoctrineDbalAdapter::class); $dbalAdapter->expects($this->once()) ->method('configureSchema') - ->with($schema, $dbalConnection, fn () => true); + ->with($schema, $dbalConnection, $this->callback(fn () => true)); $subscriber = new DoctrineDbalCacheAdapterSchemaListener([$dbalAdapter]); $subscriber->postGenerateSchema($event); diff --git a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/LockStoreSchemaListenerTest.php b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/LockStoreSchemaListenerTest.php index 6fd86a46c84e5..242db00019764 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/LockStoreSchemaListenerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/LockStoreSchemaListenerTest.php @@ -34,7 +34,7 @@ public function testPostGenerateSchemaLockPdo() $lockStore = $this->createMock(DoctrineDbalStore::class); $lockStore->expects($this->once()) ->method('configureSchema') - ->with($schema, fn () => true); + ->with($schema, $this->callback(fn () => true)); $subscriber = new LockStoreSchemaListener((static fn () => yield $lockStore)()); $subscriber->postGenerateSchema($event); diff --git a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/MessengerTransportDoctrineSchemaListenerTest.php b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/MessengerTransportDoctrineSchemaListenerTest.php index 7321ddd30e814..feca2495e2acf 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/MessengerTransportDoctrineSchemaListenerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/MessengerTransportDoctrineSchemaListenerTest.php @@ -38,7 +38,7 @@ public function testPostGenerateSchema() $doctrineTransport = $this->createMock(DoctrineTransport::class); $doctrineTransport->expects($this->once()) ->method('configureSchema') - ->with($schema, $dbalConnection, fn () => true); + ->with($schema, $dbalConnection, $this->callback(fn () => true)); $otherTransport = $this->createMock(TransportInterface::class); $otherTransport->expects($this->never()) ->method($this->anything()); diff --git a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoSessionHandlerSchemaListenerTest.php b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoSessionHandlerSchemaListenerTest.php index fce89261082c7..e10fbcafdabb6 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoSessionHandlerSchemaListenerTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/SchemaListener/PdoSessionHandlerSchemaListenerTest.php @@ -34,7 +34,7 @@ public function testPostGenerateSchemaPdo() $pdoSessionHandler = $this->createMock(PdoSessionHandler::class); $pdoSessionHandler->expects($this->once()) ->method('configureSchema') - ->with($schema, fn () => true); + ->with($schema, $this->callback(fn () => true)); $subscriber = new PdoSessionHandlerSchemaListener($pdoSessionHandler); $subscriber->postGenerateSchema($event); diff --git a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php index d6d07780351f6..94f9ffce58cc0 100644 --- a/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php +++ b/src/Symfony/Component/EventDispatcher/Tests/EventDispatcherTest.php @@ -411,8 +411,6 @@ public function testNamedClosures() $this->assertNotSame($callback1, $callback2); $this->assertNotSame($callback1, $callback3); $this->assertNotSame($callback2, $callback3); - $this->assertEquals($callback1, $callback2); - $this->assertEquals($callback1, $callback3); $this->dispatcher->addListener('foo', $callback1, 3); $this->dispatcher->addListener('foo', $callback2, 2); diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/ChoiceListAssertionTrait.php b/src/Symfony/Component/Form/Tests/ChoiceList/ChoiceListAssertionTrait.php new file mode 100644 index 0000000000000..f0b03d13e370a --- /dev/null +++ b/src/Symfony/Component/Form/Tests/ChoiceList/ChoiceListAssertionTrait.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\Form\Tests\ChoiceList; + +use Symfony\Component\Form\ChoiceList\ArrayChoiceList; +use Symfony\Component\Form\ChoiceList\LazyChoiceList; + +trait ChoiceListAssertionTrait +{ + private function assertEqualsArrayChoiceList(ArrayChoiceList $expected, $actual) + { + $this->assertInstanceOf(ArrayChoiceList::class, $actual); + $this->assertEquals($expected->getChoices(), $actual->getChoices()); + $this->assertEquals($expected->getStructuredValues(), $actual->getStructuredValues()); + $this->assertEquals($expected->getOriginalKeys(), $actual->getOriginalKeys()); + } + + private function assertEqualsLazyChoiceList(LazyChoiceList $expected, $actual) + { + $this->assertInstanceOf(LazyChoiceList::class, $actual); + $this->assertEquals($expected->getChoices(), $actual->getChoices()); + $this->assertEquals($expected->getValues(), $actual->getValues()); + $this->assertEquals($expected->getOriginalKeys(), $actual->getOriginalKeys()); + } +} diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php index 6134160046ddf..0ca1de133fa56 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/Cache/ChoiceLoaderTest.php @@ -16,10 +16,13 @@ use Symfony\Component\Form\ChoiceList\Factory\Cache\ChoiceLoader; use Symfony\Component\Form\ChoiceList\Loader\CallbackChoiceLoader; use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait; use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader; class ChoiceLoaderTest extends TestCase { + use ChoiceListAssertionTrait; + public function testSameFormTypeUseCachedLoader() { $choices = ['f' => 'foo', 'b' => 'bar', 'z' => 'baz']; @@ -30,8 +33,8 @@ public function testSameFormTypeUseCachedLoader() $loader1 = new ChoiceLoader($type, $decorated); $loader2 = new ChoiceLoader($type, new ArrayChoiceLoader()); - $this->assertEquals($choiceList, $loader1->loadChoiceList()); - $this->assertEquals($choiceList, $loader2->loadChoiceList()); + $this->assertEqualsArrayChoiceList($choiceList, $loader1->loadChoiceList()); + $this->assertEqualsArrayChoiceList($choiceList, $loader2->loadChoiceList()); $this->assertSame($choices, $loader1->loadChoicesForValues($choices)); $this->assertSame($choices, $loader2->loadChoicesForValues($choices)); diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php index 212b0b6a44dc1..fb51e0d5722bc 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/CachingFactoryDecoratorTest.php @@ -22,6 +22,7 @@ use Symfony\Component\Form\ChoiceList\Loader\FilterChoiceLoaderDecorator; use Symfony\Component\Form\ChoiceList\View\ChoiceListView; use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait; use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader; /** @@ -29,6 +30,8 @@ */ class CachingFactoryDecoratorTest extends TestCase { + use ChoiceListAssertionTrait; + private CachingFactoryDecorator $factory; protected function setUp(): void @@ -42,8 +45,8 @@ public function testCreateFromChoicesEmpty() $list2 = $this->factory->createListFromChoices([]); $this->assertSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList([]), $list1); - $this->assertEquals(new ArrayChoiceList([]), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList([]), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList([]), $list2); } public function testCreateFromChoicesComparesTraversableChoicesAsArray() @@ -56,8 +59,8 @@ public function testCreateFromChoicesComparesTraversableChoicesAsArray() $list2 = $this->factory->createListFromChoices($choices2); $this->assertSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList(['A' => 'a']), $list1); - $this->assertEquals(new ArrayChoiceList(['A' => 'a']), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList(['A' => 'a']), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList(['A' => 'a']), $list2); } public function testCreateFromChoicesGroupedChoices() @@ -68,8 +71,8 @@ public function testCreateFromChoicesGroupedChoices() $list2 = $this->factory->createListFromChoices($choices2); $this->assertNotSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList(['key' => ['A' => 'a']]), $list1); - $this->assertEquals(new ArrayChoiceList(['A' => 'a']), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList(['key' => ['A' => 'a']]), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList(['A' => 'a']), $list2); } #[DataProvider('provideSameChoices')] @@ -79,8 +82,8 @@ public function testCreateFromChoicesSameChoices($choice1, $choice2) $list2 = $this->factory->createListFromChoices([$choice2]); $this->assertSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList([$choice1]), $list1); - $this->assertEquals(new ArrayChoiceList([$choice2]), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice1]), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice2]), $list2); } #[DataProvider('provideDistinguishedChoices')] @@ -90,8 +93,8 @@ public function testCreateFromChoicesDifferentChoices($choice1, $choice2) $list2 = $this->factory->createListFromChoices([$choice2]); $this->assertNotSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList([$choice1]), $list1); - $this->assertEquals(new ArrayChoiceList([$choice2]), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice1]), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList([$choice2]), $list2); } public function testCreateFromChoicesSameValueClosure() @@ -103,8 +106,8 @@ public function testCreateFromChoicesSameValueClosure() $list2 = $this->factory->createListFromChoices($choices, $closure); $this->assertNotSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList($choices, $closure), $list1); - $this->assertEquals(new ArrayChoiceList($choices, $closure), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure), $list2); } public function testCreateFromChoicesSameValueClosureUseCache() @@ -117,8 +120,8 @@ public function testCreateFromChoicesSameValueClosureUseCache() $list2 = $this->factory->createListFromChoices($choices, ChoiceList::value($formType, function () {})); $this->assertSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList($choices, $valueCallback), $list1); - $this->assertEquals(new ArrayChoiceList($choices, function () {}), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $valueCallback), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, function () {}), $list2); } public function testCreateFromChoicesDifferentValueClosure() @@ -130,8 +133,8 @@ public function testCreateFromChoicesDifferentValueClosure() $list2 = $this->factory->createListFromChoices($choices, $closure2); $this->assertNotSame($list1, $list2); - $this->assertEquals(new ArrayChoiceList($choices, $closure1), $list1); - $this->assertEquals(new ArrayChoiceList($choices, $closure2), $list2); + self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure1), $list1); + self::assertEqualsArrayChoiceList(new ArrayChoiceList($choices, $closure2), $list2); } public function testCreateFromChoicesSameFilterClosure() @@ -143,8 +146,8 @@ public function testCreateFromChoicesSameFilterClosure() $lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), $filter), null); $this->assertNotSame($list1, $list2); - $this->assertEquals($lazyChoiceList, $list1); - $this->assertEquals($lazyChoiceList, $list2); + self::assertEqualsLazyChoiceList($lazyChoiceList, $list1); + self::assertEqualsLazyChoiceList($lazyChoiceList, $list2); } public function testCreateFromChoicesSameFilterClosureUseCache() @@ -157,8 +160,8 @@ public function testCreateFromChoicesSameFilterClosureUseCache() $lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), function () {}), null); $this->assertSame($list1, $list2); - $this->assertEquals($lazyChoiceList, $list1); - $this->assertEquals($lazyChoiceList, $list2); + self::assertEqualsLazyChoiceList($lazyChoiceList, $list1); + self::assertEqualsLazyChoiceList($lazyChoiceList, $list2); } public function testCreateFromChoicesDifferentFilterClosure() @@ -171,8 +174,8 @@ public function testCreateFromChoicesDifferentFilterClosure() $lazyChoiceList = new LazyChoiceList(new FilterChoiceLoaderDecorator(new CallbackChoiceLoader(static fn () => $choices), function () {}), null); $this->assertNotSame($list1, $list2); - $this->assertEquals($lazyChoiceList, $list1); - $this->assertEquals($lazyChoiceList, $list2); + self::assertEqualsLazyChoiceList($lazyChoiceList, $list1); + self::assertEqualsLazyChoiceList($lazyChoiceList, $list2); } public function testCreateFromLoaderSameLoader() @@ -182,8 +185,8 @@ public function testCreateFromLoaderSameLoader() $list2 = $this->factory->createListFromLoader($loader); $this->assertNotSame($list1, $list2); - $this->assertEquals(new LazyChoiceList($loader), $list1); - $this->assertEquals(new LazyChoiceList($loader), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList($loader), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList($loader), $list2); } public function testCreateFromLoaderSameLoaderUseCache() @@ -193,8 +196,8 @@ public function testCreateFromLoaderSameLoaderUseCache() $list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader())); $this->assertSame($list1, $list2); - $this->assertEquals(new LazyChoiceList(new ArrayChoiceLoader(), null), $list1); - $this->assertEquals(new LazyChoiceList(new ArrayChoiceLoader(), null), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), null), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), null), $list2); } public function testCreateFromLoaderDifferentLoader() @@ -210,8 +213,8 @@ public function testCreateFromLoaderSameValueClosure() $list2 = $this->factory->createListFromLoader($loader, $closure); $this->assertNotSame($list1, $list2); - $this->assertEquals(new LazyChoiceList($loader, $closure), $list1); - $this->assertEquals(new LazyChoiceList($loader, $closure), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list2); } public function testCreateFromLoaderSameValueClosureUseCache() @@ -223,8 +226,8 @@ public function testCreateFromLoaderSameValueClosureUseCache() $list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), ChoiceList::value($type, function () {})); $this->assertSame($list1, $list2); - $this->assertEquals(new LazyChoiceList($loader, $closure), $list1); - $this->assertEquals(new LazyChoiceList(new ArrayChoiceLoader(), function () {}), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList($loader, $closure), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new ArrayChoiceLoader(), function () {}), $list2); } public function testCreateFromLoaderDifferentValueClosure() @@ -246,8 +249,8 @@ public function testCreateFromLoaderSameFilterClosure() $list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure); $this->assertNotSame($list1, $list2); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator($loader, $closure)), $list1); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure)), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator($loader, $closure)), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure)), $list2); } public function testCreateFromLoaderSameFilterClosureUseCache() @@ -258,8 +261,8 @@ public function testCreateFromLoaderSameFilterClosureUseCache() $list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $choiceFilter); $this->assertSame($list1, $list2); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list1); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), function () {})), $list2); } public function testCreateFromLoaderDifferentFilterClosure() @@ -271,8 +274,8 @@ public function testCreateFromLoaderDifferentFilterClosure() $list2 = $this->factory->createListFromLoader(ChoiceList::loader($type, new ArrayChoiceLoader()), null, $closure2); $this->assertNotSame($list1, $list2); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure1), null), $list1); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure2), null), $list2); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure1), null), $list1); + self::assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $closure2), null), $list2); } public function testCreateViewSamePreferredChoices() diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php index 2b1b239e58861..0748011a3c7ac 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Factory/DefaultChoiceListFactoryTest.php @@ -20,6 +20,7 @@ use Symfony\Component\Form\ChoiceList\View\ChoiceGroupView; use Symfony\Component\Form\ChoiceList\View\ChoiceListView; use Symfony\Component\Form\ChoiceList\View\ChoiceView; +use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait; use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader; use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatableInterface; @@ -27,6 +28,8 @@ class DefaultChoiceListFactoryTest extends TestCase { + use ChoiceListAssertionTrait; + private \stdClass $obj1; private \stdClass $obj2; private \stdClass $obj3; @@ -261,7 +264,7 @@ public function testCreateFromLoaderWithFilter() $list = $this->factory->createListFromLoader(new ArrayChoiceLoader(), null, $filter); - $this->assertEquals(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $filter)), $list); + $this->assertEqualsLazyChoiceList(new LazyChoiceList(new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(), $filter)), $list); } public function testCreateViewFlat() diff --git a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/FilterChoiceLoaderDecoratorTest.php b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/FilterChoiceLoaderDecoratorTest.php index 5a41e5aff3415..e8f51dd6b3937 100644 --- a/src/Symfony/Component/Form/Tests/ChoiceList/Loader/FilterChoiceLoaderDecoratorTest.php +++ b/src/Symfony/Component/Form/Tests/ChoiceList/Loader/FilterChoiceLoaderDecoratorTest.php @@ -14,17 +14,20 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Form\ChoiceList\ArrayChoiceList; use Symfony\Component\Form\ChoiceList\Loader\FilterChoiceLoaderDecorator; +use Symfony\Component\Form\Tests\ChoiceList\ChoiceListAssertionTrait; use Symfony\Component\Form\Tests\Fixtures\ArrayChoiceLoader; class FilterChoiceLoaderDecoratorTest extends TestCase { + use ChoiceListAssertionTrait; + public function testLoadChoiceList() { $filter = fn ($choice) => 0 === $choice % 2; $loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(range(1, 4)), $filter); - $this->assertEquals(new ArrayChoiceList([1 => 2, 3 => 4]), $loader->loadChoiceList()); + $this->assertEqualsArrayChoiceList(new ArrayChoiceList([1 => 2, 3 => 4]), $loader->loadChoiceList()); } public function testLoadChoiceListWithGroupedChoices() @@ -33,7 +36,7 @@ public function testLoadChoiceListWithGroupedChoices() $loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader(['units' => range(1, 9), 'tens' => range(10, 90, 10)]), $filter); - $this->assertEquals(new ArrayChoiceList([ + $this->assertEqualsArrayChoiceList(new ArrayChoiceList([ 'units' => [ 1 => 2, 3 => 4, @@ -50,7 +53,7 @@ public function testLoadChoiceListMixedWithGroupedAndNonGroupedChoices() $choices = array_merge(range(1, 9), ['grouped' => range(10, 40, 5)]); $loader = new FilterChoiceLoaderDecorator(new ArrayChoiceLoader($choices), $filter); - $this->assertEquals(new ArrayChoiceList([ + $this->assertEqualsArrayChoiceList(new ArrayChoiceList([ 1 => 2, 3 => 4, 5 => 6, diff --git a/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/AttributePropertyMetadataLoaderTest.php b/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/AttributePropertyMetadataLoaderTest.php index b388f8cefde18..98eb1cb467609 100644 --- a/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/AttributePropertyMetadataLoaderTest.php +++ b/src/Symfony/Component/JsonStreamer/Tests/Mapping/Read/AttributePropertyMetadataLoaderTest.php @@ -44,8 +44,8 @@ public function testRetrieveValueTransformer() $this->assertEquals([ 'id' => new PropertyMetadata('id', Type::string(), [], [DivideStringAndCastToIntValueTransformer::class]), 'active' => new PropertyMetadata('active', Type::string(), [], [StringToBooleanValueTransformer::class]), - 'name' => new PropertyMetadata('name', Type::string(), [], [\Closure::fromCallable('strtolower')]), - 'range' => new PropertyMetadata('range', Type::string(), [], [\Closure::fromCallable(DummyWithValueTransformerAttributes::concatRange(...))]), + 'name' => new PropertyMetadata('name', Type::string(), [], [\Closure::fromCallable('strtoupper')]), + 'range' => new PropertyMetadata('range', Type::string(), [], [\Closure::fromCallable(DummyWithValueTransformerAttributes::explodeRange(...))]), ], $loader->load(DummyWithValueTransformerAttributes::class)); } diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportTest.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportTest.php index a82b788339655..5b7840f17131d 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineTransportTest.php @@ -63,11 +63,12 @@ public function testConfigureSchema() $schema = new Schema(); $dbalConnection = $this->createMock(DbalConnection::class); + $isSameDatabaseChecker = static fn () => true; $connection->expects($this->once()) ->method('configureSchema') - ->with($schema, $dbalConnection, static fn () => true); + ->with($schema, $dbalConnection, $isSameDatabaseChecker); - $transport->configureSchema($schema, $dbalConnection, static fn () => true); + $transport->configureSchema($schema, $dbalConnection, $isSameDatabaseChecker); } public function testKeepalive() diff --git a/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php b/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php index 6cd3698b1b4f5..7670db1ba169a 100644 --- a/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php +++ b/src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/ConnectionTest.php @@ -31,7 +31,7 @@ public function testFromInvalidDsn() public function testFromDsn() { - $this->assertEquals( + $this->assertEqualsConnection( new Connection([ 'stream' => 'queue', 'host' => 'localhost', @@ -43,7 +43,7 @@ public function testFromDsn() public function testFromDsnOnUnixSocket() { - $this->assertEquals( + $this->assertEqualsConnection( new Connection([ 'stream' => 'queue', 'host' => '/var/run/redis/redis.sock', @@ -55,7 +55,7 @@ public function testFromDsnOnUnixSocket() public function testFromDsnWithOptions() { - $this->assertEquals( + $this->assertEqualsConnection( Connection::fromDsn('redis://localhost', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2], $this->createRedisMock()), Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0', [], $this->createRedisMock()) ); @@ -63,7 +63,7 @@ public function testFromDsnWithOptions() public function testFromDsnWithOptionsAndTrailingSlash() { - $this->assertEquals( + $this->assertEqualsConnection( Connection::fromDsn('redis://localhost/', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2], $this->createRedisMock()), Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0', [], $this->createRedisMock()) ); @@ -85,7 +85,7 @@ public function testFromDsnWithRedissScheme() public function testFromDsnWithQueryOptions() { - $this->assertEquals( + $this->assertEqualsConnection( new Connection([ 'stream' => 'queue', 'group' => 'group1', @@ -100,12 +100,12 @@ public function testFromDsnWithQueryOptions() public function testFromDsnWithMixDsnQueryOptions() { - $this->assertEquals( + $this->assertEqualsConnection( Connection::fromDsn('redis://localhost/queue/group1?serializer=2', ['consumer' => 'specific-consumer'], $this->createRedisMock()), Connection::fromDsn('redis://localhost/queue/group1/specific-consumer?serializer=2', [], $this->createRedisMock()) ); - $this->assertEquals( + $this->assertEqualsConnection( Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['consumer' => 'specific-consumer'], $this->createRedisMock()), Connection::fromDsn('redis://localhost/queue/group1/consumer1', [], $this->createRedisMock()) ); @@ -430,7 +430,7 @@ public function testFromDsnOnUnixSocketWithUserAndPassword() ->with(['user', 'password']) ->willReturn(true); - $this->assertEquals( + $this->assertEqualsConnection( new Connection([ 'stream' => 'queue', 'delete_after_ack' => true, @@ -450,7 +450,7 @@ public function testFromDsnOnUnixSocketWithPassword() ->with('password') ->willReturn(true); - $this->assertEquals( + $this->assertEqualsConnection( new Connection([ 'stream' => 'queue', 'delete_after_ack' => true, @@ -470,7 +470,7 @@ public function testFromDsnOnUnixSocketWithUser() ->with('user') ->willReturn(true); - $this->assertEquals( + $this->assertEqualsConnection( new Connection([ 'stream' => 'queue', 'delete_after_ack' => true, @@ -533,4 +533,17 @@ private function createRedisMock(): MockObject&\Redis return $redis; } + + private function assertEqualsConnection(Connection $expected, $actual) + { + $this->assertInstanceOf(Connection::class, $actual); + + foreach ((new \ReflectionClass(Connection::class))->getProperties() as $property) { + if ('redisInitializer' === $property->getName()) { + continue; + } + + $this->assertEquals($property->getValue($expected), $property->getValue($actual)); + } + } } diff --git a/src/Symfony/Component/Security/Http/Tests/AccessToken/OAuth2/OAuth2TokenHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/AccessToken/OAuth2/OAuth2TokenHandlerTest.php index c6538ff75040e..4109ea1ab3bf3 100644 --- a/src/Symfony/Component/Security/Http/Tests/AccessToken/OAuth2/OAuth2TokenHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/AccessToken/OAuth2/OAuth2TokenHandlerTest.php @@ -20,7 +20,7 @@ class OAuth2TokenHandlerTest extends TestCase { - public static function testGetsUserIdentifierFromOAuth2ServerResponse(): void + public function testGetsUserIdentifierFromOAuth2ServerResponse() { $accessToken = 'a-secret-token'; $claims = [ @@ -35,7 +35,6 @@ public static function testGetsUserIdentifierFromOAuth2ServerResponse(): void 'iat' => 1419350238, 'extension_field' => 'twenty-seven', ]; - $expectedUser = new OAuth2User(...$claims); $client = new MockHttpClient([ new MockResponse(json_encode($claims, \JSON_THROW_ON_ERROR)), @@ -44,9 +43,11 @@ public static function testGetsUserIdentifierFromOAuth2ServerResponse(): void $userBadge = (new Oauth2TokenHandler($client))->getUserBadgeFrom($accessToken); $actualUser = $userBadge->getUserLoader()(); - self::assertEquals(new UserBadge('Z5O3upPC88QrAjx00dis', fn () => $expectedUser, $claims), $userBadge); - self::assertInstanceOf(OAuth2User::class, $actualUser); - self::assertSame($claims, $userBadge->getAttributes()); - self::assertSame($claims['sub'], $actualUser->getUserIdentifier()); + $this->assertInstanceOf(UserBadge::class, $userBadge); + $this->assertSame('Z5O3upPC88QrAjx00dis', $userBadge->getUserIdentifier()); + $this->assertSame($claims, $userBadge->getAttributes()); + $this->assertInstanceOf(OAuth2User::class, $actualUser); + $this->assertSame($claims, $userBadge->getAttributes()); + $this->assertSame($claims['sub'], $actualUser->getUserIdentifier()); } } diff --git a/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcTokenHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcTokenHandlerTest.php index e0f4eab7ca412..be3470cd23846 100644 --- a/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcTokenHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcTokenHandlerTest.php @@ -24,7 +24,6 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\User\OidcUser; use Symfony\Component\Security\Http\AccessToken\Oidc\OidcTokenHandler; -use Symfony\Component\Security\Http\Authenticator\FallbackUserLoader; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; #[RequiresPhpExtension('openssl')] @@ -61,7 +60,9 @@ public function testGetsUserIdentifierFromSignedToken(string $claim, string $exp ))->getUserBadgeFrom($token); $actualUser = $userBadge->getUserLoader()(); - $this->assertEquals(new UserBadge($expected, new FallbackUserLoader(fn () => $expectedUser), $claims), $userBadge); + $this->assertInstanceOf(UserBadge::class, $userBadge); + $this->assertSame($expected, $userBadge->getUserIdentifier()); + $this->assertSame($claims, $userBadge->getAttributes()); $this->assertInstanceOf(OidcUser::class, $actualUser); $this->assertEquals($expectedUser, $actualUser); $this->assertEquals($claims, $userBadge->getAttributes()); diff --git a/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcUserInfoTokenHandlerTest.php b/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcUserInfoTokenHandlerTest.php index 1eface9b8e1a7..4df3f4fc6f179 100644 --- a/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcUserInfoTokenHandlerTest.php +++ b/src/Symfony/Component/Security/Http/Tests/AccessToken/Oidc/OidcUserInfoTokenHandlerTest.php @@ -17,7 +17,6 @@ use Symfony\Component\Security\Core\Exception\BadCredentialsException; use Symfony\Component\Security\Core\User\OidcUser; use Symfony\Component\Security\Http\AccessToken\Oidc\OidcUserInfoTokenHandler; -use Symfony\Component\Security\Http\Authenticator\FallbackUserLoader; use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; @@ -47,7 +46,9 @@ public function testGetsUserIdentifierFromOidcServerResponse(string $claim, stri $userBadge = (new OidcUserInfoTokenHandler($clientMock, null, $claim))->getUserBadgeFrom($accessToken); $actualUser = $userBadge->getUserLoader()(); - $this->assertEquals(new UserBadge($expected, new FallbackUserLoader(fn () => $expectedUser), $claims), $userBadge); + $this->assertInstanceOf(UserBadge::class, $userBadge); + $this->assertSame($expected, $userBadge->getUserIdentifier()); + $this->assertSame($claims, $userBadge->getAttributes()); $this->assertInstanceOf(OidcUser::class, $actualUser); $this->assertEquals($expectedUser, $actualUser); $this->assertEquals($claims, $userBadge->getAttributes());
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: