Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"doctrine/orm": "^2.17 || ^3.0",
"symfony/doctrine-bridge": "^6.4 || ^7.0",
"doctrine/dbal": "^3.4",
"macpaw/schema-context-bundle": "^1.1"
"macpaw/schema-context-bundle": "^2.0"
},
"require-dev": {
"doctrine/migrations": "^3.6",
Expand Down
3 changes: 3 additions & 0 deletions src/Command/Doctrine/AbstractDoctrineSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Error;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -15,6 +16,7 @@ abstract class AbstractDoctrineSchemaCommand extends Command
public function __construct(
string $commandName,
protected readonly Connection $connection,
protected readonly BaggageSchemaResolver $schemaResolver,
) {
parent::__construct($commandName);
}
Expand Down Expand Up @@ -53,6 +55,7 @@ protected function isSchemaExist(string $schema): bool

protected function switchToSchema(string $schema): void
{
$this->schemaResolver->setSchema($schema);
$quotedSchema = $this->connection->quoteIdentifier($schema);

$this->connection->executeStatement("SET search_path TO {$quotedSchema}");
Expand Down
8 changes: 3 additions & 5 deletions src/Command/Doctrine/AbstractNestingDoctrineSchemaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Error;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -19,8 +20,9 @@ public function __construct(
string $commandName,
private readonly Command $parentCommand,
Connection $connection,
BaggageSchemaResolver $schemaResolver,
) {
parent::__construct($commandName, $connection);
parent::__construct($commandName, $connection, $schemaResolver);
}

protected function configure(): void
Expand Down Expand Up @@ -76,10 +78,6 @@ protected function runCommand(string $commandName, InputInterface $input, Output

$options = [];
foreach ($input->getOptions() as $name => $value) {
if ($value === null) {
continue;
}

if ($this->getDefinition()->getOptions()[$name]->getDefault() === $value) {
continue;
}
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Doctrine/DoctrineSchemaDropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Macpaw\PostgresSchemaBundle\Command\Doctrine;

use Doctrine\DBAL\Connection;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -16,9 +17,10 @@ class DoctrineSchemaDropCommand extends AbstractDoctrineSchemaCommand
*/
public function __construct(
Connection $connection,
BaggageSchemaResolver $schemaResolver,
private readonly array $disallowedSchemaNames = [],
) {
parent::__construct('doctrine:database:schema:drop', $connection);
parent::__construct('doctrine:database:schema:drop', $connection, $schemaResolver);
}

protected function execute(
Expand Down
4 changes: 3 additions & 1 deletion src/Command/Doctrine/DoctrineSchemaFixturesLoadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Doctrine\DBAL\Connection;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -19,9 +20,10 @@ class DoctrineSchemaFixturesLoadCommand extends AbstractNestingDoctrineSchemaCom
public function __construct(
LoadDataFixturesDoctrineCommand $parentCommand,
Connection $connection,
BaggageSchemaResolver $schemaResolver,
private readonly array $disallowedSchemaNames = [],
) {
parent::__construct('doctrine:schema:fixtures:load', $parentCommand, $connection);
parent::__construct('doctrine:schema:fixtures:load', $parentCommand, $connection, $schemaResolver);
}

protected function execute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -16,8 +17,9 @@ class DoctrineSchemaMigrationsMigrateCommand extends AbstractNestingDoctrineSche
public function __construct(
MigrateCommand $parentCommand,
Connection $connection,
BaggageSchemaResolver $schemaResolver,
) {
parent::__construct('doctrine:schema:migrations:migrate', $parentCommand, $connection);
parent::__construct('doctrine:schema:migrations:migrate', $parentCommand, $connection, $schemaResolver);
}

protected function execute(
Expand Down
4 changes: 3 additions & 1 deletion tests/Command/Doctrine/DoctrineSchemaDropCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Connection;
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaDropCommand;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Command\Command;
Expand All @@ -20,7 +21,8 @@ class DoctrineSchemaDropCommandTest extends TestCase
protected function setUp(): void
{
$this->connection = $this->createMock(Connection::class);
$this->command = new DoctrineSchemaDropCommand($this->connection, ['public']);
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
$this->command = new DoctrineSchemaDropCommand($this->connection, $resolver, ['public']);
}

public function testSuccess(): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
use Doctrine\DBAL\Connection;
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaFixturesLoadCommand;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand All @@ -33,8 +34,14 @@ protected function setUp(): void
->willReturn(new InputDefinition([
new InputOption('no-interaction'),
]));
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);

$this->command = new DoctrineSchemaFixturesLoadCommand($this->parentCommand, $this->connection, ['public']);
$this->command = new DoctrineSchemaFixturesLoadCommand(
$this->parentCommand,
$this->connection,
$resolver,
['public']
);
$this->command->setApplication($this->application);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaMigrationsMigrateCommand;
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
Expand All @@ -32,8 +33,9 @@ protected function setUp(): void
->willReturn(new InputDefinition([
new InputOption('no-interaction'),
]));
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);

$this->command = new DoctrineSchemaMigrationsMigrateCommand($this->parentCommand, $this->connection);
$this->command = new DoctrineSchemaMigrationsMigrateCommand($this->parentCommand, $this->connection, $resolver);
$this->application = $this->createMock(Application::class);
$this->command->setApplication($this->application);
}
Expand Down
22 changes: 17 additions & 5 deletions tests/Doctrine/SchemaConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testConnectSetsSearchPath(): void
$connection->method('getDatabasePlatform')->willReturn($platform);
$connection->method('fetchOne')->willReturn(true);

$resolver = new BaggageSchemaResolver();
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);

$resolver->setSchema('test_schema');

Expand Down Expand Up @@ -70,7 +70,7 @@ public function testConnectSetsSearchPathWithSpecialChars(): void
$connection->method('getDatabasePlatform')->willReturn($platform);
$connection->method('fetchOne')->willReturn(true);

$resolver = new BaggageSchemaResolver();
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);

$resolver->setSchema('test-schema/foo');

Expand All @@ -85,12 +85,24 @@ public function testConnectSkipsWhenNoSchema(): void
{
$driverConnection = $this->createMock(DriverConnection::class);

$driverConnection->expects($this->once())
->method('exec')
->with('SET search_path TO "public"');

$driver = $this->createMock(Driver::class);

$driver->method('connect')->willReturn($driverConnection);

$connection = new SchemaConnection([], $driver, new Configuration());
$resolver = new BaggageSchemaResolver();
$platform = new PostgreSQLPlatform();
$connection = $this->getMockBuilder(SchemaConnection::class)
->setConstructorArgs([[], $driver, new Configuration(), new EventManager()])
->onlyMethods(['getDatabasePlatform', 'fetchOne'])
->getMock();

$connection->method('getDatabasePlatform')->willReturn($platform);
$connection->method('fetchOne')->willReturn(true);

$resolver = new BaggageSchemaResolver('public', 'development', ['development']);

SchemaConnection::setSchemaResolver($resolver);

Expand All @@ -114,7 +126,7 @@ public function testThrowsForUnsupportedPlatform(): void

$connection->method('getDatabasePlatform')->willReturn($platform);

$resolver = new BaggageSchemaResolver();
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);

$resolver->setSchema('test_schema');

Expand Down
Loading