|
| 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\Bundle\FrameworkBundle\Tests\Command; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bundle\FrameworkBundle\Command\SecretsListCommand; |
| 16 | +use Symfony\Bundle\FrameworkBundle\Secrets\AbstractVault; |
| 17 | +use Symfony\Component\Console\Tester\CommandTester; |
| 18 | + |
| 19 | +class SecretsListCommandTest extends TestCase |
| 20 | +{ |
| 21 | + public function testExecute() |
| 22 | + { |
| 23 | + $vault = $this->createMock(AbstractVault::class); |
| 24 | + $vault->method('list')->willReturn(['A' => 'a', 'B' => 'b', 'C' => null, 'D' => null, 'E' => null]); |
| 25 | + $localVault = $this->createMock(AbstractVault::class); |
| 26 | + $localVault->method('list')->willReturn(['A' => '', 'B' => 'A', 'C' => '', 'D' => false, 'E' => null]); |
| 27 | + $command = new SecretsListCommand($vault, $localVault); |
| 28 | + $tester = new CommandTester($command); |
| 29 | + $this->assertSame(0, $tester->execute([])); |
| 30 | + |
| 31 | + $expectedOutput = <<<EOTXT |
| 32 | + // Use "%%env(<name>)%%" to reference a secret in a config file. |
| 33 | +
|
| 34 | + // To reveal the secrets run %s secrets:list --reveal |
| 35 | +
|
| 36 | + -------- -------- ------------- |
| 37 | + Secret Value Local Value |
| 38 | + -------- -------- ------------- |
| 39 | + A "a" |
| 40 | + B "b" "A" |
| 41 | + C ****** |
| 42 | + D ****** |
| 43 | + E ****** |
| 44 | + -------- -------- ------------- |
| 45 | +
|
| 46 | + // Local values override secret values. |
| 47 | + // Use secrets:set --local to define them. |
| 48 | + EOTXT; |
| 49 | + $this->assertStringMatchesFormat($expectedOutput, trim(preg_replace('/ ++$/m', '', $tester->getDisplay(true)), "\n")); |
| 50 | + } |
| 51 | +} |
0 commit comments