Skip to content

Commit

Permalink
PHPUnit 10 Migration (#77)
Browse files Browse the repository at this point in the history
* Bump PHPUnit dependencies

* Ignore PHPUnit cache folder

* Adopt PHP attributes in test classes

* Declare data providers as `static`

* Add return types to test methods

* Define test classes as `final`

* Move to phpunit.xml.dist

* Remove flag for phpunit in local test env

---------

Co-authored-by: Shift <[email protected]>
  • Loading branch information
olivervogel and laravel-shift authored Feb 28, 2024
1 parent 5fb1176 commit 2252882
Show file tree
Hide file tree
Showing 34 changed files with 203 additions and 257 deletions.
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.phpunit.result.cache
/.phpunit.cache
.idea/
composer.lock
vendor/
phpunit.xml
vendor/
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"illuminate/validation": "~10"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1",
"symfony/uid": "^5.1|^6.2",
"slevomat/coding-standard": "~8.0",
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
services:
services:
tests:
build: ./
working_dir: /project
command: bash -c "composer install && ./vendor/bin/phpunit -vvv"
command: bash -c "composer install && ./vendor/bin/phpunit"
volumes:
- ./:/project
analysis:
Expand Down
13 changes: 0 additions & 13 deletions phpunit.xml

This file was deleted.

13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>./src/Intervention/Validation/Validator.php</directory>
</include>
</source>
</phpunit>
11 changes: 5 additions & 6 deletions tests/Rules/Base64Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Base64;
use PHPUnit\Framework\TestCase;

class Base64Test extends TestCase
final class Base64Test extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Base64())->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[
Expand Down
11 changes: 5 additions & 6 deletions tests/Rules/BicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Bic;
use PHPUnit\Framework\TestCase;

class BicTest extends TestCase
final class BicTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Bic())->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[true, 'PBNKDEFF'],
Expand Down
11 changes: 5 additions & 6 deletions tests/Rules/CamelcaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Camelcase;
use PHPUnit\Framework\TestCase;

class CamelcaseTest extends TestCase
final class CamelcaseTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Camelcase())->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[true, 'foo'],
Expand Down
11 changes: 5 additions & 6 deletions tests/Rules/CidrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Cidr;
use PHPUnit\Framework\TestCase;

class CidrTest extends TestCase
final class CidrTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Cidr())->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[true, '0.0.0.0/0'],
Expand Down
11 changes: 5 additions & 6 deletions tests/Rules/CreditcardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Creditcard;
use PHPUnit\Framework\TestCase;

class CreditcardTest extends TestCase
final class CreditcardTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Creditcard())->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[true, '4444111122223333'],
Expand Down
19 changes: 8 additions & 11 deletions tests/Rules/DataUriTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,27 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\DataUri;
use PHPUnit\Framework\TestCase;

class DataUriTest extends TestCase
final class DataUriTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new DataUri())->isValid($value);
$this->assertEquals($result, $valid);
}

/**
* @dataProvider dataProviderImages
*/
public function testValidationWithMimeTypes($result, $value)
#[DataProvider('dataProviderImages')]
public function testValidationWithMimeTypes($result, $value): void
{
$valid = (new DataUri(['image/jpeg', 'image/png']))->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[
Expand Down Expand Up @@ -126,7 +123,7 @@ public function dataProvider()
];
}

public function dataProviderImages()
public static function dataProviderImages(): array
{
return [
[
Expand Down
11 changes: 5 additions & 6 deletions tests/Rules/DomainnameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Domainname;
use PHPUnit\Framework\TestCase;

class DomainnameTest extends TestCase
final class DomainnameTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Domainname())->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[true, 'foo.com'],
Expand Down
27 changes: 11 additions & 16 deletions tests/Rules/EanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,34 @@

namespace Intervention\Validation\Tests\Rules;

use PHPUnit\Framework\Attributes\DataProvider;
use Intervention\Validation\Rules\Ean;
use PHPUnit\Framework\TestCase;

class EanTest extends TestCase
final class EanTest extends TestCase
{
/**
* @dataProvider dataProvider
*/
public function testValidation($result, $value)
#[DataProvider('dataProvider')]
public function testValidation($result, $value): void
{
$valid = (new Ean())->isValid($value);
$this->assertEquals($result, $valid);
}

/**
* @dataProvider dataProviderEan13
*/
public function testValidationEan13($result, $value)
#[DataProvider('dataProviderEan13')]
public function testValidationEan13($result, $value): void
{
$valid = (new Ean([13]))->isValid($value);
$this->assertEquals($result, $valid);
}

/**
* @dataProvider dataProviderEan8
*/
public function testValidationEan8($result, $value)
#[DataProvider('dataProviderEan8')]
public function testValidationEan8($result, $value): void
{
$valid = (new Ean([8]))->isValid($value);
$this->assertEquals($result, $valid);
}

public function dataProvider()
public static function dataProvider(): array
{
return [
[true, '9789510475270'],
Expand All @@ -62,7 +57,7 @@ public function dataProvider()
];
}

public function dataProviderEan13()
public static function dataProviderEan13(): array
{
return [
[true, '9789510475270'],
Expand All @@ -75,7 +70,7 @@ public function dataProviderEan13()
];
}

public function dataProviderEan8()
public static function dataProviderEan8(): array
{
return [
[false, '4012345678901'],
Expand Down
Loading

0 comments on commit 2252882

Please sign in to comment.