File tree Expand file tree Collapse file tree
tests/Integration/Greeting/Service Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414
1515/**
1616 * @extendable-class
17+ *
18+ * @todo: getting the user should go through the user repository
1719 */
1820readonly class UserService implements UserServiceInterface
1921{
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments