diff --git a/src/ProductVote/Dao/ProductVoteDao.php b/src/ProductVote/Dao/ProductVoteDao.php index a0a8293..b49ede8 100644 --- a/src/ProductVote/Dao/ProductVoteDao.php +++ b/src/ProductVote/Dao/ProductVoteDao.php @@ -47,7 +47,7 @@ public function getProductVote(string $productId, string $userId): ?ProductVoteI return null; } - return $this->dataMapper->map($row); + return $this->dataMapper->mapFromDbRow($row); } public function setProductVote(ProductVoteInterface $vote): void diff --git a/src/ProductVote/Dao/VoteResultDao.php b/src/ProductVote/Dao/VoteResultDao.php index dfa2f6d..83c3e2b 100644 --- a/src/ProductVote/Dao/VoteResultDao.php +++ b/src/ProductVote/Dao/VoteResultDao.php @@ -46,6 +46,6 @@ public function getProductVoteResult(string $productId): VoteResultInterface if (!$row) { return new VoteResult($productId, 0, 0); } - return $this->dataMapper->map($row); + return $this->dataMapper->mapFromDbRow($row); } } diff --git a/src/ProductVote/DataMapper/ProductVoteDataMapper.php b/src/ProductVote/DataMapper/ProductVoteDataMapper.php index 7cfd420..29f47fc 100644 --- a/src/ProductVote/DataMapper/ProductVoteDataMapper.php +++ b/src/ProductVote/DataMapper/ProductVoteDataMapper.php @@ -14,7 +14,7 @@ readonly class ProductVoteDataMapper implements ProductVoteDataMapperInterface { - public function map(array $data): ProductVote + public function mapFromDbRow(array $data): ProductVote { if (!isset($data['ProductId']) || !isset($data['UserId']) || !isset($data['Vote'])) { throw new MapDataTypeException(); diff --git a/src/ProductVote/DataMapper/ProductVoteDataMapperInterface.php b/src/ProductVote/DataMapper/ProductVoteDataMapperInterface.php index be77aee..b183762 100644 --- a/src/ProductVote/DataMapper/ProductVoteDataMapperInterface.php +++ b/src/ProductVote/DataMapper/ProductVoteDataMapperInterface.php @@ -13,5 +13,5 @@ interface ProductVoteDataMapperInterface { - public function map(array $data): ProductVote; + public function mapFromDbRow(array $data): ProductVote; } diff --git a/src/ProductVote/DataMapper/VoteResultDataMapper.php b/src/ProductVote/DataMapper/VoteResultDataMapper.php index f85d53f..2625c11 100644 --- a/src/ProductVote/DataMapper/VoteResultDataMapper.php +++ b/src/ProductVote/DataMapper/VoteResultDataMapper.php @@ -14,7 +14,7 @@ readonly class VoteResultDataMapper implements VoteResultDataMapperInterface { - public function map(array $data): VoteResult + public function mapFromDbRow(array $data): VoteResult { if (!isset($data['ProductId']) || !isset($data['VoteUp']) || !isset($data['VoteDown'])) { throw new MapDataTypeException(); diff --git a/src/ProductVote/DataMapper/VoteResultDataMapperInterface.php b/src/ProductVote/DataMapper/VoteResultDataMapperInterface.php index 7466971..18b6285 100644 --- a/src/ProductVote/DataMapper/VoteResultDataMapperInterface.php +++ b/src/ProductVote/DataMapper/VoteResultDataMapperInterface.php @@ -13,5 +13,5 @@ interface VoteResultDataMapperInterface { - public function map(array $data): VoteResult; + public function mapFromDbRow(array $data): VoteResult; } diff --git a/tests/Integration/ProductVote/Controller/ArticleDetailsControllerTest.php b/tests/Integration/ProductVote/Controller/ArticleDetailsControllerTest.php index 8651c53..eaed3a8 100644 --- a/tests/Integration/ProductVote/Controller/ArticleDetailsControllerTest.php +++ b/tests/Integration/ProductVote/Controller/ArticleDetailsControllerTest.php @@ -15,7 +15,6 @@ use OxidEsales\ModuleTemplate\ProductVote\Service\VoteServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; -use PHPUnit\Framework\MockObject\Stub; use PHPUnit\Framework\TestCase; #[CoversClass(ArticleDetailsController::class)] @@ -58,12 +57,12 @@ public function voteNotLoggedIn(): void #[Test] public function voteUp(): void { - $voteServiceSpy = $this->getVoteServiceSpy( - 'setProductVote', - $this->getProductStub(), - $this->getUserStub(), - true, - ); + $voteServiceSpy = $this->createMock(VoteServiceInterface::class); + $voteServiceSpy + ->expects($this->once()) + ->method('setProductVote') + ->with($this->getProductStub()); + $sut = $this->getSutMock($voteServiceSpy); $sut->voteUp(); @@ -72,12 +71,12 @@ public function voteUp(): void #[Test] public function voteDown(): void { - $voteServiceSpy = $this->getVoteServiceSpy( - 'setProductVote', - $this->getProductStub(), - $this->getUserStub(), - false, - ); + $voteServiceSpy = $this->createMock(VoteServiceInterface::class); + $voteServiceSpy + ->expects($this->once()) + ->method('setProductVote') + ->with($this->getProductStub()); + $sut = $this->getSutMock($voteServiceSpy); $sut->voteDown(); @@ -86,28 +85,18 @@ public function voteDown(): void #[Test] public function resetVote(): void { - $voteServiceSpy = $this->getVoteServiceSpy( - 'resetProductVote', - $this->getProductStub(), - $this->getUserStub(), - ); + $voteServiceSpy = $this->createMock(VoteServiceInterface::class); + $voteServiceSpy + ->expects($this->once()) + ->method('resetProductVote') + ->with($this->getProductStub()); + $sut = $this->getSutMock($voteServiceSpy); $sut->resetVote(); } - private function getVoteServiceSpy(string $method, mixed ...$arguments): VoteServiceInterface - { - $daoSpy = $this->createMock(VoteServiceInterface::class); - $daoSpy - ->expects($this->once()) - ->method($method) - ->with(...$arguments); - - return $daoSpy; - } - - private function getProductStub(): Article|Stub + private function getProductStub(): Article { $productStub = $this->createStub(Article::class); $productStub @@ -117,7 +106,7 @@ private function getProductStub(): Article|Stub return $productStub; } - private function getUserStub(): User|Stub + private function getUserStub(): User { $userStub = $this->createStub(User::class); $userStub diff --git a/tests/Integration/ProductVote/Dao/DaoTestTrait.php b/tests/Integration/ProductVote/Dao/DaoTestTrait.php index 12bcbed..5870ef6 100644 --- a/tests/Integration/ProductVote/Dao/DaoTestTrait.php +++ b/tests/Integration/ProductVote/Dao/DaoTestTrait.php @@ -17,7 +17,7 @@ trait DaoTestTrait protected const TEST_USER_ID = '_testuser'; protected const TEST_PRODUCT_ID = '_testproduct'; - protected function getVoteQueryResult(): Result + protected function getProductVoteQueryResult(): Result { $queryBuilder = $this->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilder @@ -35,7 +35,7 @@ protected function getVoteQueryResult(): Result return $result; } - protected function executeInsertVoteQuery(bool $isVoteUp, string $userId = self::TEST_USER_ID): void + protected function executeInsertProductVoteQuery(bool $isVoteUp, string $userId = self::TEST_USER_ID): void { $queryBuilder = $this->get(QueryBuilderFactoryInterface::class)->create(); $queryBuilder diff --git a/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php b/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php index db733d7..bd50d50 100644 --- a/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php +++ b/tests/Integration/ProductVote/Dao/ProductVoteDaoTest.php @@ -36,7 +36,7 @@ public function noVoteForNoRecord(): void public function getUpVote(bool $value): void { $isVoteUp = $value; - $this->executeInsertVoteQuery($isVoteUp); + $this->executeInsertProductVoteQuery($isVoteUp); $sut = $this->get(ProductVoteDaoInterface::class); @@ -58,7 +58,7 @@ public function setVote(bool $value): void $sut = $this->get(ProductVoteDaoInterface::class); $sut->setProductVote($vote); - $result = $this->getVoteQueryResult(); + $result = $this->getProductVoteQueryResult(); $this->assertEquals(1, $result->rowCount()); $this->assertEquals( [ @@ -88,7 +88,7 @@ public function replaceVote(): void $sut->setProductVote($upVote); $sut->setProductVote($downVote); - $result = $this->getVoteQueryResult(); + $result = $this->getProductVoteQueryResult(); $this->assertEquals(1, $result->rowCount()); $this->assertEquals( [ @@ -106,19 +106,19 @@ public function resetNonExistingVote(): void $sut = $this->get(ProductVoteDaoInterface::class); $sut->resetProductVote(self::TEST_PRODUCT_ID, self::TEST_USER_ID); - $result = $this->getVoteQueryResult(); + $result = $this->getProductVoteQueryResult(); $this->assertEquals(0, $result->rowCount()); } #[Test] public function resetVote(): void { - $this->executeInsertVoteQuery(true); + $this->executeInsertProductVoteQuery(true); $sut = $this->get(ProductVoteDaoInterface::class); $sut->resetProductVote(self::TEST_PRODUCT_ID, self::TEST_USER_ID); - $result = $this->getVoteQueryResult(); + $result = $this->getProductVoteQueryResult(); $this->assertEquals(0, $result->rowCount()); } } diff --git a/tests/Integration/ProductVote/Dao/ResultDaoTest.php b/tests/Integration/ProductVote/Dao/ResultDaoTest.php index 7465346..42b19ed 100644 --- a/tests/Integration/ProductVote/Dao/ResultDaoTest.php +++ b/tests/Integration/ProductVote/Dao/ResultDaoTest.php @@ -33,7 +33,7 @@ public function calculateNoVotes(): void #[Test] public function calculateVoteResult(): void { - $this->executeInsertVoteQuery(true, 'user_1'); + $this->executeInsertProductVoteQuery(true, 'user_1'); $sut = $this->get(VoteResultDaoInterface::class); $result = $sut->getProductVoteResult(self::TEST_PRODUCT_ID); @@ -43,13 +43,13 @@ public function calculateVoteResult(): void #[Test] public function calculateVotesResult(): void { - $this->executeInsertVoteQuery(true, 'user_1'); // 1/0 - $this->executeInsertVoteQuery(false, 'user_2');// 1/1 - $this->executeInsertVoteQuery(false, 'user_3');// 1/2 - $this->executeInsertVoteQuery(false, 'user_4');// 1/3 - $this->executeInsertVoteQuery(true, 'user_5'); // 2/3 - $this->executeInsertVoteQuery(true, 'user_6'); // 3/3 - $this->executeInsertVoteQuery(true, 'user_7'); // 4/3 + $this->executeInsertProductVoteQuery(true, 'user_1'); // 1/0 + $this->executeInsertProductVoteQuery(false, 'user_2');// 1/1 + $this->executeInsertProductVoteQuery(false, 'user_3');// 1/2 + $this->executeInsertProductVoteQuery(false, 'user_4');// 1/3 + $this->executeInsertProductVoteQuery(true, 'user_5'); // 2/3 + $this->executeInsertProductVoteQuery(true, 'user_6'); // 3/3 + $this->executeInsertProductVoteQuery(true, 'user_7'); // 4/3 $sut = $this->get(VoteResultDaoInterface::class); $result = $sut->getProductVoteResult(self::TEST_PRODUCT_ID); diff --git a/tests/Integration/ProductVote/Widget/ArticleDetailsTest.php b/tests/Integration/ProductVote/Widget/ArticleDetailsTest.php index 4872d08..e47ccad 100644 --- a/tests/Integration/ProductVote/Widget/ArticleDetailsTest.php +++ b/tests/Integration/ProductVote/Widget/ArticleDetailsTest.php @@ -78,7 +78,7 @@ private function getSutMock(): ArticleDetails|MockObject return $sut; } - private function getProductStub(): Article|Stub + private function getProductStub(): Article { $productStub = $this->createStub(Article::class); $productStub @@ -88,7 +88,7 @@ private function getProductStub(): Article|Stub return $productStub; } - private function getUserStub(): User|Stub + private function getUserStub(): User { $userStub = $this->createStub(User::class); $userStub diff --git a/tests/Unit/ProductVote/DataMapper/ProductVoteDataMapperTest.php b/tests/Unit/ProductVote/DataMapper/ProductVoteDataMapperTest.php index a98788d..5f84b47 100644 --- a/tests/Unit/ProductVote/DataMapper/ProductVoteDataMapperTest.php +++ b/tests/Unit/ProductVote/DataMapper/ProductVoteDataMapperTest.php @@ -28,7 +28,7 @@ public function mapMalformedData(array $data): void $sut = new ProductVoteDataMapper(); $this->expectException(MapDataTypeException::class); - $sut->map($data); + $sut->mapFromDbRow($data); } public static function mapMalformedDataProvider(): Generator @@ -47,7 +47,7 @@ public static function mapMalformedDataProvider(): Generator public function mapData(ProductVote $expectedVote, array $data): void { $sut = new ProductVoteDataMapper(); - $this->assertEquals($expectedVote, $sut->map($data)); + $this->assertEquals($expectedVote, $sut->mapFromDbRow($data)); } public static function mapDataProvider(): Generator diff --git a/tests/Unit/ProductVote/DataMapper/ResultDataMapperTest.php b/tests/Unit/ProductVote/DataMapper/VoteResultDataMapperTest.php similarity index 92% rename from tests/Unit/ProductVote/DataMapper/ResultDataMapperTest.php rename to tests/Unit/ProductVote/DataMapper/VoteResultDataMapperTest.php index f454187..2175bab 100644 --- a/tests/Unit/ProductVote/DataMapper/ResultDataMapperTest.php +++ b/tests/Unit/ProductVote/DataMapper/VoteResultDataMapperTest.php @@ -19,7 +19,7 @@ use PHPUnit\Framework\TestCase; #[CoversClass(VoteResultDataMapper::class)] -final class ResultDataMapperTest extends TestCase +final class VoteResultDataMapperTest extends TestCase { #[Test] #[DataProvider('mapMalformedDataProvider')] @@ -28,7 +28,7 @@ public function mapMalformedData(array $data): void $sut = new VoteResultDataMapper(); $this->expectException(MapDataTypeException::class); - $sut->map($data); + $sut->mapFromDbRow($data); } public static function mapMalformedDataProvider(): Generator @@ -48,7 +48,7 @@ public static function mapMalformedDataProvider(): Generator public function mapData(VoteResult $expectedResult, array $data): void { $sut = new VoteResultDataMapper(); - $this->assertEquals($expectedResult, $sut->map($data)); + $this->assertEquals($expectedResult, $sut->mapFromDbRow($data)); } public static function mapDataProvider(): Generator