Skip to content

Commit

Permalink
Upgrade to PHPUnit 10
Browse files Browse the repository at this point in the history
  • Loading branch information
curry684 committed Dec 2, 2023
1 parent 65936fa commit 81b88de
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 44 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
[![License](https://poser.pugx.org/omines/datatables-bundle/license)](https://packagist.org/packages/omines/datatables-bundle)

This bundle provides convenient integration of the popular [DataTables](https://datatables.net/) jQuery library
for realtime Ajax tables in your [Symfony](https://symfony.com/) 5.4+ or 6.0+ application.

Already on Symfony 7.0 pre-release versions? Try out `dev-master` and
[help us out](https://github.com/omines/datatables-bundle/blob/master/CONTRIBUTING.md) if you run into problems.
for realtime Ajax tables in your [Symfony](https://symfony.com/) 6.3+ application.

Unlike other bundles providing similar functionality we decoupled the implementation of the DataTables logic
completely from the source of the data. Therefore it is possible to implement your own custom adapters for
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"phpstan/phpstan-doctrine": "^1.3.12",
"phpstan/phpstan-phpunit": "^1.1",
"phpstan/phpstan-symfony": "^1.2.9",
"phpunit/phpunit": "^9.6.14",
"phpunit/phpunit": "^10.5.1",
"ruflin/elastica": "^6.0|^7.2",
"symfony/browser-kit": "^6.1.3|^7.0",
"symfony/css-selector": "^6.1.3|^7.0",
Expand Down
24 changes: 11 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/phpunit-bootstrap.php">
<coverage>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory>./src/Adapter/MongoDB</directory>
<directory>./src/Adapter/Elasticsearch</directory>
</exclude>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="tests/phpunit-bootstrap.php" cacheDirectory=".phpunit.cache">
<coverage/>
<php>
<ini name="date.timezone" value="UTC"/>
<ini name="error_reporting" value="-1"/>
Expand All @@ -24,7 +16,13 @@
<directory>./tests/</directory>
</testsuite>
</testsuites>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener"/>
</listeners>
<source>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory>./src/Adapter/MongoDB</directory>
<directory>./src/Adapter/Elasticsearch</directory>
</exclude>
</source>
</phpunit>
20 changes: 11 additions & 9 deletions src/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,20 @@ public function configure(array $options): void

public function getData(DataTableState $state): ResultSetInterface
{
// very basic implementation of sorting
// Very basic implementation of sorting
try {
$oc = $state->getOrderBy()[0][0]->getName();
$oo = \mb_strtolower($state->getOrderBy()[0][1]);
if (!empty($ob = $state->getOrderBy())) {
$oc = $ob[0][0]->getName();
$oo = \mb_strtolower($state->getOrderBy()[0][1]);

\usort($this->data, function ($a, $b) use ($oc, $oo) {
if ('desc' === $oo) {
return $b[$oc] <=> $a[$oc];
}
\usort($this->data, function ($a, $b) use ($oc, $oo) {
if ('desc' === $oo) {
return $b[$oc] <=> $a[$oc];
}

return $a[$oc] <=> $b[$oc];
});
return $a[$oc] <=> $b[$oc];
});
}
} catch (\Throwable $exception) {
// ignore exception
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tests\Functional\Exporter\Event;

use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
Expand All @@ -30,9 +31,7 @@ protected function setUp(): void
$this->client = self::createClient();
}

/**
* @dataProvider exporterNameProvider
*/
#[DataProvider('exporterNameProvider')]
public function testPreResponseEvent(string $exporterName, string $ext): void
{
$this->client->request('POST', '/exporter', ['_dt' => 'dt', '_exporter' => $exporterName]);
Expand All @@ -43,7 +42,7 @@ public function testPreResponseEvent(string $exporterName, string $ext): void
static::assertStringContainsString($response->headers->get('content-disposition'), sprintf('attachment; filename=custom_filename.%s', $ext));
}

public function exporterNameProvider(): array
public static function exporterNameProvider(): array
{
return [
['excel', 'xlsx'],
Expand Down
19 changes: 7 additions & 12 deletions tests/Functional/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace Tests\Functional;

use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Bundle\FrameworkBundle\KernelBrowser;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\Debug\Exception\FlattenException;
Expand Down Expand Up @@ -125,9 +126,7 @@ public function testGrouped2DataTable(): void
$this->assertStringStartsWith('Company ', $json->data[0]->company);
}

/**
* @dataProvider translationProvider
*/
#[DataProvider('translationProvider')]
public function testTranslation(string $locale, string $languageProcessing, string $languageInfoFiltered): void
{
$this->client->request('GET', sprintf('/%s/translation', $locale));
Expand All @@ -140,7 +139,7 @@ public function testTranslation(string $locale, string $languageProcessing, stri
$this->assertStringContainsString(sprintf('"infoFiltered":"%s"', $languageInfoFiltered), $content);
}

public function translationProvider(): array
public static function translationProvider(): array
{
return [
['en', 'Processing...', '(filtered from _MAX_ total entries)'],
Expand All @@ -149,9 +148,7 @@ public function translationProvider(): array
];
}

/**
* @dataProvider languageInCDNProvider
*/
#[DataProvider('languageInCDNProvider')]
public function testLanguageInCDN(string $locale): void
{
$this->client->request('GET', sprintf('/%s/translation?cdn', $locale));
Expand All @@ -162,7 +159,7 @@ public function testLanguageInCDN(string $locale): void
$this->assertStringContainsString('"options":{"language":{"url"', $content);
}

public function languageInCDNProvider(): array
public static function languageInCDNProvider(): array
{
return [
['en'],
Expand All @@ -171,9 +168,7 @@ public function languageInCDNProvider(): array
];
}

/**
* @dataProvider languageNotInCDNProvider
*/
#[DataProvider('languageNotInCDNProvider')]
public function testLanguageNotInCDN(string $locale): void
{
$this->client->request('GET', sprintf('/%s/translation?cdn', $locale));
Expand All @@ -184,7 +179,7 @@ public function testLanguageNotInCDN(string $locale): void
$this->assertStringNotContainsString('"options":{"language":{"url"', $content);
}

public function languageNotInCDNProvider(): array
public static function languageNotInCDNProvider(): array
{
return [
['ua'],
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/Adapter/ElasticaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class ElasticaTest extends TestCase
{
public function testElasticaAdapter(): void
{
$this->markTestSkipped('Needs to be ported to PHPUnit 10');

// Set up expectations
$transport = $this->getMockBuilder(AbstractTransport::class)
->setMethods(['exec'])
// ->setMethods(['exec'])
->getMock();
$transport
->expects($this->exactly(2))
Expand Down

0 comments on commit 81b88de

Please sign in to comment.