Skip to content

Commit

Permalink
Upgrade "phpunit/phpunit"
Browse files Browse the repository at this point in the history
This commit also replaces PHPUnit annotations with attributes.

Signed-off-by: Henrique Moody <[email protected]>
  • Loading branch information
henriquemoody committed Jan 28, 2024
1 parent 9a19b23 commit 12c1457
Show file tree
Hide file tree
Showing 167 changed files with 1,017 additions and 1,360 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.couscous/
.iso-codes-cache/
.phpcs.cache
.phpunit.result.cache
.phpunit.cache/
composer.lock
Makefile
phpcs.xml
Expand Down
8 changes: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ declare(strict_types=1);

namespace Respect\Validation\Rules;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use Respect\Validation\Test\RuleTestCase;

/**
* @group rule
* @covers \Respect\Validation\Rules\HelloWorld
*/
#[Group('rule')]
#[CoversClass(HelloWorld::class)]
final class HelloWorldTest extends RuleTestCase
{
/**
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^9.6",
"phpunit/phpunit": "^10.5",
"psr/http-message": "^1.0",
"respect/coding-standard": "^4.0",
"squizlabs/php_codesniffer": "^3.8"
Expand Down
15 changes: 6 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="unit">
<directory suffix="Test.php">tests/unit/</directory>
Expand All @@ -18,9 +15,9 @@
<directory suffix=".phpt">tests/integration/</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
<source>
<include>
<directory suffix=".php">library/</directory>
<directory suffix=".php">library/</directory>
</include>
</coverage>
</source>
</phpunit>
21 changes: 8 additions & 13 deletions tests/library/RuleTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace Respect\Validation\Test;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Validatable;

use function implode;
Expand All @@ -17,9 +19,6 @@
use function Respect\Stringifier\stringify;
use function sprintf;

/**
* @since 1.0.0
*/
abstract class RuleTestCase extends TestCase
{
/**
Expand All @@ -29,7 +28,7 @@ abstract class RuleTestCase extends TestCase
* as the first element and an input in which the validation SHOULD pass.
*
* @api
* @return mixed[][]
* @return array<string|int, array{Validatable, mixed}>
*/
abstract public static function providerForValidInput(): array;

Expand All @@ -40,23 +39,19 @@ abstract public static function providerForValidInput(): array;
* as the first element and an input in which the validation SHOULD NOT pass.
*
* @api
* @return mixed[][]
* @return array<string|int, array{Validatable, mixed}>
*/
abstract public static function providerForInvalidInput(): array;

/**
* @test
* @dataProvider providerForValidInput
*/
#[Test]
#[DataProvider('providerForValidInput')]
public function shouldValidateValidInput(Validatable $validator, mixed $input): void
{
self::assertValidInput($validator, $input);
}

/**
* @test
* @dataProvider providerForInvalidInput
*/
#[Test]
#[DataProvider('providerForInvalidInput')]
public function shouldValidateInvalidInput(Validatable $validator, mixed $input): void
{
self::assertInvalidInput($validator, $input);
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/Exceptions/CheckExceptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,21 @@
namespace Respect\Validation\Exceptions;

use DirectoryIterator;
use PHPUnit\Framework\Attributes\CoversNothing;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use ReflectionClass;
use Respect\Validation\Test\TestCase;

use function class_exists;
use function mb_substr;
use function sprintf;

/**
* @coversNothing
*/
#[CoversNothing]
final class CheckExceptionsTest extends TestCase
{
/**
* @dataProvider provideListOfRuleNames
* @test
*/
#[Test]
#[DataProvider('provideListOfRuleNames')]
public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void
{
$exceptionClass = 'Respect\\Validation\\Exceptions\\' . $ruleName . 'Exception';
Expand Down
16 changes: 7 additions & 9 deletions tests/unit/Exceptions/NestedValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@

namespace Respect\Validation\Exceptions;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Message\Formatter;
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
use Respect\Validation\Test\TestCase;

/**
* @covers \Respect\Validation\Exceptions\NestedValidationException
*/
#[Group('core')]
#[CoversClass(NestedValidationException::class)]
final class NestedValidationExceptionTest extends TestCase
{
/**
* @test
*/
#[Test]
public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
{
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
Expand All @@ -30,9 +30,7 @@ public function getChildrenShouldReturnExceptionAddedByAddRelated(): void
self::assertContainsOnly(IntValException::class, $composite->getChildren());
}

/**
* @test
*/
#[Test]
public function addingTheSameInstanceShouldAddJustOneSingleReference(): void
{
$composite = new AttributeException('input', 'id', [], new Formatter('strval', new KeepOriginalStringName()));
Expand Down
65 changes: 19 additions & 46 deletions tests/unit/Exceptions/ValidationExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,28 @@

namespace Respect\Validation\Exceptions;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;
use Respect\Validation\Message\Formatter;
use Respect\Validation\Message\Stringifier\KeepOriginalStringName;
use Respect\Validation\Test\TestCase;

use function trim;

/**
* @group core
* @covers \Respect\Validation\Exceptions\ValidationException
*/
#[Group('core')]
#[CoversClass(ValidationException::class)]
final class ValidationExceptionTest extends TestCase
{
/**
* @test
*/
#[Test]
public function itShouldImplementException(): void
{
$sut = new ValidationException('input', 'id', [], $this->createFormatter());

self::assertInstanceOf(Exception::class, $sut);
}

/**
* @test
*/
#[Test]
public function itShouldRetrieveId(): void
{
$id = 'my id';
Expand All @@ -42,9 +39,7 @@ public function itShouldRetrieveId(): void
self::assertSame($id, $sut->getId());
}

/**
* @test
*/
#[Test]
public function itShouldRetrieveParams(): void
{
$params = ['foo' => true, 'bar' => 23];
Expand All @@ -54,9 +49,7 @@ public function itShouldRetrieveParams(): void
self::assertSame($params, $sut->getParams());
}

/**
* @test
*/
#[Test]
public function itShouldRetrieveOneSingleParameter(): void
{
$name = 'any name';
Expand All @@ -67,29 +60,23 @@ public function itShouldRetrieveOneSingleParameter(): void
self::assertSame($value, $sut->getParam($name));
}

/**
* @test
*/
#[Test]
public function itShouldReturnNullWhenParameterCanNotBeFound(): void
{
$sut = new ValidationException('input', 'id', [], $this->createFormatter());

self::assertNull($sut->getParam('foo'));
}

/**
* @test
*/
#[Test]
public function itShouldHaveTemplateByDefault(): void
{
$sut = new ValidationException('input', 'id', [], $this->createFormatter());

self::assertSame('"input" must be valid', $sut->getMessage());
}

/**
* @test
*/
#[Test]
public function itShouldUpdateMode(): void
{
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
Expand All @@ -98,9 +85,7 @@ public function itShouldUpdateMode(): void
self::assertSame('"input" must not be valid', $sut->getMessage());
}

/**
* @test
*/
#[Test]
public function itShouldUpdateTemplate(): void
{
$template = 'This is my new template';
Expand All @@ -111,9 +96,7 @@ public function itShouldUpdateTemplate(): void
self::assertEquals($template, $sut->getMessage());
}

/**
* @test
*/
#[Test]
public function itShouldTellWhenHasAsCustomUpdateTemplate(): void
{
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
Expand All @@ -125,9 +108,7 @@ public function itShouldTellWhenHasAsCustomUpdateTemplate(): void
self::assertTrue($sut->hasCustomTemplate());
}

/**
* @test
*/
#[Test]
public function itShouldUseFormatter(): void
{
$template = ' This is my new template ';
Expand All @@ -139,9 +120,7 @@ public function itShouldUseFormatter(): void
self::assertEquals($expected, $sut->getMessage());
}

/**
* @test
*/
#[Test]
public function itShouldReplacePlaceholders(): void
{
$sut = new ValidationException('foo', 'id', ['bar' => 1, 'baz' => 2], $this->createFormatter());
Expand All @@ -153,9 +132,7 @@ public function itShouldReplacePlaceholders(): void
);
}

/**
* @test
*/
#[Test]
public function itShouldKeepPlaceholdersThatCanNotReplace(): void
{
$sut = new ValidationException('foo', 'id', ['foo' => 1], $this->createFormatter());
Expand All @@ -167,9 +144,7 @@ public function itShouldKeepPlaceholdersThatCanNotReplace(): void
);
}

/**
* @test
*/
#[Test]
public function itShouldUpdateParams(): void
{
$sut = new ValidationException('input', 'id', ['foo' => 1], $this->createFormatter());
Expand All @@ -179,9 +154,7 @@ public function itShouldUpdateParams(): void
self::assertEquals('2', $sut->getMessage());
}

/**
* @test
*/
#[Test]
public function itShouldConvertToString(): void
{
$sut = new ValidationException('input', 'id', [], $this->createFormatter());
Expand Down
Loading

0 comments on commit 12c1457

Please sign in to comment.