-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
334 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/Symfony/Component/Validator/Tests/Constraints/GroupSequenceProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\Constraints; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Validator\Constraints\GroupSequence; | ||
use Symfony\Component\Validator\Constraints\GroupSequenceProvider; | ||
use Symfony\Component\Validator\Tests\Dummy\DummyGroupSequenceProvider; | ||
|
||
class GroupSequenceProviderTest extends TestCase | ||
{ | ||
public function testCreate() | ||
{ | ||
$sequence = new GroupSequenceProvider(['class' => DummyGroupSequenceProvider::class]); | ||
|
||
$this->assertSame(DummyGroupSequenceProvider::class, $sequence->class); | ||
} | ||
|
||
public function testCreateAttributeStyle() | ||
{ | ||
$sequence = new GroupSequenceProvider(class: DummyGroupSequenceProvider::class); | ||
|
||
$this->assertSame(DummyGroupSequenceProvider::class, $sequence->class); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/Symfony/Component/Validator/Tests/ContainerGroupSequenceProviderFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\Container; | ||
use Symfony\Component\Validator\ContainerGroupSequenceProviderFactory; | ||
use Symfony\Component\Validator\Exception\GroupDefinitionException; | ||
use Symfony\Component\Validator\Exception\UnexpectedTypeException; | ||
use Symfony\Component\Validator\Tests\Dummy\DummyGroupSequenceProvider; | ||
|
||
class ContainerGroupSequenceProviderFactoryTest extends TestCase | ||
{ | ||
public function testGetInstanceCreatesProvider() | ||
{ | ||
$factory = new ContainerGroupSequenceProviderFactory(new Container()); | ||
$this->assertInstanceOf(DummyGroupSequenceProvider::class, $factory->getInstance(DummyGroupSequenceProvider::class)); | ||
} | ||
|
||
public function testGetInstanceReturnsExistingProvider() | ||
{ | ||
$factory = new ContainerGroupSequenceProviderFactory(new Container()); | ||
$v1 = $factory->getInstance(DummyGroupSequenceProvider::class); | ||
$v2 = $factory->getInstance(DummyGroupSequenceProvider::class); | ||
$this->assertSame($v1, $v2); | ||
} | ||
|
||
public function testGetInstanceReturnsService() | ||
{ | ||
$provider = new DummyGroupSequenceProvider(); | ||
$container = new Container(); | ||
$container->set(DummyGroupSequenceProvider::class, $provider); | ||
|
||
$factory = new ContainerGroupSequenceProviderFactory($container); | ||
|
||
$this->assertSame($provider, $factory->getInstance(DummyGroupSequenceProvider::class)); | ||
} | ||
|
||
public function testGetInstanceProviderNotFound() | ||
{ | ||
$this->expectException(GroupDefinitionException::class); | ||
|
||
$factory = new ContainerGroupSequenceProviderFactory(new Container()); | ||
$factory->getInstance('Unknown\\Class'); | ||
} | ||
|
||
public function testGetInstanceProviderDoNotImplementInterface() | ||
{ | ||
$this->expectException(UnexpectedTypeException::class); | ||
|
||
$factory = new ContainerGroupSequenceProviderFactory(new Container()); | ||
$factory->getInstance(stdClass::class); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...mfony/Component/Validator/Tests/DependencyInjection/AddGroupSequenceProvidersPassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\DependencyInjection; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\ServiceLocator; | ||
use Symfony\Component\Validator\DependencyInjection\AddGroupSequenceProvidersPass; | ||
|
||
class AddGroupSequenceProvidersPassTest extends TestCase | ||
{ | ||
public function testThatGroupSequenceProviderServicesAreProcessed() | ||
{ | ||
$container = new ContainerBuilder(); | ||
$groupSequenceProviderFactory = $container->register('validator.group_sequence_provider_factory') | ||
->addArgument([]); | ||
|
||
$container->register('my_group_sequence_provider_service1', Provider1::class) | ||
->addTag('validator.group_sequence_provider', ['alias' => 'my_group_sequence_provider_alias1']); | ||
$container->register('my_group_sequence_provider_service2', Provider2::class) | ||
->addTag('validator.group_sequence_provider'); | ||
|
||
$addGroupSequenceProvidersPass = new AddGroupSequenceProvidersPass(); | ||
$addGroupSequenceProvidersPass->process($container); | ||
|
||
$locator = $container->getDefinition((string) $groupSequenceProviderFactory->getArgument(0)); | ||
$this->assertTrue(!$locator->isPublic() || $locator->isPrivate()); | ||
$expected = (new Definition(ServiceLocator::class, [[ | ||
Provider1::class => new ServiceClosureArgument(new Reference('my_group_sequence_provider_service1')), | ||
'my_group_sequence_provider_alias1' => new ServiceClosureArgument(new Reference('my_group_sequence_provider_service1')), | ||
Provider2::class => new ServiceClosureArgument(new Reference('my_group_sequence_provider_service2')), | ||
]]))->addTag('container.service_locator')->setPublic(false); | ||
$this->assertEquals($expected, $locator->setPublic(false)); | ||
} | ||
|
||
public function testAbstractGroupSequenceProvider() | ||
{ | ||
$this->expectException(\InvalidArgumentException::class); | ||
$this->expectExceptionMessage('The service "my_abstract_group_sequence_provider" tagged "validator.group_sequence_provider" must not be abstract.'); | ||
$container = new ContainerBuilder(); | ||
$container->register('validator.group_sequence_provider_factory') | ||
->addArgument([]); | ||
|
||
$container->register('my_abstract_group_sequence_provider') | ||
->setAbstract(true) | ||
->addTag('validator.group_sequence_provider'); | ||
|
||
$addGroupSequenceProvidersPass = new AddGroupSequenceProvidersPass(); | ||
$addGroupSequenceProvidersPass->process($container); | ||
} | ||
|
||
public function testThatCompilerPassIsIgnoredIfThereIsNoGroupSequenceProviderFactoryDefinition() | ||
{ | ||
$container = new ContainerBuilder(); | ||
|
||
$definitionsBefore = \count($container->getDefinitions()); | ||
$aliasesBefore = \count($container->getAliases()); | ||
|
||
$addGroupSequenceProvidersPass = new AddGroupSequenceProvidersPass(); | ||
$addGroupSequenceProvidersPass->process($container); | ||
|
||
// the container is untouched (i.e. no new definitions or aliases) | ||
$this->assertCount($definitionsBefore, $container->getDefinitions()); | ||
$this->assertCount($aliasesBefore, $container->getAliases()); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Symfony/Component/Validator/Tests/Dummy/DummyGroupSequenceProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\Dummy; | ||
|
||
use Symfony\Component\Validator\Constraints\GroupSequence; | ||
use Symfony\Component\Validator\GroupSequenceProviderInterface; | ||
|
||
class DummyGroupSequenceProvider implements GroupSequenceProviderInterface | ||
{ | ||
public function getGroupSequence(): array|GroupSequence | ||
{ | ||
return ['foo', 'bar']; | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Symfony/Component/Validator/Tests/Fixtures/Attribute/GroupSequenceProviderDto.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Microservices bundle. | ||
* | ||
* (c) Yonel Ceruto <yonelceruto@gmail.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Validator\Tests\Fixtures\Attribute; | ||
|
||
use Symfony\Component\Validator\Constraints as Assert; | ||
use Symfony\Component\Validator\Tests\Dummy\DummyGroupSequenceProvider; | ||
|
||
#[Assert\GroupSequenceProvider(class: DummyGroupSequenceProvider::class)] | ||
class GroupSequenceProviderDto | ||
{ | ||
public string $firstName = ''; | ||
public string $lastName = ''; | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Symfony/Component/Validator/Tests/GroupSequenceProviderFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Validator\GroupSequenceProviderFactory; | ||
use Symfony\Component\Validator\Tests\Dummy\DummyGroupSequenceProvider; | ||
|
||
class GroupSequenceProviderFactoryTest extends TestCase | ||
{ | ||
public function testGetInstance() | ||
{ | ||
$factory = new GroupSequenceProviderFactory(); | ||
$this->assertInstanceOf(DummyGroupSequenceProvider::class, $factory->getInstance(DummyGroupSequenceProvider::class)); | ||
} | ||
|
||
public function testPredefinedGetInstance() | ||
{ | ||
$provider = new DummyGroupSequenceProvider(); | ||
$factory = new GroupSequenceProviderFactory([DummyGroupSequenceProvider::class => $provider]); | ||
$this->assertSame($provider, $factory->getInstance(DummyGroupSequenceProvider::class)); | ||
} | ||
} |
Oops, something went wrong.