Skip to content

Commit 3894aff

Browse files
committed
OXDEV-9497 Rework UserModelFactory test to actually test the code but not a mock
1 parent 7230d96 commit 3894aff

5 files changed

Lines changed: 58 additions & 31 deletions

File tree

src/Extension/Model/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
* @mixin BaseModel
2727
*/
28-
class User extends User_parent implements PersonalGreetingUserInterface
28+
class User extends User_parent implements UserInterface
2929
{
3030
use PersonalGreetingUser;
3131
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
/**
4+
* Copyright © OXID eSales AG. All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
namespace OxidEsales\ExamplesModule\Extension\Model;
9+
10+
use OxidEsales\ExamplesModule\Greeting\Model\PersonalGreetingUserInterface;
11+
12+
interface UserInterface extends PersonalGreetingUserInterface
13+
{
14+
}

src/Greeting/Infrastructure/UserModelFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class UserModelFactory implements UserModelFactoryInterface
1818
*/
1919
public function create(): User
2020
{
21-
return oxNew(User::class); /** @phpstan-ignore return.type */
21+
/** @phpstan-ignore return.type */
22+
return oxNew(User::class);
2223
}
2324
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/**
4+
* Copyright © . All rights reserved.
5+
* See LICENSE file for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace OxidEsales\ExamplesModule\Tests\Unit\Greeting\Infrastructure;
11+
12+
use OxidEsales\ExamplesModule\Extension\Model\UserInterface;
13+
use OxidEsales\ExamplesModule\Greeting\Infrastructure\UserModelFactory;
14+
use PHPUnit\Framework\Attributes\Test;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* @covers \OxidEsales\ExamplesModule\Greeting\Infrastructure\UserModelFactory
19+
*/
20+
class UserModelFactoryTest extends TestCase
21+
{
22+
#[Test]
23+
public function createProducesCorrectTypeOfObjects(): void
24+
{
25+
$sut = new UserModelFactory();
26+
27+
$user = $sut->create();
28+
$this->assertInstanceOf(UserInterface::class, $user);
29+
}
30+
31+
#[Test]
32+
public function createProducesNewObjectsWithEveryCall(): void
33+
{
34+
$sut = new UserModelFactory();
35+
36+
$user1 = $sut->create();
37+
$user2 = $sut->create();
38+
39+
$this->assertNotSame($user1, $user2);
40+
}
41+
}

tests/Unit/Greeting/Infrastructure/UserModelFactoryTest.php

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)