Skip to content

Commit

Permalink
Merge #612
Browse files Browse the repository at this point in the history
612: Fix "dynamic call to static method" phpstan error in tests r=norkunas a=aivchen

# Pull Request

## What does this PR do?
- replaces `$this->assertXXX` calls with `static::assertXXX`
- replaces `assertEquals` calls with `assertSame`
- ordered arguments in `assertSame` calls
## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: andrew <[email protected]>
Co-authored-by: Andrew Ivchenkov <[email protected]>
  • Loading branch information
meili-bors[bot] and aivchen authored Jan 23, 2024
2 parents f07267b + c54be54 commit 7586fc9
Show file tree
Hide file tree
Showing 45 changed files with 850 additions and 863 deletions.
2 changes: 2 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
'declare_strict_types' => true,
'void_return' => true,
'native_function_invocation' => ['include' => ['@compiler_optimized'], 'scope' => 'namespaced'],
'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
'php_unit_strict' => true,
];

$config = new PhpCsFixer\Config();
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,3 @@ parameters:
paths:
- src
- tests
ignoreErrors:
- '#Dynamic call to static method PHPUnit\\Framework\\.*#'
10 changes: 3 additions & 7 deletions tests/Contracts/CancelTasksQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,21 @@ public function testSetTypes(): void
{
$data = (new CancelTasksQuery())->setTypes(['abc', 'xyz']);

$this->assertEquals(['types' => 'abc,xyz'], $data->toArray());
self::assertSame(['types' => 'abc,xyz'], $data->toArray());
}

public function testSetAnyDateFilter(): void
{
$date = new \DateTime();
$data = (new CancelTasksQuery())->setBeforeEnqueuedAt($date);

$this->assertEquals(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray());
self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray());
}

public function testToArrayWithDifferentSets(): void
{
$data = (new CancelTasksQuery())->setUids([1, 2, 3])->setStatuses(['enqueued']);

$this->assertEquals([
'uids' => '1,2,3', 'statuses' => 'enqueued',
],
$data->toArray()
);
self::assertSame(['statuses' => 'enqueued', 'uids' => '1,2,3'], $data->toArray());
}
}
9 changes: 3 additions & 6 deletions tests/Contracts/DeleteTasksQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,21 @@ public function testSetTypes(): void
{
$data = (new DeleteTasksQuery())->setTypes(['abc', 'xyz']);

$this->assertEquals(['types' => 'abc,xyz'], $data->toArray());
self::assertSame(['types' => 'abc,xyz'], $data->toArray());
}

public function testSetAnyDateFilter(): void
{
$date = new \DateTime();
$data = (new DeleteTasksQuery())->setCanceledBy([null])->setBeforeEnqueuedAt($date);

$this->assertEquals(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray());
self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray());
}

public function testToArrayWithDifferentSets(): void
{
$data = (new DeleteTasksQuery())->setCanceledBy([1, 2])->setStatuses(['enqueued']);

$this->assertEquals([
'canceledBy' => '1,2', 'statuses' => 'enqueued',
], $data->toArray()
);
self::assertSame(['statuses' => 'enqueued', 'canceledBy' => '1,2'], $data->toArray());
}
}
8 changes: 4 additions & 4 deletions tests/Contracts/DocumentsQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public function testSetFields(): void
{
$data = (new DocumentsQuery())->setLimit(10)->setFields(['abc', 'xyz']);

$this->assertEquals(['limit' => 10, 'fields' => 'abc,xyz'], $data->toArray());
self::assertSame(['limit' => 10, 'fields' => 'abc,xyz'], $data->toArray());
}

public function testToArrayWithoutSetFields(): void
{
$data = (new DocumentsQuery())->setLimit(10);

$this->assertEquals(['limit' => 10], $data->toArray());
self::assertSame(['limit' => 10], $data->toArray());
}

public function testToArrayWithoutSetOffset(): void
{
$data = (new DocumentsQuery())->setOffset(10);

$this->assertEquals(['offset' => 10], $data->toArray());
self::assertSame(['offset' => 10], $data->toArray());
}

