diff --git a/.github/workflows/qa.yml b/.github/workflows/qa.yml index c2fe040..0712db4 100644 --- a/.github/workflows/qa.yml +++ b/.github/workflows/qa.yml @@ -10,11 +10,11 @@ jobs: strategy: matrix: operating-system: [ubuntu-latest] - php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1'] + php-versions: ['8.2', '8.3', '8.4'] runs-on: ${{ matrix.operating-system }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -27,7 +27,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} @@ -46,12 +46,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '8.0' + php-version: '8.2' coverage: none - name: Get composer cache directory @@ -59,7 +59,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} @@ -76,12 +76,12 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: 8.0 + php-version: '8.2' coverage: none - name: Get composer cache directory @@ -89,7 +89,7 @@ jobs: run: echo "::set-output name=dir::$(composer config cache-files-dir)" - name: Cache composer dependencies - uses: actions/cache@v2 + uses: actions/cache@v4 with: path: ${{ steps.composer-cache.outputs.dir }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 98% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index da6bde7..992b9a0 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -15,7 +15,7 @@ file that was distributed with this source code. EOF; -return Config::create() +return (new Config()) ->setUsingCache(false) ->setRiskyAllowed(true) ->setRules([ diff --git a/composer.json b/composer.json index f4c4d7d..b5c5609 100644 --- a/composer.json +++ b/composer.json @@ -11,17 +11,17 @@ } ], "require": { - "php": "^7.2.5|^8", - "composer/package-versions-deprecated": "1.11.99.5", + "php": "^8.2", + "composer/package-versions-deprecated": "^1.11", "composer/semver": "^3.3", - "rybakit/phpunit-extras": "^0.2.4", - "symfony/expression-language": "^3.3|^4|^5|^6", + "rybakit/phpunit-extras": "dev-feature/php82-phpunit10-attributes-migration", + "symfony/expression-language": "^7.0", "tarantool/client": "^0.10" }, "require-dev": { - "php": "^7.2.5|^8", - "friendsofphp/php-cs-fixer": "^2.19", - "vimeo/psalm": "^3.9|^4" + "friendsofphp/php-cs-fixer": "^3", + "phpunit/phpunit": "^10.5", + "vimeo/psalm": "^5.23|^6" }, "autoload": { "psr-4": { @@ -38,5 +38,12 @@ "*": "dist" }, "sort-packages": true - } + }, + "minimum-stability": "dev", + "prefer-stable": true, + "repositories": [{ + "type": "vcs", + "url": "https://github.com/rybakit/phpunit-extras", + "no-api": true + }] } diff --git a/phpunit-extension.xml b/phpunit-extension.xml index fef869a..f343a3e 100644 --- a/phpunit-extension.xml +++ b/phpunit-extension.xml @@ -1,45 +1,26 @@ - - - - - - - - - - - - tests/Annotation/AnnotationExtensionTest.php - - - - - - src - - - - - - - - - true - - - 42 - - - foobar - - - - - + + + + + + + + + + tests/Annotation/AnnotationExtensionTest.php + + + + + src + + + + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c48d998..c6e4b88 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,28 +1,20 @@ - - - - - - - - - - - - tests - tests/Annotation/AnnotationExtensionTest.php - - - - - - src - - + + + + + + + + + + tests + tests/Annotation/AnnotationExtensionTest.php + + + + + src + + diff --git a/psalm.xml b/psalm.xml index 18db1fb..fbc3fcb 100644 --- a/psalm.xml +++ b/psalm.xml @@ -14,15 +14,16 @@ - + + + + + + + - - - - - - + - + diff --git a/src/Annotation/AnnotationExtension.php b/src/Annotation/AnnotationExtension.php index 2c8ae49..e7e2352 100644 --- a/src/Annotation/AnnotationExtension.php +++ b/src/Annotation/AnnotationExtension.php @@ -22,19 +22,39 @@ class AnnotationExtension extends BaseAnnotationExtension use Annotations; /** @var array|string */ - private $clientConfig; + private $clientConfig = 'tcp://127.0.0.1:3301'; /** @var Client|null */ private $client; - /** - * @param array|string $clientConfig - */ - public function __construct($clientConfig = 'tcp://127.0.0.1:3301') + #[\Override] + public function bootstrap(\PHPUnit\TextUI\Configuration\Configuration $configuration, \PHPUnit\Runner\Extension\Facade $facade, \PHPUnit\Runner\Extension\ParameterCollection $parameters) : void { - $this->clientConfig = $clientConfig; + $this->parseParameters($parameters); + parent::bootstrap($configuration, $facade, $parameters); + } + + protected function parseParameters(\PHPUnit\Runner\Extension\ParameterCollection $parameters) : void + { + if ($parameters->has('dsn')) { + $this->clientConfig = $parameters->get('dsn'); + } else { + $closure = \Closure::bind(function () { + /** + * @psalm-suppress InaccessibleProperty + * @var \PHPUnit\Runner\Extension\ParameterCollection $this + */ + return $this->parameters; + }, $parameters, \PHPUnit\Runner\Extension\ParameterCollection::class); + $options = $closure ? $closure() : []; + + if ([] !== $options) { + $this->clientConfig = $options; + } + } } + #[\Override] protected function getClient() : Client { if ($this->client) { @@ -71,12 +91,12 @@ final protected function getClientConfig(bool $resolveEnvVars = true) private static function resolveEnvValues(string $configValue) : string { - return preg_replace_callback('/%env\((?P.+?)\)%/', static function (array $matches) : string { + return (string) preg_replace_callback('/%env\((?P.+?)\)%/', static function (array $matches) : string { if (false !== $value = getenv($matches['name'])) { return $value; } - $errorMessage = sprintf('Environment variable "%s" does not exist', $matches['name']); + $errorMessage = \sprintf('Environment variable "%s" does not exist', $matches['name']); throw new class($errorMessage) extends \RuntimeException implements Exception { }; }, $configValue); } diff --git a/src/Annotation/Attribute/Lua.php b/src/Annotation/Attribute/Lua.php new file mode 100644 index 0000000..119b002 --- /dev/null +++ b/src/Annotation/Attribute/Lua.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Tarantool\PhpUnit\Annotation\Attribute; + +use PHPUnitExtras\Annotation\Attribute\AnnotationAttribute; + +#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] +final class Lua implements AnnotationAttribute +{ + private $code; + + public function __construct(string $code) + { + $this->code = $code; + } + + #[\Override] + public function getName() : string + { + return 'lua'; + } + + #[\Override] + public function getValue() : string + { + return $this->code; + } +} diff --git a/src/Annotation/Attribute/Sql.php b/src/Annotation/Attribute/Sql.php new file mode 100644 index 0000000..45370d9 --- /dev/null +++ b/src/Annotation/Attribute/Sql.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Tarantool\PhpUnit\Annotation\Attribute; + +use PHPUnitExtras\Annotation\Attribute\AnnotationAttribute; + +#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)] +final class Sql implements AnnotationAttribute +{ + private $code; + + public function __construct(string $code) + { + $this->code = $code; + } + + #[\Override] + public function getName() : string + { + return 'sql'; + } + + #[\Override] + public function getValue() : string + { + return $this->code; + } +} diff --git a/src/Annotation/Processor/LuaProcessor.php b/src/Annotation/Processor/LuaProcessor.php index 375bd67..d76eca9 100644 --- a/src/Annotation/Processor/LuaProcessor.php +++ b/src/Annotation/Processor/LuaProcessor.php @@ -25,11 +25,13 @@ public function __construct(Client $client) $this->client = $client; } + #[\Override] public function getName() : string { return 'lua'; } + #[\Override] public function process(string $value) : void { $this->client->evaluate($value); diff --git a/src/Annotation/Processor/SqlProcessor.php b/src/Annotation/Processor/SqlProcessor.php index 144c6b5..3c8261e 100644 --- a/src/Annotation/Processor/SqlProcessor.php +++ b/src/Annotation/Processor/SqlProcessor.php @@ -25,11 +25,13 @@ public function __construct(Client $client) $this->client = $client; } + #[\Override] public function getName() : string { return 'sql'; } + #[\Override] public function process(string $value) : void { $this->client->executeUpdate($value); diff --git a/src/Annotation/Requirement/LuaConditionRequirement.php b/src/Annotation/Requirement/LuaConditionRequirement.php index 9b1b950..976d586 100644 --- a/src/Annotation/Requirement/LuaConditionRequirement.php +++ b/src/Annotation/Requirement/LuaConditionRequirement.php @@ -25,11 +25,13 @@ public function __construct(Client $client) $this->client = $client; } + #[\Override] public function getName() : string { return 'luaCondition'; } + #[\Override] public function check(string $value) : ?string { [$result] = $this->client->evaluate("return ($value)"); @@ -38,6 +40,6 @@ public function check(string $value) : ?string return null; } - return sprintf('"%s" is not evaluated to true', $value); + return \sprintf('"%s" is not evaluated to true', $value); } } diff --git a/src/Annotation/Requirement/TarantoolVersionRequirement.php b/src/Annotation/Requirement/TarantoolVersionRequirement.php index 7d8ecb4..dcb5d63 100644 --- a/src/Annotation/Requirement/TarantoolVersionRequirement.php +++ b/src/Annotation/Requirement/TarantoolVersionRequirement.php @@ -29,21 +29,23 @@ public function __construct(Client $client) $this->client = $client; } + #[\Override] public function getName() : string { return 'Tarantool'; } + #[\Override] public function check(string $value) : ?string { // Replace dash with dot. - $constraints = preg_replace('/(\d+\.\d+\.\d+)-(\d+)/', '$1.$2', $value); + $constraints = (string) preg_replace('/(\d+\.\d+\.\d+)-(\d+)/', '$1.$2', $value); if (Semver::satisfies($this->getVersion(), $constraints)) { return null; } - return sprintf('%s version %s is required', $this->getName(), $value); + return \sprintf('%s version %s is required', $this->getName(), $value); } private function getVersion() : string @@ -53,13 +55,16 @@ private function getVersion() : string } $version = $this->client->call('box.info')[0]['version']; + if (!\is_string($version)) { + throw new \UnexpectedValueException('Tarantool version must be a string'); + } // Normalize 2.2.1-3-g878e2a42c to 2.2.1.3. - $version = preg_replace('/-(\d+)-[^-]+$/', '.$1', $version); + $version = (string) preg_replace('/-(\d+)-[^-]+$/', '.$1', $version); // Treat "entrypoint" versions as "dev", // so 2.11.0-entrypoint.8 becomes 2.11.0-dev+entrypoint.8. - $version = preg_replace('/(\d)-entrypoint/', '$1-dev+entrypoint', $version); + $version = (string) preg_replace('/(\d)-entrypoint/', '$1-dev+entrypoint', $version); return $this->version = $version; } diff --git a/src/Client/IsRequestType.php b/src/Client/IsRequestType.php index b8b4c57..141c510 100644 --- a/src/Client/IsRequestType.php +++ b/src/Client/IsRequestType.php @@ -25,18 +25,20 @@ final class IsRequestType extends Constraint public function __construct(int $requestType) { // needed for backward compatibility with PHPUnit 7 - if (\is_callable('parent::__construct')) { + if (method_exists(parent::class, '__construct')) { parent::__construct(); } $this->requestType = $requestType; } + #[\Override] public function toString() : string { - return sprintf('is a "%s" request', strtoupper(RequestTypes::getName($this->requestType))); + return \sprintf('is a "%s" request', strtoupper(RequestTypes::getName($this->requestType))); } + #[\Override] protected function matches($other) : bool { return $other instanceof Request && $other->getType() === $this->requestType; diff --git a/src/Client/TestDoubleClientBuilder.php b/src/Client/TestDoubleClientBuilder.php index 8ce18b3..5f37445 100755 --- a/src/Client/TestDoubleClientBuilder.php +++ b/src/Client/TestDoubleClientBuilder.php @@ -41,7 +41,7 @@ final class TestDoubleClientBuilder private $packer; /** @var int|null */ - private $shouldBeCalledTimes = null; + private $shouldBeCalledTimes; public function __construct(TestCase $testCase) { @@ -51,12 +51,8 @@ public function __construct(TestCase $testCase) public static function buildDummy() : Client { - /** - * @psalm-suppress InternalMethod - * @psalm-suppress PropertyNotSetInConstructor - */ - $self = new self(new class() extends TestCase { - }); + /** @psalm-suppress InternalMethod */ + $self = new self(new class('dummy') extends TestCase {}); return $self->build(); } @@ -79,9 +75,8 @@ public function shouldSend($request, ...$requests) : self /** * @param Request|Constraint|int $request - * @param Response ...$responses */ - public function shouldHandle($request, ...$responses) : self + public function shouldHandle($request, Response ...$responses) : self { $this->shouldSend($request); $this->willReceive(...$responses); @@ -137,7 +132,24 @@ private function createHandler() : MockObject : $handler->method('handle'); if ($this->requests) { - $handleMocker->withConsecutive(...array_chunk($this->requests, 1)); + $invocationCount = 0; + $requests = $this->requests; + $handleMocker->with(TestCase::callback(static function ($request) use (&$invocationCount, $requests) { + if (!isset($requests[$invocationCount])) { + ++$invocationCount; + + return true; + } + $expected = $requests[$invocationCount++]; + + if ($expected instanceof Constraint) { + return (bool) $expected->evaluate($request, '', true); + } + + $constraint = new \PHPUnit\Framework\Constraint\IsEqual($expected); + + return (bool) $constraint->evaluate($request, '', true); + })); } if (1 === \count($this->responses)) { diff --git a/src/Client/TestDoubleFactory.php b/src/Client/TestDoubleFactory.php old mode 100755 new mode 100644 diff --git a/src/Expectation/ExpressionContext/PreparedStatementCountContext.php b/src/Expectation/ExpressionContext/PreparedStatementCountContext.php index 0d8d71d..ab69daa 100644 --- a/src/Expectation/ExpressionContext/PreparedStatementCountContext.php +++ b/src/Expectation/ExpressionContext/PreparedStatementCountContext.php @@ -52,11 +52,13 @@ public static function atMost(Client $client, int $count) : self return new self($client, "new_count <= old_count + $count"); } + #[\Override] public function getExpression() : string { return $this->expression; } + #[\Override] public function getValues() : array { if (null === $this->finalValue) { diff --git a/src/Expectation/ExpressionContext/RequestCountContext.php b/src/Expectation/ExpressionContext/RequestCountContext.php index b5f821a..20d4226 100644 --- a/src/Expectation/ExpressionContext/RequestCountContext.php +++ b/src/Expectation/ExpressionContext/RequestCountContext.php @@ -75,11 +75,13 @@ public static function atMost(Client $client, RequestCounter $requestCounter, st return new self($client, $requestCounter, $requestName, "new_count <= old_count + $count"); } + #[\Override] public function getExpression() : string { return $this->expression; } + #[\Override] public function getValues() : array { if (null === $this->finalValue) { diff --git a/src/Expectation/ExpressionContext/RequestCounter.php b/src/Expectation/ExpressionContext/RequestCounter.php index c020cea..a1cfee8 100644 --- a/src/Expectation/ExpressionContext/RequestCounter.php +++ b/src/Expectation/ExpressionContext/RequestCounter.php @@ -25,6 +25,7 @@ final class RequestCounter implements Middleware */ private $requestCount = []; + #[\Override] public function process(Request $request, Handler $handler) : Response { $response = $handler->handle($request); diff --git a/tests/Annotation/AnnotationExtension.php b/tests/Annotation/AnnotationExtension.php index d2a9e83..fe084e6 100755 --- a/tests/Annotation/AnnotationExtension.php +++ b/tests/Annotation/AnnotationExtension.php @@ -27,4 +27,9 @@ protected function getClient() : Client return TestDoubleClientBuilder::buildDummy(); } + + public function doParseParameters(array $parameters) : void + { + $this->parseParameters(\PHPUnit\Runner\Extension\ParameterCollection::fromArray($parameters)); + } } diff --git a/tests/Annotation/AnnotationExtensionTest.php b/tests/Annotation/AnnotationExtensionTest.php index cf9c334..ca5fddc 100755 --- a/tests/Annotation/AnnotationExtensionTest.php +++ b/tests/Annotation/AnnotationExtensionTest.php @@ -14,35 +14,37 @@ namespace Tarantool\PhpUnit\Tests\Annotation; use PHPUnit\Framework\TestCase; +use Tarantool\PhpUnit\Annotation\Attribute\Lua; final class AnnotationExtensionTest extends TestCase { - /** - * @lua dummy_code_to_trigger_annotation_processing = true - */ - public function testConstructorUsesDefaultDsn() : void + private function bootstrapExtension(string $method, array $parameters = []) : AnnotationExtension { $ext = new AnnotationExtension(); + $ext->doParseParameters($parameters); + $ext->processTestAttributes(self::class, $method); + + return $ext; + } + + #[Lua('dummy_code_to_trigger_annotation_processing = true')] + public function testConstructorUsesDefaultDsn() : void + { + $ext = $this->bootstrapExtension(__FUNCTION__); - $ext->executeBeforeTest(__METHOD__); self::assertSame('tcp://127.0.0.1:3301', $ext->resolvedDnsOrOptions); } - /** - * @lua dummy_code_to_trigger_annotation_processing = true - */ + #[Lua('dummy_code_to_trigger_annotation_processing = true')] public function testConstructorUsesCustomDsn() : void { $dsn = 'tcp://tnt_foobar:3302'; - $ext = new AnnotationExtension($dsn); + $ext = $this->bootstrapExtension(__FUNCTION__, ['dsn' => $dsn]); - $ext->executeBeforeTest(__METHOD__); self::assertSame($dsn, $ext->resolvedDnsOrOptions); } - /** - * @lua dummy_code_to_trigger_annotation_processing = true - */ + #[Lua('dummy_code_to_trigger_annotation_processing = true')] public function testGetClientConfigNormalizesDsnString() : void { $hostname = 'tnt_foobar'; @@ -51,15 +53,12 @@ public function testGetClientConfigNormalizesDsnString() : void $envPortName = 'tnt_phpunit_env_port_'.random_int(1, 1000); putenv("$envHostName=$hostname"); putenv("$envPortName=$port"); - $ext = new AnnotationExtension("tcp://%env($envHostName)%:%env($envPortName)%"); + $ext = $this->bootstrapExtension(__FUNCTION__, ['dsn' => "tcp://%env($envHostName)%:%env($envPortName)%"]); - $ext->executeBeforeTest(__METHOD__); self::assertSame("tcp://$hostname:$port", $ext->resolvedDnsOrOptions); } - /** - * @lua dummy_code_to_trigger_annotation_processing = true - */ + #[Lua('dummy_code_to_trigger_annotation_processing = true')] public function testGetClientConfigNormalizesOptionArray() : void { $hostname = 'tnt_foobar'; @@ -68,17 +67,16 @@ public function testGetClientConfigNormalizesOptionArray() : void $envPortName = 'tnt_phpunit_env_port_'.random_int(1, 1000); putenv("$envHostName=$hostname"); putenv("$envPortName=$port"); - $ext = new AnnotationExtension([ + $ext = $this->bootstrapExtension(__FUNCTION__, [ 'uri' => "tcp://%env($envHostName)%:%env($envPortName)%", - 'socket_timeout' => 10, - 'persistent' => true, + 'socket_timeout' => '10', + 'persistent' => '1', ]); - $ext->executeBeforeTest(__METHOD__); - self::assertSame([ + self::assertEquals([ 'uri' => "tcp://$hostname:$port", - 'socket_timeout' => 10, - 'persistent' => true, + 'socket_timeout' => '10', + 'persistent' => '1', ], $ext->resolvedDnsOrOptions); } } diff --git a/tests/Annotation/Requirement/LuaConditionRequirementTest.php b/tests/Annotation/Requirement/LuaConditionRequirementTest.php index 24096a2..b1f1076 100755 --- a/tests/Annotation/Requirement/LuaConditionRequirementTest.php +++ b/tests/Annotation/Requirement/LuaConditionRequirementTest.php @@ -50,7 +50,7 @@ public function testCheckFailsForFalsyExpression() : void ) ->build(); - $errorMessage = sprintf('"%s" is not evaluated to true', $luaExpression); + $errorMessage = \sprintf('"%s" is not evaluated to true', $luaExpression); $requirement = new LuaConditionRequirement($mockClient); self::assertSame($errorMessage, $requirement->check($luaExpression)); diff --git a/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php b/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php index 57983dc..12a2808 100755 --- a/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php +++ b/tests/Annotation/Requirement/TarantoolVersionRequirementTest.php @@ -13,6 +13,7 @@ namespace Tarantool\PhpUnit\Tests\Annotation\Requirement; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Tarantool\Client\Request\CallRequest; use Tarantool\PhpUnit\Annotation\Requirement\TarantoolVersionRequirement; @@ -23,9 +24,7 @@ final class TarantoolVersionRequirementTest extends TestCase { use TestDoubleClient; - /** - * @dataProvider provideCheckPassesForValidConstraintsData() - */ + #[DataProvider('provideCheckPassesForValidConstraintsData')] public function testCheckPassesForValidConstraints(string $serverVersion, string $constraints) : void { $mockClient = $this->getTestDoubleClientBuilder() @@ -39,7 +38,7 @@ public function testCheckPassesForValidConstraints(string $serverVersion, string self::assertNull($requirement->check($constraints)); } - public function provideCheckPassesForValidConstraintsData() : iterable + public static function provideCheckPassesForValidConstraintsData() : iterable { $v2_3_1_3 = '2.3.1-3-g878e2a42c'; @@ -95,9 +94,7 @@ public function provideCheckPassesForValidConstraintsData() : iterable ]; } - /** - * @dataProvider provideCheckFailsForInvalidConstraintsData() - */ + #[DataProvider('provideCheckFailsForInvalidConstraintsData')] public function testCheckFailsForInvalidConstraints(string $serverVersion, string $constraints) : void { $mockClient = $this->getTestDoubleClientBuilder() @@ -107,12 +104,12 @@ public function testCheckFailsForInvalidConstraints(string $serverVersion, strin ->build(); $requirement = new TarantoolVersionRequirement($mockClient); - $errorMessage = sprintf('Tarantool version %s is required', $constraints); + $errorMessage = \sprintf('Tarantool version %s is required', $constraints); self::assertSame($errorMessage, $requirement->check($constraints)); } - public function provideCheckFailsForInvalidConstraintsData() : iterable + public static function provideCheckFailsForInvalidConstraintsData() : iterable { $v2_3_1_3 = '2.3.1-3-g878e2a42c'; diff --git a/tests/Expectation/RequestExpectationsTest.php b/tests/Expectation/RequestExpectationsTest.php index 3453ec6..160b194 100755 --- a/tests/Expectation/RequestExpectationsTest.php +++ b/tests/Expectation/RequestExpectationsTest.php @@ -13,6 +13,7 @@ namespace Tarantool\PhpUnit\Tests\Expectation; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\ExpectationFailedException; use PHPUnitExtras\TestCase; use Tarantool\Client\Client; @@ -33,7 +34,7 @@ protected function getClient() : Client { // increase values for eval requests // to eliminate RequestCounter's count adjustments - if ('Eval' === $this->getProvidedData()[0]) { + if ('Eval' === $this->providedData()[0]) { ++$this->oldValue; $this->newValue += 2; } @@ -47,7 +48,7 @@ protected function getClient() : Client ->build(); } - public function provideRequestNames() : iterable + public static function provideRequestNames() : iterable { return [ ['Auth'], @@ -63,9 +64,7 @@ public function provideRequestNames() : iterable ]; } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -74,9 +73,7 @@ public function testExpectToBeCalledSucceeds(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledFails(string $requestName) : void { $this->oldValue = 1; @@ -87,9 +84,7 @@ public function testExpectToBeCalledFails(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtLeastSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -98,9 +93,7 @@ public function testExpectToBeCalledAtLeastSucceeds(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtLeastFails(string $requestName) : void { $this->oldValue = 1; @@ -111,9 +104,7 @@ public function testExpectToBeCalledAtLeastFails(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtMostSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -122,9 +113,7 @@ public function testExpectToBeCalledAtMostSucceeds(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtMostFails(string $requestName) : void { $this->oldValue = 1; @@ -135,9 +124,7 @@ public function testExpectToBeCalledAtMostFails(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledOnceSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -146,9 +133,7 @@ public function testExpectToBeCalledOnceSucceeds(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledOnceFails(string $requestName) : void { $this->oldValue = 1; @@ -159,9 +144,7 @@ public function testExpectToBeCalledOnceFails(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeNeverCalledSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -170,9 +153,7 @@ public function testExpectToBeNeverCalledSucceeds(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeNeverCalledFails(string $requestName) : void { $this->oldValue = 1; @@ -183,9 +164,7 @@ public function testExpectToBeNeverCalledFails(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtLeastOnceSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -194,9 +173,7 @@ public function testExpectToBeCalledAtLeastOnceSucceeds(string $requestName) : v $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtLeastOnceFails(string $requestName) : void { $this->oldValue = 1; @@ -207,9 +184,7 @@ public function testExpectToBeCalledAtLeastOnceFails(string $requestName) : void $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtMostOnceSucceeds(string $requestName) : void { $this->oldValue = 1; @@ -218,9 +193,7 @@ public function testExpectToBeCalledAtMostOnceSucceeds(string $requestName) : vo $this->verifyExpectations(); } - /** - * @dataProvider provideRequestNames - */ + #[DataProvider('provideRequestNames')] public function testExpectToBeCalledAtMostOnceFails(string $requestName) : void { $this->oldValue = 1;