. */ namespace SP\Tests\Domain\Account\Services; use PHPUnit\Framework\Attributes\Group; use PHPUnit\Framework\MockObject\MockObject; use SP\Domain\Account\Ports\AccountToFavoriteRepository; use SP\Domain\Account\Services\AccountToFavorite; 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 AccountToFavoriteServiceTest * */ #[Group('unitary')] class AccountToFavoriteTest extends UnitaryTestCase { private AccountToFavoriteRepository|MockObject $accountToFavoriteRepository; private AccountToFavorite $accountToFavorite; /** * @throws QueryException * @throws ConstraintException * @throws SPException */ public function testGetForUserId() { $userId = self::$faker->randomNumber(); $result = new QueryResult([['userId' => $userId, 'accountId' => self::$faker->randomNumber()]]); $this->accountToFavoriteRepository ->expects(self::once()) ->method('getForUserId') ->with($userId) ->willReturn($result); $actual = $this->accountToFavorite->getForUserId($userId); $this->assertEquals($result->getDataAsArray(), $actual); } /** * @throws QueryException * @throws ConstraintException */ public function testDelete() { $accountId = self::$faker->randomNumber(); $userId = self::$faker->randomNumber(); $out = self::$faker->boolean; $this->accountToFavoriteRepository->expects(self::once()) ->method('delete') ->with($accountId, $userId) ->willReturn($out); $actual = $this->accountToFavorite->delete($accountId, $userId); $this->assertEquals($out, $actual); } /** * @throws QueryException * @throws ConstraintException */ public function testAdd() { $accountId = self::$faker->randomNumber(); $userId = self::$faker->randomNumber(); $out = self::$faker->randomNumber(); $this->accountToFavoriteRepository->expects(self::once()) ->method('add') ->with($accountId, $userId) ->willReturn($out); $actual = $this->accountToFavorite->add($accountId, $userId); $this->assertEquals($out, $actual); } protected function setUp(): void { parent::setUp(); $this->accountToFavoriteRepository = $this->createMock(AccountToFavoriteRepository::class); $this->accountToFavorite = new AccountToFavorite($this->application, $this->accountToFavoriteRepository); } }