1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Tools\Console\Command;
use Doctrine\DBAL\Connection;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Console\Command\EnsureProductionSettingsCommand;
use Doctrine\ORM\Tools\Console\EntityManagerProvider\SingleManagerProvider;
use Doctrine\Tests\DoctrineTestCase;
use RuntimeException;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use function array_merge;
class EnsureProductionSettingsCommandTest extends DoctrineTestCase
{
public function testExecute(): void
{
$em = $this->createMock(EntityManagerInterface::class);
$configuration = $this->createMock(Configuration::class);
$configuration->expects(self::once())
->method('ensureProductionSettings');
$em->method('getConfiguration')
->willReturn($configuration);
$em->expects(self::never())
->method('getConnection');
self::assertSame(0, $this->executeCommand($em));
}
public function testExecuteFailed(): void
{
$em = $this->createMock(EntityManagerInterface::class);
$configuration = $this->createMock(Configuration::class);
$configuration->expects(self::once())
->method('ensureProductionSettings')
->willThrowException(new RuntimeException());
$em->method('getConfiguration')
->willReturn($configuration);
$em->expects(self::never())
->method('getConnection');
self::assertSame(1, $this->executeCommand($em));
}
public function testExecuteWithComplete(): void
{
$em = $this->createMock(EntityManagerInterface::class);
$configuration = $this->createMock(Configuration::class);
$configuration->expects(self::once())
->method('ensureProductionSettings');
$em->method('getConfiguration')
->willReturn($configuration);
$connection = $this->createMock(Connection::class);
$connection->expects(self::once())
->method('connect');
$em->method('getConnection')
->willReturn($connection);
self::assertSame(0, $this->executeCommand($em, ['--complete' => true]));
}
public function testExecuteWithCompleteFailed(): void
{
$em = $this->createMock(EntityManagerInterface::class);
$configuration = $this->createMock(Configuration::class);
$configuration->expects(self::once())
->method('ensureProductionSettings');
$em->method('getConfiguration')
->willReturn($configuration);
$connection = $this->createMock(Connection::class);
$connection->expects(self::once())
->method('connect')
->willThrowException(new RuntimeException());
$em->method('getConnection')
->willReturn($connection);
self::assertSame(1, $this->executeCommand($em, ['--complete' => true]));
}
private function executeCommand(
EntityManagerInterface $em,
array $input = []
): int {
$application = new Application();
$application->add(new EnsureProductionSettingsCommand(new SingleManagerProvider($em)));
$command = $application->find('orm:ensure-production-settings');
$tester = new CommandTester($command);
return $tester->execute(
array_merge([
'command' => $command->getName(),
], $input)
);
}
}
|