Skip to content

Commit 8c234b0

Browse files
Merge pull request #13 from MacPaw/feat/update-core-bundle
feat: update schema context bundle to ^2.0
2 parents a80ed37 + ff45b95 commit 8c234b0

10 files changed

+47
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"doctrine/orm": "^2.17 || ^3.0",
1919
"symfony/doctrine-bridge": "^6.4 || ^7.0",
2020
"doctrine/dbal": "^3.4",
21-
"macpaw/schema-context-bundle": "^1.1"
21+
"macpaw/schema-context-bundle": "^2.0"
2222
},
2323
"require-dev": {
2424
"doctrine/migrations": "^3.6",

src/Command/Doctrine/AbstractDoctrineSchemaCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Connection;
88
use Error;
9+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputArgument;
1112
use Symfony\Component\Console\Input\InputInterface;
@@ -15,6 +16,7 @@ abstract class AbstractDoctrineSchemaCommand extends Command
1516
public function __construct(
1617
string $commandName,
1718
protected readonly Connection $connection,
19+
protected readonly BaggageSchemaResolver $schemaResolver,
1820
) {
1921
parent::__construct($commandName);
2022
}
@@ -53,6 +55,7 @@ protected function isSchemaExist(string $schema): bool
5355

5456
protected function switchToSchema(string $schema): void
5557
{
58+
$this->schemaResolver->setSchema($schema);
5659
$quotedSchema = $this->connection->quoteIdentifier($schema);
5760

5861
$this->connection->executeStatement("SET search_path TO {$quotedSchema}");

src/Command/Doctrine/AbstractNestingDoctrineSchemaCommand.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Connection;
88
use Error;
9+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\ArrayInput;
1112
use Symfony\Component\Console\Input\InputArgument;
@@ -19,8 +20,9 @@ public function __construct(
1920
string $commandName,
2021
private readonly Command $parentCommand,
2122
Connection $connection,
23+
BaggageSchemaResolver $schemaResolver,
2224
) {
23-
parent::__construct($commandName, $connection);
25+
parent::__construct($commandName, $connection, $schemaResolver);
2426
}
2527

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

7779
$options = [];
7880
foreach ($input->getOptions() as $name => $value) {
79-
if ($value === null) {
80-
continue;
81-
}
82-
8381
if ($this->getDefinition()->getOptions()[$name]->getDefault() === $value) {
8482
continue;
8583
}

src/Command/Doctrine/DoctrineSchemaDropCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Macpaw\PostgresSchemaBundle\Command\Doctrine;
66

77
use Doctrine\DBAL\Connection;
8+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputInterface;
1011
use Symfony\Component\Console\Output\OutputInterface;
@@ -16,9 +17,10 @@ class DoctrineSchemaDropCommand extends AbstractDoctrineSchemaCommand
1617
*/
1718
public function __construct(
1819
Connection $connection,
20+
BaggageSchemaResolver $schemaResolver,
1921
private readonly array $disallowedSchemaNames = [],
2022
) {
21-
parent::__construct('doctrine:database:schema:drop', $connection);
23+
parent::__construct('doctrine:database:schema:drop', $connection, $schemaResolver);
2224
}
2325

2426
protected function execute(

src/Command/Doctrine/DoctrineSchemaFixturesLoadCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
88
use Doctrine\DBAL\Connection;
9+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Output\OutputInterface;
@@ -19,9 +20,10 @@ class DoctrineSchemaFixturesLoadCommand extends AbstractNestingDoctrineSchemaCom
1920
public function __construct(
2021
LoadDataFixturesDoctrineCommand $parentCommand,
2122
Connection $connection,
23+
BaggageSchemaResolver $schemaResolver,
2224
private readonly array $disallowedSchemaNames = [],
2325
) {
24-
parent::__construct('doctrine:schema:fixtures:load', $parentCommand, $connection);
26+
parent::__construct('doctrine:schema:fixtures:load', $parentCommand, $connection, $schemaResolver);
2527
}
2628

2729
protected function execute(

src/Command/Doctrine/DoctrineSchemaMigrationsMigrateCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Connection;
88
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
9+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Input\InputInterface;
1112
use Symfony\Component\Console\Output\OutputInterface;
@@ -16,8 +17,9 @@ class DoctrineSchemaMigrationsMigrateCommand extends AbstractNestingDoctrineSche
1617
public function __construct(
1718
MigrateCommand $parentCommand,
1819
Connection $connection,
20+
BaggageSchemaResolver $schemaResolver,
1921
) {
20-
parent::__construct('doctrine:schema:migrations:migrate', $parentCommand, $connection);
22+
parent::__construct('doctrine:schema:migrations:migrate', $parentCommand, $connection, $schemaResolver);
2123
}
2224

2325
protected function execute(

tests/Command/Doctrine/DoctrineSchemaDropCommandTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Connection;
88
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaDropCommand;
9+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
910
use PHPUnit\Framework\MockObject\MockObject;
1011
use PHPUnit\Framework\TestCase;
1112
use Symfony\Component\Console\Command\Command;
@@ -20,7 +21,8 @@ class DoctrineSchemaDropCommandTest extends TestCase
2021
protected function setUp(): void
2122
{
2223
$this->connection = $this->createMock(Connection::class);
23-
$this->command = new DoctrineSchemaDropCommand($this->connection, ['public']);
24+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
25+
$this->command = new DoctrineSchemaDropCommand($this->connection, $resolver, ['public']);
2426
}
2527

2628
public function testSuccess(): void

tests/Command/Doctrine/DoctrineSchemaFixturesLoadCommandTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\Bundle\FixturesBundle\Command\LoadDataFixturesDoctrineCommand;
88
use Doctrine\DBAL\Connection;
99
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaFixturesLoadCommand;
10+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
1011
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
1213
use Symfony\Component\Console\Application;
@@ -33,8 +34,14 @@ protected function setUp(): void
3334
->willReturn(new InputDefinition([
3435
new InputOption('no-interaction'),
3536
]));
37+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
3638

37-
$this->command = new DoctrineSchemaFixturesLoadCommand($this->parentCommand, $this->connection, ['public']);
39+
$this->command = new DoctrineSchemaFixturesLoadCommand(
40+
$this->parentCommand,
41+
$this->connection,
42+
$resolver,
43+
['public']
44+
);
3845
$this->command->setApplication($this->application);
3946
}
4047

tests/Command/Doctrine/DoctrineSchemaMigrationsMigrateCommandTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Doctrine\DBAL\Connection;
88
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;
99
use Macpaw\PostgresSchemaBundle\Command\Doctrine\DoctrineSchemaMigrationsMigrateCommand;
10+
use Macpaw\SchemaContextBundle\Service\BaggageSchemaResolver;
1011
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\TestCase;
1213
use Symfony\Component\Console\Application;
@@ -32,8 +33,9 @@ protected function setUp(): void
3233
->willReturn(new InputDefinition([
3334
new InputOption('no-interaction'),
3435
]));
36+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
3537

36-
$this->command = new DoctrineSchemaMigrationsMigrateCommand($this->parentCommand, $this->connection);
38+
$this->command = new DoctrineSchemaMigrationsMigrateCommand($this->parentCommand, $this->connection, $resolver);
3739
$this->application = $this->createMock(Application::class);
3840
$this->command->setApplication($this->application);
3941
}

tests/Doctrine/SchemaConnectionTest.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function testConnectSetsSearchPath(): void
3838
$connection->method('getDatabasePlatform')->willReturn($platform);
3939
$connection->method('fetchOne')->willReturn(true);
4040

41-
$resolver = new BaggageSchemaResolver();
41+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
4242

4343
$resolver->setSchema('test_schema');
4444

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

73-
$resolver = new BaggageSchemaResolver();
73+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
7474

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

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

88+
$driverConnection->expects($this->once())
89+
->method('exec')
90+
->with('SET search_path TO "public"');
91+
8892
$driver = $this->createMock(Driver::class);
8993

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

92-
$connection = new SchemaConnection([], $driver, new Configuration());
93-
$resolver = new BaggageSchemaResolver();
96+
$platform = new PostgreSQLPlatform();
97+
$connection = $this->getMockBuilder(SchemaConnection::class)
98+
->setConstructorArgs([[], $driver, new Configuration(), new EventManager()])
99+
->onlyMethods(['getDatabasePlatform', 'fetchOne'])
100+
->getMock();
101+
102+
$connection->method('getDatabasePlatform')->willReturn($platform);
103+
$connection->method('fetchOne')->willReturn(true);
104+
105+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
94106

95107
SchemaConnection::setSchemaResolver($resolver);
96108

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

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

117-
$resolver = new BaggageSchemaResolver();
129+
$resolver = new BaggageSchemaResolver('public', 'development', ['development']);
118130

119131
$resolver->setSchema('test_schema');
120132

0 commit comments

Comments
 (0)