|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Brainbits\FunctionalTestHelpers\Tests\Schema; |
| 6 | + |
| 7 | +use Brainbits\FunctionalTestHelpers\Schema\CreateApplySchema; |
| 8 | +use Brainbits\FunctionalTestHelpers\Schema\NoApplySchemaStrategyFound; |
| 9 | +use Brainbits\FunctionalTestHelpers\Schema\SqliteFileBasedApplySchema; |
| 10 | +use Brainbits\FunctionalTestHelpers\Schema\SqliteMemoryBasedApplySchema; |
| 11 | +use Doctrine\DBAL\Connection; |
| 12 | +use PHPUnit\Framework\TestCase; |
| 13 | + |
| 14 | +/** @covers \Brainbits\FunctionalTestHelpers\Schema\SqliteFileBasedApplySchema */ |
| 15 | +final class CreateApplySchemaTest extends TestCase |
| 16 | +{ |
| 17 | + public function testItUsesSqliteMemoryStrategyIfConfiguredByUrl(): void |
| 18 | + { |
| 19 | + $connection = $this->createMock(Connection::class); |
| 20 | + $connection->expects($this->once()) |
| 21 | + ->method('getParams') |
| 22 | + ->willReturn(['url' => 'sqlite://:memory:']); |
| 23 | + |
| 24 | + $applySchema = (new CreateApplySchema())($connection); |
| 25 | + |
| 26 | + $this->assertInstanceOf(SqliteMemoryBasedApplySchema::class, $applySchema); |
| 27 | + } |
| 28 | + |
| 29 | + public function testItUsesSqliteMemoryStrategyIfConfiguredByParams(): void |
| 30 | + { |
| 31 | + $connection = $this->createMock(Connection::class); |
| 32 | + $connection->expects($this->once()) |
| 33 | + ->method('getParams') |
| 34 | + ->willReturn(['driver' => 'pdo_sqlite', 'memory' => true]); |
| 35 | + |
| 36 | + $applySchema = (new CreateApplySchema())($connection); |
| 37 | + |
| 38 | + $this->assertInstanceOf(SqliteMemoryBasedApplySchema::class, $applySchema); |
| 39 | + } |
| 40 | + |
| 41 | + public function testItUsesSqliteFileStrategyIfConfiguredByUrl(): void |
| 42 | + { |
| 43 | + $connection = $this->createMock(Connection::class); |
| 44 | + $connection->expects($this->once()) |
| 45 | + ->method('getParams') |
| 46 | + ->willReturn(['url' => 'sqlite:///tmp/my.db', 'path' => '/tmp/my.db']); |
| 47 | + |
| 48 | + $applySchema = (new CreateApplySchema())($connection); |
| 49 | + |
| 50 | + $this->assertInstanceOf(SqliteFileBasedApplySchema::class, $applySchema); |
| 51 | + } |
| 52 | + |
| 53 | + public function testItUsesSqliteStrategyIfConfiguredByParams(): void |
| 54 | + { |
| 55 | + $connection = $this->createMock(Connection::class); |
| 56 | + $connection->expects($this->once()) |
| 57 | + ->method('getParams') |
| 58 | + ->willReturn(['driver' => 'pdo_sqlite', 'path' => '/tmp/my.db']); |
| 59 | + |
| 60 | + $applySchema = (new CreateApplySchema())($connection); |
| 61 | + |
| 62 | + $this->assertInstanceOf(SqliteFileBasedApplySchema::class, $applySchema); |
| 63 | + } |
| 64 | + |
| 65 | + public function testItThrowsException(): void |
| 66 | + { |
| 67 | + $this->expectException(NoApplySchemaStrategyFound::class); |
| 68 | + $this->expectExceptionMessage('No apply schema strategy found for connection parameters: {"key":"value"}'); |
| 69 | + |
| 70 | + $connection = $this->createMock(Connection::class); |
| 71 | + $connection->expects($this->once()) |
| 72 | + ->method('getParams') |
| 73 | + ->willReturn(['key' => 'value']); |
| 74 | + |
| 75 | + $applySchema = (new CreateApplySchema())($connection); |
| 76 | + |
| 77 | + $this->assertInstanceOf(SqliteFileBasedApplySchema::class, $applySchema); |
| 78 | + } |
| 79 | +} |
0 commit comments