public function testToArrayWithZeros(): void
{
$data = (new DocumentsQuery())->setLimit(0)->setOffset(0);

$this->assertEquals(['limit' => 0, 'offset' => 0], $data->toArray());
self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray());
}
}
8 changes: 4 additions & 4 deletions tests/Contracts/IndexesQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public function testToArrayWithSetOffsetAndSetLimit(): void
{
$data = (new IndexesQuery())->setLimit(10)->setOffset(18);

$this->assertEquals(['limit' => 10, 'offset' => 18], $data->toArray());
self::assertSame(['offset' => 18, 'limit' => 10], $data->toArray());
}

public function testToArrayWithSetOffset(): void
{
$data = (new IndexesQuery())->setOffset(5);

$this->assertEquals(['offset' => 5], $data->toArray());
self::assertSame(['offset' => 5], $data->toArray());
}

public function testToArrayWithoutSet(): void
{
$data = new IndexesQuery();

$this->assertEmpty($data->toArray());
self::assertEmpty($data->toArray());
}

public function testToArrayWithZeros(): void
{
$data = (new IndexesQuery())->setLimit(0)->setOffset(0);

$this->assertEquals(['limit' => 0, 'offset' => 0], $data->toArray());
self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray());
}
}
8 changes: 4 additions & 4 deletions tests/Contracts/KeysQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@ public function testToArrayWithSetOffsetAndSetLimit(): void
{
$data = (new KeysQuery())->setLimit(10)->setOffset(18);

$this->assertEquals(['limit' => 10, 'offset' => 18], $data->toArray());
self::assertSame(['offset' => 18, 'limit' => 10], $data->toArray());
}

public function testToArrayWithSetOffset(): void
{
$data = (new KeysQuery())->setOffset(5);

$this->assertEquals(['offset' => 5], $data->toArray());
self::assertSame(['offset' => 5], $data->toArray());
}

public function testToArrayWithoutSet(): void
{
$data = new KeysQuery();

$this->assertEmpty($data->toArray());
self::assertEmpty($data->toArray());
}

public function testToArrayWithZeros(): void
{
$data = (new KeysQuery())->setLimit(0)->setOffset(0);

$this->assertEquals(['limit' => 0, 'offset' => 0], $data->toArray());
self::assertSame(['offset' => 0, 'limit' => 0], $data->toArray());
}
}
12 changes: 5 additions & 7 deletions tests/Contracts/TasksQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,35 @@ public function testSetTypes(): void
{
$data = (new TasksQuery())->setTypes(['abc', 'xyz']);

$this->assertEquals(['types' => 'abc,xyz'], $data->toArray());
self::assertSame(['types' => 'abc,xyz'], $data->toArray());
}

public function testSetAnyDateFilter(): void
{
$date = new \DateTime();
$data = (new TasksQuery())->setBeforeEnqueuedAt($date);

$this->assertEquals($data->toArray(), ['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)]);
self::assertSame(['beforeEnqueuedAt' => $date->format(\DateTime::RFC3339)], $data->toArray());
}

public function testToArrayWithSetLimit(): void
{
$data = (new TasksQuery())->setLimit(10);

$this->assertEquals(['limit' => 10], $data->toArray());
self::assertSame(['limit' => 10], $data->toArray());
}

public function testToArrayWithSetLimitWithZero(): void
{
$data = (new TasksQuery())->setLimit(0);

$this->assertEquals(['limit' => 0], $data->toArray());
self::assertSame(['limit' => 0], $data->toArray());
}

public function testToArrayWithDifferentSets(): void
{
$data = (new TasksQuery())->setFrom(10)->setLimit(9)->setCanceledBy([1, 4])->setStatuses(['enqueued']);

$this->assertEquals([
'limit' => 9, 'from' => 10, 'statuses' => 'enqueued', 'canceledBy' => '1,4',
], $data->toArray());
self::assertSame(['statuses' => 'enqueued', 'from' => 10, 'limit' => 9, 'canceledBy' => '1,4'], $data->toArray());
}
}
Loading

0 comments on commit 7586fc9

Please sign in to comment.