Skip to content

Commit

Permalink
OXDEV-8213 Improve CoreThemeFactory along test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RahatHameed committed Jul 12, 2024
1 parent 27a41cd commit 69f90a9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Theme/Infrastructure/CoreThemeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class CoreThemeFactory implements CoreThemeFactoryInterface
* @inheritDoc
*/
public function create(): Theme
{
return $this->createTheme();
}

protected function createTheme(): Theme
{
return oxNew(Theme::class);
}
Expand Down
46 changes: 46 additions & 0 deletions tests/Unit/Theme/Infrastructure/CoreThemeFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* Copyright © OXID eSales AG. All rights reserved.
* See LICENSE file for license details.
*/

declare(strict_types=1);

namespace OxidEsales\GraphQL\ConfigurationAccess\Tests\Unit\Theme\Infrastructure;

use OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\CoreThemeFactory;
use PHPUnit\Framework\TestCase;
use OxidEsales\Eshop\Core\Theme;

/**
* @covers \OxidEsales\GraphQL\ConfigurationAccess\Theme\Infrastructure\CoreThemeFactory
*/
class CoreThemeFactoryTest extends TestCase
{
public function testCreateProducesCorrectTypeOfObjects(): void
{
$sut = $this->getSut();
$this->assertInstanceOf(Theme::class, $sut->create());
}

public function testCreateProducesDifferentObjectsOnEveryCall(): void
{
$model1 = $this->getSut()->create();
$model2 = $this->getSut()->create();

$this->assertNotSame($model1, $model2);
}

private function getSut(): CoreThemeFactory
{
$coreThemeFactoryMock = $this->getMockBuilder(CoreThemeFactory::class)
->onlyMethods(['createTheme'])
->getMock();

$coreThemeFactoryMock->method('createTheme')
->willReturn(new Theme());

return $coreThemeFactoryMock;
}
}

0 comments on commit 69f90a9

Please sign in to comment.