|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Component\Validator\Tests\Command; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Component\Console\Tester\CommandTester; |
| 16 | +use Symfony\Component\Validator\Command\DebugCommand; |
| 17 | +use Symfony\Component\Validator\Constraints\Email; |
| 18 | +use Symfony\Component\Validator\Constraints\NotBlank; |
| 19 | +use Symfony\Component\Validator\Mapping\ClassMetadataInterface; |
| 20 | +use Symfony\Component\Validator\Mapping\PropertyMetadataInterface; |
| 21 | +use Symfony\Component\Validator\Tests\Dummy\DummyClassOne; |
| 22 | +use Symfony\Component\Validator\Validator\ValidatorInterface; |
| 23 | + |
| 24 | +/** |
| 25 | + * @author Loïc Frémont <lc.fremont@gmail.com> |
| 26 | + */ |
| 27 | +class DebugCommandTest extends TestCase |
| 28 | +{ |
| 29 | + public function testOutputWithClassArgument(): void |
| 30 | + { |
| 31 | + $validator = $this->createMock(ValidatorInterface::class); |
| 32 | + $classMetadata = $this->createMock(ClassMetadataInterface::class); |
| 33 | + $propertyMetadata = $this->createMock(PropertyMetadataInterface::class); |
| 34 | + |
| 35 | + $validator |
| 36 | + ->expects($this->once()) |
| 37 | + ->method('getMetadataFor') |
| 38 | + ->with(DummyClassOne::class) |
| 39 | + ->willReturn($classMetadata); |
| 40 | + |
| 41 | + $classMetadata |
| 42 | + ->expects($this->once()) |
| 43 | + ->method('getConstrainedProperties') |
| 44 | + ->willReturn([ |
| 45 | + 'firstArgument', |
| 46 | + ]); |
| 47 | + |
| 48 | + $classMetadata |
| 49 | + ->expects($this->once()) |
| 50 | + ->method('getPropertyMetadata') |
| 51 | + ->with('firstArgument') |
| 52 | + ->willReturn([ |
| 53 | + $propertyMetadata, |
| 54 | + ]); |
| 55 | + |
| 56 | + $propertyMetadata |
| 57 | + ->expects($this->once()) |
| 58 | + ->method('getConstraints') |
| 59 | + ->willReturn([new NotBlank(), new Email()]); |
| 60 | + |
| 61 | + $command = new DebugCommand($validator); |
| 62 | + |
| 63 | + $tester = new CommandTester($command); |
| 64 | + $tester->execute(['class' => DummyClassOne::class], ['decorated' => false]); |
| 65 | + |
| 66 | + $this->assertSame(<<<TXT |
| 67 | +
|
| 68 | +Information for class "Symfony\Component\Validator\Tests\Dummy\DummyClassOne" |
| 69 | +============================================================================= |
| 70 | +
|
| 71 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 72 | +| Property | Name | Groups | Options | |
| 73 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 74 | +| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | {"message":"This value should not be blank.","allowNull":false,"normalizer":null | |
| 75 | +| | | | ,"payload":null} | |
| 76 | +| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | {"message":"This value is not a valid email address.","mode":null,"normalizer":n | |
| 77 | +| | | | ull,"payload":null} | |
| 78 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 79 | +
|
| 80 | +TXT |
| 81 | + , $tester->getDisplay(true) |
| 82 | + ); |
| 83 | + } |
| 84 | + |
| 85 | + public function testOutputWithPathArgument(): void |
| 86 | + { |
| 87 | + $validator = $this->createMock(ValidatorInterface::class); |
| 88 | + $classMetadata = $this->createMock(ClassMetadataInterface::class); |
| 89 | + $secondClassMetadata = $this->createMock(ClassMetadataInterface::class); |
| 90 | + $propertyMetadata = $this->createMock(PropertyMetadataInterface::class); |
| 91 | + |
| 92 | + $validator |
| 93 | + ->expects($this->exactly(2)) |
| 94 | + ->method('getMetadataFor') |
| 95 | + ->withAnyParameters() |
| 96 | + ->willReturn($classMetadata); |
| 97 | + |
| 98 | + $classMetadata |
| 99 | + ->method('getConstrainedProperties') |
| 100 | + ->willReturn([ |
| 101 | + 'firstArgument', |
| 102 | + ]); |
| 103 | + |
| 104 | + $classMetadata |
| 105 | + ->method('getPropertyMetadata') |
| 106 | + ->with('firstArgument') |
| 107 | + ->willReturn([ |
| 108 | + $propertyMetadata, |
| 109 | + ]); |
| 110 | + |
| 111 | + $propertyMetadata |
| 112 | + ->method('getConstraints') |
| 113 | + ->willReturn([new NotBlank(), new Email()]); |
| 114 | + |
| 115 | + $command = new DebugCommand($validator); |
| 116 | + |
| 117 | + $tester = new CommandTester($command); |
| 118 | + $tester->execute(['--path' => __DIR__.'/../Dummy'], ['decorated' => false]); |
| 119 | + |
| 120 | + $this->assertSame(<<<TXT |
| 121 | +
|
| 122 | +Information for class "Symfony\Component\Validator\Tests\Dummy\DummyClassOne" |
| 123 | +============================================================================= |
| 124 | +
|
| 125 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 126 | +| Property | Name | Groups | Options | |
| 127 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 128 | +| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | {"message":"This value should not be blank.","allowNull":false,"normalizer":null | |
| 129 | +| | | | ,"payload":null} | |
| 130 | +| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | {"message":"This value is not a valid email address.","mode":null,"normalizer":n | |
| 131 | +| | | | ull,"payload":null} | |
| 132 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 133 | +
|
| 134 | +Information for class "Symfony\Component\Validator\Tests\Dummy\DummyClassTwo" |
| 135 | +============================================================================= |
| 136 | +
|
| 137 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 138 | +| Property | Name | Groups | Options | |
| 139 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 140 | +| firstArgument | Symfony\Component\Validator\Constraints\NotBlank | Default | {"message":"This value should not be blank.","allowNull":false,"normalizer":null | |
| 141 | +| | | | ,"payload":null} | |
| 142 | +| firstArgument | Symfony\Component\Validator\Constraints\Email | Default | {"message":"This value is not a valid email address.","mode":null,"normalizer":n | |
| 143 | +| | | | ull,"payload":null} | |
| 144 | ++---------------+--------------------------------------------------+---------+----------------------------------------------------------------------------------+ |
| 145 | +
|
| 146 | +TXT |
| 147 | + , $tester->getDisplay(true) |
| 148 | + ); |
| 149 | + } |
| 150 | +} |
0 commit comments