From f082b166112560bf4879c0d673ad8640f5bd4c87 Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Tue, 26 Nov 2024 00:36:20 +0300 Subject: [PATCH 1/4] =?UTF-8?q?-=20=D0=92=D0=BE=D0=B9=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=20AggregateRoot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- src/AggregateRoot.php | 19 +++++++++++++++ .../Entity/Bitrix24Account.php | 23 +++++++------------ .../UseCase/Uninstall/Handler.php | 6 ++++- .../UseCase/Uninstall/HandlerTest.php | 12 +++++++--- 5 files changed, 42 insertions(+), 20 deletions(-) create mode 100644 src/AggregateRoot.php diff --git a/Makefile b/Makefile index c71ff1d..823a5ae 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ test-run-functional: debug-print-env # Запустить один функциональный тест с дебагером run-one-functional-test: debug-print-env - docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testRenewAuthTokenWithoutBitrix24UserId' tests/Functional/Bitrix24Accounts/UseCase/RenewAuthToken/HandlerTest.php + docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testUninstallWithHappyPath' tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php schema-drop: docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force diff --git a/src/AggregateRoot.php b/src/AggregateRoot.php new file mode 100644 index 0000000..4fc766b --- /dev/null +++ b/src/AggregateRoot.php @@ -0,0 +1,19 @@ +events; + $this->events = []; + + return $events; + } + +} \ No newline at end of file diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index 580d719..482651b 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -12,6 +12,7 @@ namespace Bitrix24\Lib\Bitrix24Accounts\Entity; +use Bitrix24\Lib\AggregateRoot; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountInterface; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountStatus; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Events\Bitrix24AccountApplicationInstalledEvent; @@ -30,7 +31,7 @@ use Symfony\Component\Uid\Uuid; use Symfony\Contracts\EventDispatcher\Event; -class Bitrix24Account implements Bitrix24AccountInterface, AggregateRootEventsEmitterInterface +class Bitrix24Account implements Bitrix24AccountInterface { private array $applicationScope; @@ -40,10 +41,7 @@ class Bitrix24Account implements Bitrix24AccountInterface, AggregateRootEventsEm private AuthToken $authToken; - /** - * @var Event[] - */ - private array $events = []; + private array $events; public function __construct( private Uuid $id, @@ -207,6 +205,8 @@ public function applicationInstalled(string $applicationToken): void $this->id, new CarbonImmutable() ); + var_dump('applicationInstalled'); + // dd($this->events); } /** @@ -346,19 +346,12 @@ public function getComment(): ?string return $this->comment; } - /** - * @return Event[] - */ - #[\Override] - public function emitEvents(): array + public function getEvents(): array { - $events = $this->events; - $this->events = []; - - return $events; + return $this->events; } - public function addAccountCreatedEventIfNeeded(bool $isEmitCreatedEvent): void + private function addAccountCreatedEventIfNeeded(bool $isEmitCreatedEvent): void { if ($isEmitCreatedEvent) { // Создание события и добавление его в массив событий diff --git a/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php b/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php index 407a7d1..b85a390 100644 --- a/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php +++ b/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php @@ -4,6 +4,7 @@ namespace Bitrix24\Lib\Bitrix24Accounts\UseCase\Uninstall; +use Bitrix24\Lib\AggregateRoot; use Bitrix24\Lib\Services\Flusher; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountInterface; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Exceptions\Bitrix24AccountNotFoundException; @@ -19,7 +20,7 @@ public function __construct( private EventDispatcherInterface $eventDispatcher, private Bitrix24AccountRepositoryInterface $bitrix24AccountRepository, private Flusher $flusher, - private LoggerInterface $logger + private LoggerInterface $logger, ) {} /** @@ -28,6 +29,8 @@ public function __construct( */ public function handle(Command $command): void { + var_dump('handle'); + $aggregateRoot = new AggregateRoot(); $this->logger->debug('Bitrix24Accounts.Uninstall.start', [ 'b24_application_token' => $command->applicationToken, ]); @@ -41,6 +44,7 @@ public function handle(Command $command): void $account->applicationUninstalled($command->applicationToken); $this->bitrix24AccountRepository->save($account); $this->flusher->flush(); + foreach ($account->emitEvents() as $event) { $this->eventDispatcher->dispatch($event); } diff --git a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php index 8b6a752..c712bf7 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php @@ -13,6 +13,7 @@ namespace Bitrix24\Lib\Tests\Functional\Bitrix24Accounts\UseCase\Uninstall; +use Bitrix24\Lib\AggregateRoot; use Bitrix24\Lib\Bitrix24Accounts\Entity\Bitrix24Account; use Bitrix24\Lib\Bitrix24Accounts\Infrastructure\Doctrine\Bitrix24AccountRepository; use Bitrix24\Lib\Services\Flusher; @@ -45,6 +46,7 @@ class HandlerTest extends TestCase #[Test] public function testUninstallWithHappyPath(): void { + var_dump('testUninstallWithHappyPath'); $oldDomainUrl = Uuid::v7()->toRfc4122() . '-test.bitrix24.com'; $bitrix24Account = new Bitrix24Account( Uuid::v7(), @@ -65,9 +67,10 @@ public function testUninstallWithHappyPath(): void $this->repository->save($bitrix24Account); $this->flusher->flush(); - + var_dump('beforehandle'); + var_dump($this->eventDispatcher->getOrphanedEvents()); $this->handler->handle(new Bitrix24Accounts\UseCase\Uninstall\Command($applicationToken)); - + var_dump($this->eventDispatcher->getOrphanedEvents()); $updated = $this->repository->getById($bitrix24Account->getId()); $this->assertEquals( Bitrix24AccountStatus::deleted, @@ -89,15 +92,18 @@ public function testUninstallWithHappyPath(): void #[Override] protected function setUp(): void { + var_dump('setUp'); + $entityManager = EntityManagerFactory::get(); $this->repository = new Bitrix24AccountRepository($entityManager); $this->flusher = new Flusher($entityManager); $this->eventDispatcher = new TraceableEventDispatcher(new EventDispatcher(), new Stopwatch()); + $this->handler = new Bitrix24Accounts\UseCase\Uninstall\Handler( $this->eventDispatcher, $this->repository, $this->flusher, - new NullLogger() + new NullLogger(), ); } } \ No newline at end of file From e6a69779c7eaebe6392ee11e73d44cef44e4d221 Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Wed, 27 Nov 2024 23:37:50 +0300 Subject: [PATCH 2/4] =?UTF-8?q?-=20=D0=92=D0=BD=D0=B5=D1=81=20=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=B4=D0=BB=D1=8F=20AggregateRoot?= =?UTF-8?q?=20-=20=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20=D0=B8=D0=B7=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20delete=20=D1=80=D0=B5=D0=BF?= =?UTF-8?q?=D0=BE=D0=B7=D0=B8=D1=82=D0=BE=D1=80=D0=B8=D1=8F=20=D0=B0=D0=BA?= =?UTF-8?q?=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0=20=D1=85=D0=B0=D1=80=D0=B4?= =?UTF-8?q?=20=D0=B4=D0=B5=D0=BB=D0=B8=D1=82=20=D0=B8=20=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D0=B5=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BD=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BE=D1=84=D1=82=20=D0=B4=D0=B5=D0=BB=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- src/Bitrix24Accounts/Entity/Bitrix24Account.php | 11 ++++++----- .../Doctrine/Bitrix24AccountRepository.php | 4 ++-- src/Bitrix24Accounts/UseCase/Uninstall/Handler.php | 2 -- .../UseCase/Uninstall/HandlerTest.php | 5 ----- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 823a5ae..276e66c 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ test-run-functional: debug-print-env # Запустить один функциональный тест с дебагером run-one-functional-test: debug-print-env - docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testUninstallWithHappyPath' tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php + docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testDeleteHappyPath' tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php schema-drop: docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index 482651b..7328cce 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -31,7 +31,7 @@ use Symfony\Component\Uid\Uuid; use Symfony\Contracts\EventDispatcher\Event; -class Bitrix24Account implements Bitrix24AccountInterface +class Bitrix24Account extends AggregateRoot implements Bitrix24AccountInterface { private array $applicationScope; @@ -41,8 +41,6 @@ class Bitrix24Account implements Bitrix24AccountInterface private AuthToken $authToken; - private array $events; - public function __construct( private Uuid $id, private readonly int $bitrix24UserId, @@ -99,6 +97,11 @@ public function getStatus(): Bitrix24AccountStatus return $this->status; } + public function setStatus(Bitrix24AccountStatus $status): void + { + $this->status = $status; + } + /** * @throws InvalidArgumentException */ @@ -205,8 +208,6 @@ public function applicationInstalled(string $applicationToken): void $this->id, new CarbonImmutable() ); - var_dump('applicationInstalled'); - // dd($this->events); } /** diff --git a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php index 9cb26d9..8827969 100644 --- a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php +++ b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php @@ -100,8 +100,8 @@ public function delete(Uuid $uuid): void ) ); } - - $this->getEntityManager()->remove($bitrix24Account); + $bitrix24Account->setStatus(Bitrix24AccountStatus::deleted); + $this->save($bitrix24Account); } public function findAllActive(int|null $limit = null, int|null $offset = null): array diff --git a/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php b/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php index b85a390..5c72473 100644 --- a/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php +++ b/src/Bitrix24Accounts/UseCase/Uninstall/Handler.php @@ -29,8 +29,6 @@ public function __construct( */ public function handle(Command $command): void { - var_dump('handle'); - $aggregateRoot = new AggregateRoot(); $this->logger->debug('Bitrix24Accounts.Uninstall.start', [ 'b24_application_token' => $command->applicationToken, ]); diff --git a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php index c712bf7..498ec17 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php @@ -46,7 +46,6 @@ class HandlerTest extends TestCase #[Test] public function testUninstallWithHappyPath(): void { - var_dump('testUninstallWithHappyPath'); $oldDomainUrl = Uuid::v7()->toRfc4122() . '-test.bitrix24.com'; $bitrix24Account = new Bitrix24Account( Uuid::v7(), @@ -67,10 +66,7 @@ public function testUninstallWithHappyPath(): void $this->repository->save($bitrix24Account); $this->flusher->flush(); - var_dump('beforehandle'); - var_dump($this->eventDispatcher->getOrphanedEvents()); $this->handler->handle(new Bitrix24Accounts\UseCase\Uninstall\Command($applicationToken)); - var_dump($this->eventDispatcher->getOrphanedEvents()); $updated = $this->repository->getById($bitrix24Account->getId()); $this->assertEquals( Bitrix24AccountStatus::deleted, @@ -92,7 +88,6 @@ public function testUninstallWithHappyPath(): void #[Override] protected function setUp(): void { - var_dump('setUp'); $entityManager = EntityManagerFactory::get(); $this->repository = new Bitrix24AccountRepository($entityManager); From ba7575abd4c9db60a12366c268c01e50c0992898 Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Fri, 29 Nov 2024 00:04:04 +0300 Subject: [PATCH 3/4] =?UTF-8?q?-=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=B8=D1=81=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B2=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20getById=20-?= =?UTF-8?q?=20=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=82?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- .../Infrastructure/Doctrine/Bitrix24AccountRepository.php | 7 ++++--- .../Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php | 4 ++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 276e66c..e64b4d8 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ test-run-functional: debug-print-env # Запустить один функциональный тест с дебагером run-one-functional-test: debug-print-env - docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testDeleteHappyPath' tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php + docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testDeleteNotInDeletedState' tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php schema-drop: docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force diff --git a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php index 8827969..c3322af 100644 --- a/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php +++ b/src/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepository.php @@ -32,14 +32,15 @@ public function __construct( #[Override] public function getById(Uuid $uuid): Bitrix24AccountInterface { - $res = $this->getEntityManager()->getRepository(Bitrix24Account::class)->find($uuid); - if (null === $res) { + $account = $this->getEntityManager()->getRepository(Bitrix24Account::class)->find($uuid); + if (null === $account || $account->getStatus() === Bitrix24AccountStatus::deleted) { throw new Bitrix24AccountNotFoundException( sprintf('bitrix24 account not found by id %s', $uuid->toRfc4122()) ); } - return $res; + + return $account; } #[Override] diff --git a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php index 498ec17..1f2c6db 100644 --- a/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php +++ b/tests/Functional/Bitrix24Accounts/UseCase/Uninstall/HandlerTest.php @@ -21,6 +21,7 @@ use Bitrix24\Lib\Tests\EntityManagerFactory; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Entity\Bitrix24AccountStatus; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Events\Bitrix24AccountApplicationUninstalledEvent; +use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Exceptions\Bitrix24AccountNotFoundException; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Repository\Bitrix24AccountRepositoryInterface; use Bitrix24\SDK\Core\Credentials\AuthToken; use Bitrix24\SDK\Core\Credentials\Scope; @@ -67,7 +68,10 @@ public function testUninstallWithHappyPath(): void $this->flusher->flush(); $this->handler->handle(new Bitrix24Accounts\UseCase\Uninstall\Command($applicationToken)); + + $this->expectException(Bitrix24AccountNotFoundException::class); $updated = $this->repository->getById($bitrix24Account->getId()); + $this->assertEquals( Bitrix24AccountStatus::deleted, $updated->getStatus(), From 57a3f515e5367f065b6eeb60a03514fbe59a8fdf Mon Sep 17 00:00:00 2001 From: KarlsonComplete Date: Sat, 30 Nov 2024 17:30:57 +0300 Subject: [PATCH 4/4] =?UTF-8?q?-=20=D0=A2=D0=B5=D1=81=D1=82=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=84=D0=B5=D1=82=D1=87=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- .../Entity/Bitrix24Account.php | 9 ++++----- src/Bitrix24Accounts/ReadModel/Fetcher.php | 10 +++++++--- .../Bitrix24Accounts/FetcherTest.php | 19 +++++++++++++------ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index e64b4d8..441329a 100644 --- a/Makefile +++ b/Makefile @@ -101,7 +101,7 @@ test-run-functional: debug-print-env # Запустить один функциональный тест с дебагером run-one-functional-test: debug-print-env - docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testDeleteNotInDeletedState' tests/Functional/Bitrix24Accounts/Infrastructure/Doctrine/Bitrix24AccountRepositoryTest.php + docker-compose run --rm php-cli php -dxdebug.start_with_request=yes vendor/bin/phpunit --filter 'testListReturnsPaginatedResults' tests/Functional/Bitrix24Accounts/FetcherTest.php schema-drop: docker-compose run --rm php-cli php bin/doctrine orm:schema-tool:drop --force diff --git a/src/Bitrix24Accounts/Entity/Bitrix24Account.php b/src/Bitrix24Accounts/Entity/Bitrix24Account.php index 7328cce..6e31484 100644 --- a/src/Bitrix24Accounts/Entity/Bitrix24Account.php +++ b/src/Bitrix24Accounts/Entity/Bitrix24Account.php @@ -33,7 +33,7 @@ class Bitrix24Account extends AggregateRoot implements Bitrix24AccountInterface { - private array $applicationScope; + private array|Scope $applicationScope; private ?string $applicationToken = null; @@ -57,7 +57,8 @@ public function __construct( bool $isEmitBitrix24AccountCreatedEvent = false ) { $this->authToken = $authToken; - $this->applicationScope = $applicationScope->getScopeCodes(); + $array = $applicationScope->getScopeCodes(); + $this->applicationScope = $array; $this->addAccountCreatedEventIfNeeded($isEmitBitrix24AccountCreatedEvent); } @@ -144,13 +145,11 @@ public function getApplicationVersion(): int return $this->applicationVersion; } - /** - * @throws UnknownScopeCodeException - */ #[\Override] public function getApplicationScope(): Scope { return new Scope($this->applicationScope); + // return $this->applicationScope; } /** diff --git a/src/Bitrix24Accounts/ReadModel/Fetcher.php b/src/Bitrix24Accounts/ReadModel/Fetcher.php index 91b1982..0430f40 100644 --- a/src/Bitrix24Accounts/ReadModel/Fetcher.php +++ b/src/Bitrix24Accounts/ReadModel/Fetcher.php @@ -6,9 +6,9 @@ use Bitrix24\Lib\Bitrix24Accounts\Infrastructure\Doctrine\Bitrix24AccountRepository; use Doctrine\ORM\EntityManagerInterface; +use Knp\Component\Pager\Event\Subscriber\Paginate\Callback\CallbackPagination; use Knp\Component\Pager\Pagination\PaginationInterface; use Knp\Component\Pager\PaginatorInterface; - class Fetcher { public function __construct( @@ -23,7 +23,7 @@ public function list( ): PaginationInterface { - $queryBuilder = $this->em->getConnection()->createQueryBuilder() + /* $queryBuilder = $this->em->getConnection()->createQueryBuilder() ->select( 'b24account.id as id', 'b24account.status as status', @@ -35,7 +35,11 @@ public function list( ) ->from('bitrix24account', 'b24account') ->orderBy('b24account.created_at_utc', 'DESC'); + */ + // var_dump($queryBuilder->getMaxResults()); + $query = $this->em->createQuery("SELECT b24account FROM Bitrix24\Lib\Bitrix24Accounts\Entity\Bitrix24Account b24account"); - return $this->paginator->paginate($queryBuilder, $page, $size); + return $this->paginator->paginate($query, $page, $size); + // return $this->paginator->paginate($queryBuilder->getSQL(), $page, $size); } } \ No newline at end of file diff --git a/tests/Functional/Bitrix24Accounts/FetcherTest.php b/tests/Functional/Bitrix24Accounts/FetcherTest.php index c4e5dc4..fa1012c 100644 --- a/tests/Functional/Bitrix24Accounts/FetcherTest.php +++ b/tests/Functional/Bitrix24Accounts/FetcherTest.php @@ -8,6 +8,8 @@ use Bitrix24\Lib\Bitrix24Accounts\ReadModel\Fetcher; use Bitrix24\Lib\Services\Flusher; use Bitrix24\Lib\Tests\EntityManagerFactory; +use Knp\Component\Pager\Event\Subscriber\Paginate\PaginationSubscriber; +use Knp\Component\Pager\Event\Subscriber\Sortable\SortableSubscriber; use Knp\Component\Pager\Paginator; use PHPUnit\Framework\TestCase; use Doctrine\ORM\EntityManagerInterface; @@ -16,8 +18,9 @@ use Bitrix24\Lib\Tests\Functional\Bitrix24Accounts\Builders\Bitrix24AccountBuilder; use Bitrix24\SDK\Application\Contracts\Bitrix24Accounts\Repository\Bitrix24AccountRepositoryInterface; use Symfony\Component\EventDispatcher\EventDispatcher; -use Knp\Component\Pager\ArgumentAccess; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpFoundation\Request; +use Knp\Component\Pager\ArgumentAccess\RequestArgumentAccess; class FetcherTest extends TestCase { @@ -34,9 +37,13 @@ protected function setUp(): void { $this->entityManager = EntityManagerFactory::get(); $eventDispatcher = new EventDispatcher(); + $eventDispatcher->addSubscriber(new PaginationSubscriber()); + $eventDispatcher->addSubscriber(new SortableSubscriber()); + // dd(Request::createFromGlobals()); $requestStack = new RequestStack(); - $argumentAccess = new ArgumentAccess\RequestArgumentAccess($requestStack); - $this->paginator = new Paginator($eventDispatcher, $argumentAccess); + // Request::createFromGlobals() + $accessor = new RequestArgumentAccess(new RequestStack()); + $this->paginator = new Paginator($eventDispatcher, $accessor); $this->fetcher = new Fetcher($this->entityManager, $this->paginator); $this->flusher = new Flusher($this->entityManager); $this->repository = new Bitrix24AccountRepository($this->entityManager); @@ -55,14 +62,14 @@ public function testListReturnsPaginatedResults(): void $page = 1; $size = 10; // Вызов метода list - /** @var PaginationInterface $result */ $result = $this->fetcher->list($page, $size); - + // var_dump($result->getItems()); + // var_dump($result->count()); // Проверка, что результат является экземпляром PaginationInterface $this->assertInstanceOf(PaginationInterface::class, $result); // Проверка, что данные возвращаются корректно - $this->assertGreaterThan(0, count($result)); // Проверяем, что есть хотя бы одна запись + $this->assertGreaterThan(0, $result->count()); // Проверяем, что есть хотя бы одна запись } } \ No newline at end of file