|
6 | 6 |
|
7 | 7 | use Doctrine\DBAL\Connection; |
8 | 8 | use Doctrine\DBAL\Schema\AbstractSchemaManager; |
| 9 | +use Doctrine\Persistence\ConnectionRegistry; |
9 | 10 | use Patchlevel\EventSourcing\Subscription\Cleanup\CleanupTaskNotSupported; |
| 11 | +use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\ConnectionNameNotSupported; |
10 | 12 | use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DbalCleanupTaskHandler; |
11 | 13 | use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DropIndexTask; |
12 | 14 | use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DropTableTask; |
| 15 | +use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\UnexpectedConnectionType; |
13 | 16 | use PHPUnit\Framework\Attributes\CoversClass; |
14 | 17 | use PHPUnit\Framework\TestCase; |
15 | 18 | use stdClass; |
@@ -78,4 +81,51 @@ public function testHandleDropIndex(): void |
78 | 81 |
|
79 | 82 | $handler(new DropIndexTask('foo', 'bar')); |
80 | 83 | } |
| 84 | + |
| 85 | + public function testHandleWithConnectionRegistry(): void |
| 86 | + { |
| 87 | + $schemaManager = $this->createMock(AbstractSchemaManager::class); |
| 88 | + $schemaManager->expects($this->once())->method('dropTable')->with('test'); |
| 89 | + |
| 90 | + $connection = $this->createMock(Connection::class); |
| 91 | + $connection |
| 92 | + ->expects($this->once()) |
| 93 | + ->method('createSchemaManager') |
| 94 | + ->willReturn($schemaManager); |
| 95 | + |
| 96 | + $registry = $this->createMock(ConnectionRegistry::class); |
| 97 | + $registry |
| 98 | + ->expects($this->once()) |
| 99 | + ->method('getConnection') |
| 100 | + ->with('foo') |
| 101 | + ->willReturn($connection); |
| 102 | + |
| 103 | + $handler = new DbalCleanupTaskHandler($registry); |
| 104 | + |
| 105 | + $handler(new DropTableTask('test', 'foo')); |
| 106 | + } |
| 107 | + |
| 108 | + public function testHandleWithConnectionRegistryAndUnexpectedType(): void |
| 109 | + { |
| 110 | + $registry = $this->createMock(ConnectionRegistry::class); |
| 111 | + $registry |
| 112 | + ->expects($this->once()) |
| 113 | + ->method('getConnection') |
| 114 | + ->with('foo') |
| 115 | + ->willReturn(new stdClass()); |
| 116 | + |
| 117 | + $handler = new DbalCleanupTaskHandler($registry); |
| 118 | + |
| 119 | + $this->expectException(UnexpectedConnectionType::class); |
| 120 | + $handler(new DropTableTask('test', 'foo')); |
| 121 | + } |
| 122 | + |
| 123 | + public function testHandleWithConnectionAndConnectionNameNotSupported(): void |
| 124 | + { |
| 125 | + $connection = $this->createMock(Connection::class); |
| 126 | + $handler = new DbalCleanupTaskHandler($connection); |
| 127 | + |
| 128 | + $this->expectException(ConnectionNameNotSupported::class); |
| 129 | + $handler(new DropTableTask('test', 'foo')); |
| 130 | + } |
81 | 131 | } |
0 commit comments