Skip to content

Commit

Permalink
Clean up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Dec 2, 2023
1 parent 4e406fe commit 3238ded
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bin/prepare-commit
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ vendor/bin/php-cs-fixer fix
vendor/bin/phpstan

# Clear cache and quarantine manually to avoid locking up with corrupted container
rm -rf tests/fixture/var/cache/test
rm -rf tests/Fixtures/var/cache/test
php -d "zend.assertions=1" vendor/bin/phpunit --testdox --coverage-text \
--coverage-xml=build/coverage/coverage-xml --log-junit=build/coverage/junit.xml

Expand Down
6 changes: 5 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory>./src/Adapter/MongoDB</directory>
<directory>./src/Adapter/Elasticsearch</directory>
</exclude>
</coverage>
<php>
<ini name="date.timezone" value="UTC"/>
Expand All @@ -12,7 +16,7 @@
<ini name="intl.error_level" value="0"/>
<ini name="memory_limit" value="-1"/>
<env name="SHELL_VERBOSITY" value="-1"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[self]=0"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0&amp;verbose=0&amp;ignoreFile=./tests/known-deprecations"/>
<env name="KERNEL_CLASS" value="\Tests\Fixtures\AppKernel"/>
</php>
<testsuites>
Expand Down
15 changes: 7 additions & 8 deletions src/DataTableState.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@
use Symfony\Component\HttpFoundation\ParameterBag;

/**
* DataTableState.
*
* @author Robbert Beesems <[email protected]>
* @phpstan-type SearchColumn array{column: AbstractColumn, search: string, regex: bool}
* @phpstan-type OrderColumn array{AbstractColumn, string}
*/
final class DataTableState
{
Expand All @@ -29,10 +28,10 @@ final class DataTableState
private ?int $length = null;
private string $globalSearch = '';

/** @var array{column: AbstractColumn, search: string, regex: bool}[] */
/** @var SearchColumn[] */
private array $searchColumns = [];

/** @var array{AbstractColumn, string}[] */
/** @var OrderColumn[] */
private array $orderBy = [];

private bool $isInitial = false;
Expand Down Expand Up @@ -185,15 +184,15 @@ public function addOrderBy(AbstractColumn $column, string $direction = DataTable
}

/**
* @return array{AbstractColumn, string}[]
* @return OrderColumn[]
*/
public function getOrderBy(): array
{
return $this->orderBy;
}

/**
* @param array{AbstractColumn, string}[] $orderBy
* @param OrderColumn[] $orderBy
*/
public function setOrderBy(array $orderBy = []): static
{
Expand All @@ -205,7 +204,7 @@ public function setOrderBy(array $orderBy = []): static
/**
* Returns an array of column-level searches.
*
* @return array{column: AbstractColumn, search: string, regex: bool}[]
* @return SearchColumn[]
*/
public function getSearchColumns(): array
{
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/DataTableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public function testDataTableState(): void
$this->assertSame(10, $state->getLength());
$this->assertSame(0, $state->getDraw());
$this->assertSame('', $state->getGlobalSearch());
$this->assertFalse($state->isExport());

$state->setStart(5);
$state->setLength(10);
Expand All @@ -98,6 +99,13 @@ public function testDataTableState(): void
$this->assertSame('foo', $state->getGlobalSearch());
$this->assertCount(2, $state->getOrderBy());
$this->assertSame('bar', $state->getSearchColumns()['foo']['search']);

// Test boundaries
$state->setStart(-1);
$state->setLength(0);

$this->assertSame(0, $state->getStart());
$this->assertNull($state->getLength());
}

public function testPostMethod(): void
Expand Down
7 changes: 7 additions & 0 deletions tests/known-deprecations
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Internal deprecations
%Passing a negative value to the.*setStart%
%with a length less than 1 is deprecated%

# Elastica
%Passing a array of strings as 1st argument%

0 comments on commit 3238ded

Please sign in to comment.