-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDoctrineSchemaFixturesLoadCommandTest.php
More file actions
89 lines (72 loc) · 3.2 KB
/
DoctrineSchemaFixturesLoadCommandTest.php
File metadata and controls
89 lines (72 loc) · 3.2 KB
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
<?php
declare(strict_types=1);
namespace Macpaw\PostgresSchemaBundle\Tests\Command\Doctrine;
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Doctrine\DBAL\Connection;
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaFixturesLoadCommand;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\BufferedOutput;
class DoctrineSchemaFixturesLoadCommandTest extends TestCase
{
private Connection&MockObject $connection;
private Application&MockObject $application;
private LoadDataFixturesDoctrineCommand&Command&MockObject $parentCommand;
private DoctrineSchemaFixturesLoadCommand $command;
protected function setUp(): void
{
$this->connection = $this->createMock(Connection::class);
$this->application = $this->createMock(Application::class);
$this->parentCommand = $this->createMock(LoadDataFixturesDoctrineCommand::class);
$this->parentCommand
->method('getDefinition')
->willReturn(new InputDefinition([
new InputOption('no-interaction'),
]));
$this->command = new DoctrineSchemaFixturesLoadCommand($this->parentCommand, $this->connection, ['public']);
$this->command->setApplication($this->application);
}
public function testSuccess(): void
{
$input = new ArrayInput(['schema' => 'test_schema']);
$output = new BufferedOutput();
$this->connection->expects($this->once())
->method('fetchOne')
->with('SELECT EXISTS (SELECT 1 FROM pg_namespace WHERE nspname = ?)', ['test_schema'])
->willReturn(1);
$this->connection->expects($this->once())
->method('quoteIdentifier')
->with('test_schema')
->willReturn('"test_schema"');
$this->connection->expects($this->once())
->method('executeStatement')
->with('SET search_path TO "test_schema"');
$fixturesCommand = $this->createMock(Command::class);
$this->application->expects($this->once())
->method('find')
->with('doctrine:fixtures:load')
->willReturn($fixturesCommand);
$fixturesCommand->expects($this->once())
->method('run')
->willReturn(Command::SUCCESS);
$result = $this->command->run($input, $output);
$this->assertEquals(Command::SUCCESS, $result);
$this->assertStringContainsString("Load fixtures for 'test_schema'...", $output->fetch());
}
public function testDisallowedSchemaNameFail(): void
{
$input = new ArrayInput(['schema' => 'public']);
$output = new BufferedOutput();
$result = $this->command->run($input, $output);
$this->assertStringContainsString(
"Command is disallowed from being called for the 'public' schema",
$output->fetch()
);
$this->assertEquals(Command::FAILURE, $result);
}
}