|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Patchlevel\EventSourcing\Tests\Unit\Subscription\Cleanup\Dbal; |
| 6 | + |
| 7 | +use Doctrine\DBAL\Connection; |
| 8 | +use Doctrine\DBAL\Schema\AbstractSchemaManager; |
| 9 | +use Patchlevel\EventSourcing\Subscription\Cleanup\CleanupTaskNotSupported; |
| 10 | +use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DbalCleanupTaskHandler; |
| 11 | +use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DropIndexTask; |
| 12 | +use Patchlevel\EventSourcing\Subscription\Cleanup\Dbal\DropTableTask; |
| 13 | +use PHPUnit\Framework\Attributes\CoversClass; |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use stdClass; |
| 16 | + |
| 17 | +#[CoversClass(DbalCleanupTaskHandler::class)] |
| 18 | +final class DbalCleanupTaskHandlerTest extends TestCase |
| 19 | +{ |
| 20 | + public function testNoSupport(): void |
| 21 | + { |
| 22 | + $handler = new DbalCleanupTaskHandler( |
| 23 | + $this->createMock(Connection::class), |
| 24 | + ); |
| 25 | + |
| 26 | + self::assertFalse($handler->supports(new stdClass())); |
| 27 | + } |
| 28 | + |
| 29 | + public function testSupports(): void |
| 30 | + { |
| 31 | + $handler = new DbalCleanupTaskHandler( |
| 32 | + $this->createMock(Connection::class), |
| 33 | + ); |
| 34 | + |
| 35 | + self::assertTrue($handler->supports(new DropTableTask('test'))); |
| 36 | + self::assertTrue($handler->supports(new DropIndexTask('test', 'test'))); |
| 37 | + } |
| 38 | + |
| 39 | + public function testHandleNoSupportedTask(): void |
| 40 | + { |
| 41 | + $handler = new DbalCleanupTaskHandler( |
| 42 | + $this->createMock(Connection::class), |
| 43 | + ); |
| 44 | + |
| 45 | + $this->expectException(CleanupTaskNotSupported::class); |
| 46 | + |
| 47 | + $handler(new stdClass()); |
| 48 | + } |
| 49 | + |
| 50 | + public function testHandleDropTable(): void |
| 51 | + { |
| 52 | + $schemaManager = $this->createMock(AbstractSchemaManager::class); |
| 53 | + $schemaManager->expects($this->once())->method('dropTable')->with('test'); |
| 54 | + |
| 55 | + $connection = $this->createMock(Connection::class); |
| 56 | + $connection |
| 57 | + ->expects($this->once()) |
| 58 | + ->method('createSchemaManager') |
| 59 | + ->willReturn($schemaManager); |
| 60 | + |
| 61 | + $handler = new DbalCleanupTaskHandler($connection); |
| 62 | + |
| 63 | + $handler(new DropTableTask('test')); |
| 64 | + } |
| 65 | + |
| 66 | + public function testHandleDropIndex(): void |
| 67 | + { |
| 68 | + $schemaManager = $this->createMock(AbstractSchemaManager::class); |
| 69 | + $schemaManager->expects($this->once())->method('dropIndex')->with('foo', 'bar'); |
| 70 | + |
| 71 | + $connection = $this->createMock(Connection::class); |
| 72 | + $connection |
| 73 | + ->expects($this->once()) |
| 74 | + ->method('createSchemaManager') |
| 75 | + ->willReturn($schemaManager); |
| 76 | + |
| 77 | + $handler = new DbalCleanupTaskHandler($connection); |
| 78 | + |
| 79 | + $handler(new DropIndexTask('foo', 'bar')); |
| 80 | + } |
| 81 | +} |
0 commit comments