From c164a1a7509d5cf460bbcbc5dca5785b960ca9f3 Mon Sep 17 00:00:00 2001 From: marcelmanzel Date: Tue, 6 Aug 2024 10:12:14 +0200 Subject: [PATCH] OXDEV-8215: Refactor and improve some tests --- .../ThemeListInfrastructureTest.php | 6 +++--- .../ThemeListInfrastructureTest.php | 19 +++---------------- .../Theme/Service/ThemeListServiceTest.php | 6 +++++- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php b/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php index 621533d..18b4312 100644 --- a/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php +++ b/tests/Integration/Infrastructure/ThemeListInfrastructureTest.php @@ -36,10 +36,10 @@ public function testGetThemesValidData(): void } } - public function getSut(): ThemeListInfrastructure { + public function getSut(): ThemeListInfrastructure + { return new ThemeListInfrastructure( - $this->get(CoreThemeFactoryInterface::class), - $this->get(ThemeDataTypeFactoryInterface::class) + $this->get(CoreThemeFactoryInterface::class), ); } } diff --git a/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php b/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php index 39caa9e..bb57880 100644 --- a/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php +++ b/tests/Unit/Theme/Infrastructure/ThemeListInfrastructureTest.php @@ -25,21 +25,8 @@ class ThemeListInfrastructureTest extends TestCase { public function testGetThemes(): void { - $theme1 = [ - 'title' => uniqid(), - 'id' => uniqid(), - 'version' => uniqid(), - 'description' => uniqid(), - 'active' => true - ]; - - $theme2 = [ - 'title' => uniqid(), - 'id' => uniqid(), - 'version' => uniqid(), - 'description' => uniqid(), - 'active' => false - ]; + $theme1 = $this->createStub(Theme::class); + $theme2 = $this->createStub(Theme::class); $coreThemeMock = $this->createMock(Theme::class); $coreThemeMock->expects($this->once())->method('getList') @@ -49,7 +36,7 @@ public function testGetThemes(): void $sut = $this->getSut(coreThemeFactory: $coreThemeFactoryMock); $actualThemesArray = $sut->getThemes(); - $this->assertEquals([$theme1, $theme2], $actualThemesArray); + $this->assertSame([$theme1, $theme2], $actualThemesArray); } public function testGetThemesThrowsException(): void diff --git a/tests/Unit/Theme/Service/ThemeListServiceTest.php b/tests/Unit/Theme/Service/ThemeListServiceTest.php index 2894f18..d51c731 100644 --- a/tests/Unit/Theme/Service/ThemeListServiceTest.php +++ b/tests/Unit/Theme/Service/ThemeListServiceTest.php @@ -39,8 +39,12 @@ public function testGetThemeListWithFilters(): void $themeDataTypeFactoryMock = $this->createMock(ThemeDataTypeFactoryInterface::class); $themeDataTypeFactoryMock + ->expects($this->exactly(2)) ->method('createFromCoreTheme') - ->willReturnOnConsecutiveCalls($themeList[0], $themeList[1]); + ->willReturnMap([ + [$themes[0], $themeList[0]], + [$themes[1], $themeList[1]] + ]); $filtersList = new ThemeFilters( titleFilter: new StringFilter(contains: uniqid()),