|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the SymfonyCasts ResetPasswordBundle package. |
| 5 | + * Copyright (c) SymfonyCasts <https://symfonycasts.com/> |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace SymfonyCasts\Bundle\ResetPassword\Tests\IntegrationTests; |
| 11 | + |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | +use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
| 14 | +use Symfony\Component\DependencyInjection\ContainerBuilder; |
| 15 | +use SymfonyCasts\Bundle\ResetPassword\Tests\Fixtures\AbstractResetPasswordTestKernel; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Jesse Rushlow <[email protected]> |
| 19 | + * @author Ryan Weaver <[email protected]> |
| 20 | + */ |
| 21 | +final class ResetPasswordServiceDefinitionTest extends TestCase |
| 22 | +{ |
| 23 | + public function bundleServiceDefinitionDataProvider(): \Generator |
| 24 | + { |
| 25 | + $prefix = 'symfonycasts.reset_password.'; |
| 26 | + |
| 27 | + yield [$prefix.'fake_request_repository']; |
| 28 | + yield [$prefix.'cleaner']; |
| 29 | + yield [$prefix.'random_generator']; |
| 30 | + yield [$prefix.'token_generator']; |
| 31 | + yield [$prefix.'helper']; |
| 32 | + yield ['SymfonyCasts\Bundle\ResetPassword\Command\ResetPasswordRemoveExpiredCommand']; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @dataProvider bundleServiceDefinitionDataProvider |
| 37 | + */ |
| 38 | + public function testBundleServiceDefinitions(string $definition): void |
| 39 | + { |
| 40 | + // Make private reset-password-bundle services public |
| 41 | + $pass = new DefinitionPublicCompilerPass(); |
| 42 | + $pass->definition = $definition; |
| 43 | + |
| 44 | + $kernel = new ResetPasswordDefinitionTestKernel(); |
| 45 | + $kernel->compilerPass = $pass; |
| 46 | + $kernel->boot(); |
| 47 | + |
| 48 | + $container = $kernel->getContainer(); |
| 49 | + $container->get($definition); |
| 50 | + |
| 51 | + // If a service is not correctly defined, i.e. wrong class namespace, an exception will be thrown. |
| 52 | + $this->expectNotToPerformAssertions(); |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +/** |
| 57 | + * @internal |
| 58 | + */ |
| 59 | +final class DefinitionPublicCompilerPass implements CompilerPassInterface |
| 60 | +{ |
| 61 | + public $definition; |
| 62 | + |
| 63 | + public function process(ContainerBuilder $container) |
| 64 | + { |
| 65 | + $container->getDefinition($this->definition) |
| 66 | + ->setPublic(true) |
| 67 | + ; |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +/** |
| 72 | + * @internal |
| 73 | + */ |
| 74 | +final class ResetPasswordDefinitionTestKernel extends AbstractResetPasswordTestKernel |
| 75 | +{ |
| 76 | + public $compilerPass; |
| 77 | + |
| 78 | + protected function build(ContainerBuilder $container) |
| 79 | + { |
| 80 | + $container->addCompilerPass($this->compilerPass); |
| 81 | + } |
| 82 | +} |
0 commit comments