diff --git a/blog-api/config/environments/test/params.php b/blog-api/config/environments/test/params.php index a8757bdd..abcc1796 100644 --- a/blog-api/config/environments/test/params.php +++ b/blog-api/config/environments/test/params.php @@ -10,7 +10,6 @@ 'enabled' => false, ], 'yiisoft/yii-cycle' => [ - // DBAL config 'dbal' => [ 'connections' => [ 'sqlite' => new SQLiteDriverConfig( diff --git a/blog-api/src/Auth/AuthController.php b/blog-api/src/Auth/AuthController.php index de3a7924..9416937c 100644 --- a/blog-api/src/Auth/AuthController.php +++ b/blog-api/src/Auth/AuthController.php @@ -14,15 +14,10 @@ #[OA\SecurityScheme(securityScheme: 'ApiKey', type: 'apiKey', name: 'X-Api-Key', in: 'header')] final class AuthController { - private ResponseFactory $responseFactory; - private UserService $userService; - public function __construct( - ResponseFactory $responseFactory, - UserService $userService + private ResponseFactory $responseFactory, + private UserService $userService, ) { - $this->responseFactory = $responseFactory; - $this->userService = $userService; } #[OA\Post( diff --git a/blog-api/src/User/UserRepository.php b/blog-api/src/User/UserRepository.php index acd5d750..b6ad8078 100644 --- a/blog-api/src/User/UserRepository.php +++ b/blog-api/src/User/UserRepository.php @@ -6,20 +6,21 @@ use Cycle\ORM\ORMInterface; use Cycle\ORM\Select; -use Cycle\ORM\Transaction; use Yiisoft\Auth\IdentityInterface; use Yiisoft\Auth\IdentityRepositoryInterface; use Yiisoft\Auth\IdentityWithTokenRepositoryInterface; use Yiisoft\Data\Cycle\Reader\EntityReader; +use Yiisoft\Data\Cycle\Writer\EntityWriter; use Yiisoft\Data\Reader\Sort; final class UserRepository extends Select\Repository implements IdentityWithTokenRepositoryInterface, IdentityRepositoryInterface { - private ORMInterface $orm; - - public function __construct(Select $select, ORMInterface $orm) + public function __construct( + Select $select, + private ORMInterface $orm, + private EntityWriter $entityWriter, + ) { - $this->orm = $orm; parent::__construct($select); } @@ -52,9 +53,7 @@ public function findByLogin(string $login): ?IdentityInterface public function save(IdentityInterface $user): void { - $transaction = new Transaction($this->orm); - $transaction->persist($user); - $transaction->run(); + $this->entityWriter->write([$user]); } private function findIdentityBy(string $field, string $value): ?IdentityInterface diff --git a/blog-api/src/User/UserService.php b/blog-api/src/User/UserService.php index f5df91d5..b125d9e3 100644 --- a/blog-api/src/User/UserService.php +++ b/blog-api/src/User/UserService.php @@ -15,18 +15,11 @@ final class UserService { - private IdentityRepositoryInterface $identityRepository; - private CurrentUser $currentUser; - private QueueFactoryInterface $queueFactory; - public function __construct( - CurrentUser $currentUser, - IdentityRepositoryInterface $identityRepository, - QueueFactoryInterface $queueFactory + private CurrentUser $currentUser, + private IdentityRepositoryInterface $identityRepository, + private QueueFactoryInterface $queueFactory, ) { - $this->currentUser = $currentUser; - $this->identityRepository = $identityRepository; - $this->queueFactory = $queueFactory; } /** @@ -40,7 +33,9 @@ public function __construct( */ public function login(string $login, string $password): IdentityInterface { - $identity = $this->identityRepository->findByLogin($login); + /** @var UserRepository $identityRepository */ + $identityRepository = $this->identityRepository; + $identity = $identityRepository->findByLogin($login); if ($identity === null) { throw new BadRequestException('No such user.'); } diff --git a/blog-api/tests/Acceptance/AuthCest.php b/blog-api/tests/Acceptance/AuthCest.php index 9b674f59..2fe54ba8 100644 --- a/blog-api/tests/Acceptance/AuthCest.php +++ b/blog-api/tests/Acceptance/AuthCest.php @@ -12,7 +12,6 @@ final class AuthCest { public function testAuth(AcceptanceTester $I): void { - $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPOST( '/auth/', [