diff --git a/src/Sql/Sql.php b/src/Sql/Sql.php index 50b45e48..08c6702d 100644 --- a/src/Sql/Sql.php +++ b/src/Sql/Sql.php @@ -6,6 +6,8 @@ use PhpDb\Adapter\AdapterInterface; use PhpDb\Adapter\Driver\StatementInterface; +use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\SqlInterface; use function sprintf; @@ -15,7 +17,7 @@ class Sql protected TableIdentifier|string|array|null $table; - protected Platform\Platform $sqlPlatform; + protected PlatformDecoratorInterface|PreparableSqlInterface $sqlPlatform; public function __construct( AdapterInterface $adapter, @@ -23,7 +25,7 @@ public function __construct( ) { $this->adapter = $adapter; $this->table = $table; - $this->sqlPlatform = new Platform\Platform($adapter->getPlatform()); + $this->sqlPlatform = $this->adapter->getPlatform()->getSqlPlatformDecorator(); } public function getAdapter(): ?AdapterInterface @@ -51,7 +53,7 @@ public function getTable(): array|string|TableIdentifier|null return $this->table; } - public function getSqlPlatform(): ?Platform\Platform + public function getSqlPlatform(): ?PlatformDecoratorInterface { return $this->sqlPlatform; } diff --git a/test/unit/RowGateway/AbstractRowGatewayTest.php b/test/unit/RowGateway/AbstractRowGatewayTest.php index af6f1243..1aa762b9 100644 --- a/test/unit/RowGateway/AbstractRowGatewayTest.php +++ b/test/unit/RowGateway/AbstractRowGatewayTest.php @@ -16,6 +16,8 @@ use PhpDb\RowGateway\Exception\RuntimeException; use PhpDb\RowGateway\Feature\FeatureSet; use PhpDb\RowGateway\RowGateway; +use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\PreparableSqlInterface; use PhpDb\Sql\Select; use PhpDb\Sql\Sql; use PHPUnit\Framework\Attributes\CoversMethod; @@ -72,12 +74,16 @@ protected function setUp(): void $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement); $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection); + $mockPlatform = $this->createStubForIntersectionOfInterfaces( + [PlatformInterface::class, PlatformDecoratorInterface::class, PreparableSqlInterface::class] + ); + $this->mockAdapter = $this->getMockBuilder(Adapter::class) ->onlyMethods([]) ->setConstructorArgs( [ $mockDriver, - $this->getMockBuilder(PlatformInterface::class)->getMock(), + $mockPlatform, ] )->getMock(); diff --git a/test/unit/RowGateway/RowGatewayTest.php b/test/unit/RowGateway/RowGatewayTest.php index f0fd2ffb..282f694f 100644 --- a/test/unit/RowGateway/RowGatewayTest.php +++ b/test/unit/RowGateway/RowGatewayTest.php @@ -14,6 +14,8 @@ use PhpDb\RowGateway\Exception\InvalidArgumentException; use PhpDb\RowGateway\Exception\RuntimeException; use PhpDb\RowGateway\RowGateway; +use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\PreparableSqlInterface; use PhpDb\Sql\Sql; use PhpDb\Sql\TableIdentifier; use PHPUnit\Framework\MockObject\MockObject; @@ -46,12 +48,16 @@ protected function setUp(): void $mockDriver->expects($this->any())->method('createStatement')->willReturn($mockStatement); $mockDriver->expects($this->any())->method('getConnection')->willReturn($mockConnection); + $mockPlatform = $this->createStubForIntersectionOfInterfaces( + [PlatformInterface::class, PlatformDecoratorInterface::class, PreparableSqlInterface::class] + ); + $this->mockAdapter = $this->getMockBuilder(Adapter::class) ->onlyMethods([]) ->setConstructorArgs( [ $mockDriver, - $this->getMockBuilder(PlatformInterface::class)->getMock(), + $mockPlatform, ] )->getMock(); } diff --git a/test/unit/TableGateway/AbstractTableGatewayTest.php b/test/unit/TableGateway/AbstractTableGatewayTest.php index b6c14f79..f91f36f5 100644 --- a/test/unit/TableGateway/AbstractTableGatewayTest.php +++ b/test/unit/TableGateway/AbstractTableGatewayTest.php @@ -16,6 +16,8 @@ use PhpDb\Sql; use PhpDb\Sql\Delete; use PhpDb\Sql\Insert; +use PhpDb\Sql\Platform\PlatformDecoratorInterface; +use PhpDb\Sql\PreparableSqlInterface; use PhpDb\Sql\Select; use PhpDb\Sql\Update; use PhpDb\TableGateway\AbstractTableGateway; @@ -78,7 +80,10 @@ protected function setUp(): void $mockResult = $this->getMockBuilder(ResultInterface::class)->getMock(); $mockResult->expects($this->any())->method('getAffectedRows')->willReturn(5); - $mockPlatform = $this->getMockBuilder(PlatformInterface::class)->getMock(); + //$mockPlatform = $this->getMockBuilder(PlatformInterface::class)->getMock(); + $mockPlatform = $this->createStubForIntersectionOfInterfaces( + [PlatformInterface::class, PlatformDecoratorInterface::class, PreparableSqlInterface::class] + ); $mockResultSet = $this->getMockBuilder(ResultSetInterface::class)->getMock();