Skip to content

Commit

Permalink
* inline all single usage of variable with value self::getContainer()
Browse files Browse the repository at this point in the history
- override method `tearDown()` as it's only invoking the parent @ `EventListener\ShowReactJsonViewTest`
@ `App\Tests`

* rename `hasQueryResultMorePages()` to `hasMorePages()` since 122379f @ `App\PostsQuery\QueryResult`, also affects its usage in `App\Controller\UsersController->query()`
@ be
  • Loading branch information
n0099 committed Oct 30, 2024
1 parent 3f225ce commit ce2285b
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion be/src/Controller/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function (array $acc, $paramValue, string $paramName) use ($paramConstraints): a
)[1]->orderBy('t.uid', 'DESC');

['result' => $result, 'hasMorePages' => $hasMorePages] =
QueryResult::hasQueryResultMorePages($queries, $this->perPageItems);
QueryResult::hasMorePages($queries, $this->perPageItems);
$resultCount = count($result);
Helper::abortAPIIf(40402, $resultCount === 0);

Expand Down
4 changes: 2 additions & 2 deletions be/src/PostsQuery/QueryResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(
) {}

/** @return array{result: Collection, hasMorePages: bool} */
public static function hasQueryResultMorePages(QueryBuilder $query, int $limit): array
public static function hasMorePages(QueryBuilder $query, int $limit): array
{
$results = collect($query->setMaxResults($limit + 1)->getQuery()->getResult());
if ($results->count() === $limit + 1) {
Expand Down Expand Up @@ -91,7 +91,7 @@ public function setResult(
});
$resultsAndHasMorePages = $queries->map(fn(QueryBuilder $query) =>
self::hasQueryResultMorePages($query, $this->perPageItems));
self::hasMorePages($query, $this->perPageItems));
/** @var PostsKeyByTypePluralName $postsKeyByTypePluralName */
$postsKeyByTypePluralName = $resultsAndHasMorePages
->mapWithKeys(fn(array $resultAndHasMorePages, string $postType) =>
Expand Down
3 changes: 1 addition & 2 deletions be/tests/EventListener/PrettyJsonResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$container = static::getContainer();
$this->sut = $container->get(PrettyJsonResponse::class);
$this->sut = static::getContainer()->get(PrettyJsonResponse::class);
}

public function test(): void
Expand Down
8 changes: 1 addition & 7 deletions be/tests/EventListener/ShowReactJsonViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,7 @@ protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$container = static::getContainer();
$this->sut = $container->get(ShowReactJsonView::class);
}

protected function tearDown(): void
{
parent::tearDown();
$this->sut = static::getContainer()->get(ShowReactJsonView::class);
}

public function testShowing(): void
Expand Down
3 changes: 1 addition & 2 deletions be/tests/PostsQuery/PostsTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$container = self::getContainer();
$this->sut = $container->get(PostsTree::class);
$this->sut = self::getContainer()->get(PostsTree::class);
}

#[DataProvider('provideReOrderNestedPostsData')]
Expand Down
3 changes: 1 addition & 2 deletions be/tests/Repository/Post/PostRepositoryFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ protected function setUp(): void
{
parent::setUp();
self::bootKernel();
$container = static::getContainer();
$this->sut = $container->get(PostRepositoryFactory::class);
$this->sut = static::getContainer()->get(PostRepositoryFactory::class);
}

#[DataProvider('providePostModelFid')]
Expand Down

0 comments on commit ce2285b

Please sign in to comment.