From c24991bd7df09d033c0e6408be5cd565e08aeec6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 18 Sep 2026 11:17:44 +0200 Subject: [PATCH] refactor(service): remove redundant short methods from IncoService --- src/Service/ArcadiaIncoService.php | 32 ------- src/Service/IncoService.php | 25 ------ tests/Unit/Service/ArcadiaIncoServiceTest.php | 85 ------------------- 3 files changed, 142 deletions(-) diff --git a/src/Service/ArcadiaIncoService.php b/src/Service/ArcadiaIncoService.php index 5b56e94..f043499 100644 --- a/src/Service/ArcadiaIncoService.php +++ b/src/Service/ArcadiaIncoService.php @@ -73,18 +73,6 @@ final class ArcadiaIncoService implements IncoService ); } - /** - * @param BrandCode[]|BrandCode $brands - * @return StreamOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort> - */ - public function streamAllShortOfBrands( - array | BrandCode $brands, - PageSize $pageSize = new PageSize(), - ?IncoSorter $sorter = null, - ): StreamOf { - return $this->streamAllOfBrands($brands, $pageSize, $sorter); - } - /** * @param BrandCode[]|BrandCode $brands * @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError @@ -119,18 +107,6 @@ final class ArcadiaIncoService implements IncoService ); } - /** - * @param BrandCode[]|BrandCode $brands - * @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError - */ - public function getAllShortOfBrands( - Pagination $pagination, - array | BrandCode $brands, - ?IncoSorter $sorter = null - ): PageOf | ApiError { - return $this->getAllOfBrands($pagination, $brands, $sorter); - } - /** @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError */ public function getAll( Pagination $pagination, @@ -154,14 +130,6 @@ final class ArcadiaIncoService implements IncoService ); } - /** - * @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError - */ - public function findShortByIncoIdLike(string $incoIdLike, BrandCode ...$onBrands): PageOf | ApiError - { - return $this->findByIncoIdLike($incoIdLike, ...$onBrands); - } - public function findBy(IncoId $id): Inco | null | ApiError { return $this->incoRepository->find($id); diff --git a/src/Service/IncoService.php b/src/Service/IncoService.php index 736ab18..09bdfb5 100644 --- a/src/Service/IncoService.php +++ b/src/Service/IncoService.php @@ -45,16 +45,6 @@ interface IncoService \SortDirection $sortDirection = \SortDirection::Descending, ): StreamOf; - /** - * @param BrandCode[]|BrandCode $brands - * @return StreamOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort> - */ - public function streamAllShortOfBrands( - array | BrandCode $brands, - PageSize $pageSize = new PageSize(), - ?IncoSorter $sorter = null, - ): StreamOf; - /** * @param BrandCode[]|BrandCode $brands * @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError @@ -76,16 +66,6 @@ interface IncoService ?IncoSorter $sorter = null ): PageOf | ApiError; - /** - * @param BrandCode[]|BrandCode $brands - * @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError - */ - public function getAllShortOfBrands( - Pagination $pagination, - array | BrandCode $brands, - ?IncoSorter $sorter = null - ): PageOf | ApiError; - /** @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError */ public function getAll( Pagination $pagination, @@ -97,11 +77,6 @@ interface IncoService */ public function findByIncoIdLike(string $incoIdLike, BrandCode ...$onBrands): PageOf | ApiError; - /** - * @return PageOf<\Uwil\ArcadiaApiPhpClient\Lib\ApiDto\Dto\IncoShort>|ApiError - */ - public function findShortByIncoIdLike(string $incoIdLike, BrandCode ...$onBrands): PageOf | ApiError; - public function findBy(IncoId $id): Inco | null | ApiError; public function findCompo(IncoId | IncoCompoId $id): IncoCompo | null | ApiError; diff --git a/tests/Unit/Service/ArcadiaIncoServiceTest.php b/tests/Unit/Service/ArcadiaIncoServiceTest.php index 4f70bf9..92058b3 100644 --- a/tests/Unit/Service/ArcadiaIncoServiceTest.php +++ b/tests/Unit/Service/ArcadiaIncoServiceTest.php @@ -208,32 +208,6 @@ describe('ArcadiaIncoService', function () { }); }); - describe('getAllShortOfBrands', function () { - it('returns PageOf of IncoShort when repository succeeds', function () { - // GIVEN - $pagination = Pagination::firstPage(); - $brand = new BrandCode('LGL39'); - $expectedPage = new PageOf( - new PaginationDto(page: 1, pageSize: 50, totalItems: 1, totalPages: 1), - [dummyIncoShortForService()] - ); - - [$incoRepo, $shortRepo, $compoRepo] = serviceIncoMocks(); - $shortRepo->shouldReceive('selectAllHavingBrands') - ->once() - ->with($pagination, [$brand], null) - ->andReturn($expectedPage); - - $service = new ArcadiaIncoService($incoRepo, $shortRepo, $compoRepo); - - // WHEN - $result = $service->getAllShortOfBrands($pagination, $brand); - - // THEN - expect($result)->toBe($expectedPage); - }); - }); - describe('findByIncoIdLike', function () { it('returns PageOf when search succeeds', function () { // GIVEN @@ -268,40 +242,6 @@ describe('ArcadiaIncoService', function () { }); }); - describe('findShortByIncoIdLike', function () { - it('returns PageOf of IncoShort when search succeeds', function () { - // GIVEN - $brand = new BrandCode('LGL39'); - $expectedPage = new PageOf( - new PaginationDto(page: 1, pageSize: 50, totalItems: 1, totalPages: 1), - [dummyIncoShortForService()] - ); - - [$incoRepo, $shortRepo, $compoRepo] = serviceIncoMocks(); - $shortRepo->shouldReceive('findWhere') - ->once() - ->andReturn($expectedPage); - - $service = new ArcadiaIncoService($incoRepo, $shortRepo, $compoRepo); - - // WHEN - $result = $service->findShortByIncoIdLike('poulet', $brand); - - // THEN - expect($result)->toBe($expectedPage); - }); - - it('throws InvalidArgumentException when no brands are passed', function () { - // GIVEN - [$incoRepo, $shortRepo, $compoRepo] = serviceIncoMocks(); - $service = new ArcadiaIncoService($incoRepo, $shortRepo, $compoRepo); - - // WHEN / THEN - expect(fn () => $service->findShortByIncoIdLike('poulet')) - ->toThrow(\InvalidArgumentException::class, 'At least 1 brand code is required'); - }); - }); - describe('findBy', function () { it('returns Inco when found', function () { // GIVEN @@ -500,30 +440,5 @@ describe('ArcadiaIncoService', function () { expect($items)->toHaveCount(1); expect($items[0])->toBe($incoShort); }); - - it('streamAllShortOfBrands returns StreamOf yielding inco shorts', function () { - // GIVEN - $incoShort = dummyIncoShortForService(); - $expectedPage = new PageOf( - new PaginationDto(page: 1, pageSize: 50, totalItems: 1, totalPages: 1), - [$incoShort] - ); - - [$incoRepo, $shortRepo, $compoRepo] = serviceIncoMocks(); - $shortRepo->shouldReceive('selectAllHavingBrands') - ->once() - ->andReturn($expectedPage); - - $service = new ArcadiaIncoService($incoRepo, $shortRepo, $compoRepo); - - // WHEN - $stream = $service->streamAllShortOfBrands(new BrandCode('LGL39')); - $items = iterator_to_array($stream); - - // THEN - expect($stream)->toBeInstanceOf(StreamOf::class); - expect($items)->toHaveCount(1); - expect($items[0])->toBe($incoShort); - }); }); });