Skip to content

Commit 2dcb58c

Browse files
committed
OXDEV-9497 Add UserService test
Signed-off-by: Anton Fedurtsya <anton@fedurtsya.com>
1 parent 6ffab4b commit 2dcb58c

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

src/Greeting/Service/UserService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
/**
1616
* @extendable-class
17+
*
18+
* @todo: getting the user should go through the user repository
1719
*/
1820
readonly class UserService implements UserServiceInterface
1921
{
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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 Greeting\Service;
11+
12+
use OxidEsales\EshopCommunity\Tests\Integration\IntegrationTestCase;
13+
use OxidEsales\ExamplesModule\Extension\Model\User;
14+
use OxidEsales\ExamplesModule\Greeting\Infrastructure\UserModelFactoryInterface;
15+
use OxidEsales\ExamplesModule\Greeting\Service\UserService;
16+
use PHPUnit\Framework\Attributes\Test;
17+
18+
final class UserServiceTest extends IntegrationTestCase
19+
{
20+
public function setUp(): void
21+
{
22+
// @todo: its a temporary hack for broken autoloader solution 9474. Remove this when the case is solved.
23+
oxNew(User::class);
24+
}
25+
26+
#[Test]
27+
public function getUserByIdLoadsUserAndReturnsIt(): void
28+
{
29+
$userId = uniqid();
30+
31+
$userModelSpy = $this->createMock(User::class);
32+
$userModelSpy->expects($this->once())
33+
->method('load')
34+
->with($userId);
35+
36+
$userModelFactoryMock = $this->createConfiguredStub(UserModelFactoryInterface::class, [
37+
'create' => $userModelSpy,
38+
]);
39+
40+
$sut = new UserService(
41+
userModelFactory: $userModelFactoryMock
42+
);
43+
44+
$result = $sut->getUserById($userId);
45+
$this->assertSame($userModelSpy, $result);
46+
}
47+
}

0 commit comments

Comments
 (0)