. */ namespace SP\Tests\Domain\Account\Services; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\MockObject; use SP\Domain\Account\Ports\AccountToUserRepository; use SP\Domain\Account\Services\AccountToUser; use SP\Domain\Common\Models\Item; use SP\Domain\Core\Exceptions\ConstraintException; use SP\Domain\Core\Exceptions\QueryException; use SP\Domain\Core\Exceptions\SPException; use SP\Infrastructure\Database\QueryResult; use SP\Tests\UnitaryTestCase; /** * Class AccountToUserServiceTest * */ #[Group('unitary')] class AccountToUserTest extends UnitaryTestCase { private AccountToUserRepository|MockObject $accountToUserRepository; private AccountToUser $accountToUser; /** * @throws ConstraintException * @throws QueryException * @throws SPException */ public function testGetUsersByAccountId() { $accountId = self::$faker->randomNumber(); $result = new QueryResult( [ new Item( [ 'id' => self::$faker->randomNumber(), 'name' => self::$faker->colorName, 'isEdit' => self::$faker->boolean, 'login' => self::$faker->colorName, ] ), ] ); $this->accountToUserRepository ->expects(self::once()) ->method('getUsersByAccountId') ->with($accountId) ->willReturn($result); $actual = $this->accountToUser->getUsersByAccountId($accountId); $expected = $result->getData(Item::class)->toArray(null, null, true); $this->assertTrue($actual[0] instanceof Item); $this->assertEquals($expected, $actual[0]->toArray(null, null, true)); } /** * @throws ConstraintException * @throws QueryException * @throws SPException */ public function testGetUsersByAccountIdWithNoUsers() { $accountId = self::$faker->randomNumber(); $result = new QueryResult([]); $this->accountToUserRepository ->expects(self::once()) ->method('getUsersByAccountId') ->with($accountId) ->willReturn($result); $actual = $this->accountToUser->getUsersByAccountId($accountId); $this->assertEmpty($actual); } protected function setUp(): void { parent::setUp(); $this->accountToUserRepository = $this->createMock(AccountToUserRepository::class); $this->accountToUser = new AccountToUser($this->application, $this->accountToUserRepository); } }