diff --git a/phpstan-tests.neon b/phpstan-tests.neon index 92922a1..4b62b22 100644 --- a/phpstan-tests.neon +++ b/phpstan-tests.neon @@ -4,29 +4,14 @@ parameters: paths: - ./tests bootstrapFiles: - - ./tests/phpstan-bootstrap.php + - ./tests/static-analysis/stubs.php checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false - excludes_analyse: - - ./tests/ExpectedBehaviorTest.php - - ./tests/phpstan-bootstrap.php + excludePaths: + analyse: + - ./tests/ExpectedBehaviorTest.php + - ./tests/static-analysis/stubs.php ignoreErrors: - - - message: "#^Function uuid_create\\(\\) has no return typehint specified\\.$#" - count: 1 - path: ./tests/phpstan-bootstrap.php - - - message: "#^Function uuid_create\\(\\) has parameter \\$uuid_type with no typehint specified\\.$#" - count: 1 - path: ./tests/phpstan-bootstrap.php - - - message: "#^Function uuid_parse\\(\\) has no return typehint specified\\.$#" - count: 1 - path: ./tests/phpstan-bootstrap.php - - - message: "#^Function uuid_parse\\(\\) has parameter \\$uuid with no typehint specified\\.$#" - count: 1 - path: ./tests/phpstan-bootstrap.php - message: "#^Call to static method Ramsey\\\\Uuid\\\\.+ on a separate line has no effect\\.$#" paths: diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 1382f73..b602959 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -6,7 +6,7 @@ parameters: checkMissingIterableValueType: false reportUnmatchedIgnoredErrors: false bootstrapFiles: - - ./tests/phpstan-bootstrap.php + - ./tests/static-analysis/stubs.php ignoreErrors: - message: '#^Call to function is_int\(\) with float will always evaluate to false\.$#' diff --git a/psalm.xml b/psalm.xml index 7d4f6f5..f607d91 100644 --- a/psalm.xml +++ b/psalm.xml @@ -8,11 +8,14 @@ - + + + + - + diff --git a/src/Generator/PeclUuidRandomGenerator.php b/src/Generator/PeclUuidRandomGenerator.php index df750f6..07c47d2 100644 --- a/src/Generator/PeclUuidRandomGenerator.php +++ b/src/Generator/PeclUuidRandomGenerator.php @@ -14,6 +14,9 @@ declare(strict_types=1); namespace Ramsey\Uuid\Generator; +use function uuid_create; +use function uuid_parse; + use const UUID_TYPE_RANDOM; /** diff --git a/src/Generator/PeclUuidTimeGenerator.php b/src/Generator/PeclUuidTimeGenerator.php index 903798d..e01f44e 100644 --- a/src/Generator/PeclUuidTimeGenerator.php +++ b/src/Generator/PeclUuidTimeGenerator.php @@ -14,6 +14,9 @@ declare(strict_types=1); namespace Ramsey\Uuid\Generator; +use function uuid_create; +use function uuid_parse; + use const UUID_TYPE_TIME; /** diff --git a/tests/Generator/PeclUuidNameGeneratorTest.php b/tests/Generator/PeclUuidNameGeneratorTest.php index 6d2aad3..6501b24 100644 --- a/tests/Generator/PeclUuidNameGeneratorTest.php +++ b/tests/Generator/PeclUuidNameGeneratorTest.php @@ -22,6 +22,7 @@ class PeclUuidNameGeneratorTest extends TestCase * @param non-empty-string $ns * * @dataProvider provideNamesForHashingTest + * @requires extension uuid */ public function testPeclUuidNameGeneratorHashesName(string $ns, string $name, string $algorithm): void { @@ -55,7 +56,7 @@ class PeclUuidNameGeneratorTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideNamesForHashingTest(): array { @@ -98,6 +99,7 @@ class PeclUuidNameGeneratorTest extends TestCase 'Unable to hash namespace and name with algorithm \'aBadAlgorithm\'' ); + /** @phpstan-ignore-next-line */ $generator->generate($namespace, 'a test name', 'aBadAlgorithm'); } } diff --git a/tests/Generator/PeclUuidRandomGeneratorTest.php b/tests/Generator/PeclUuidRandomGeneratorTest.php index acacf61..ec778a5 100644 --- a/tests/Generator/PeclUuidRandomGeneratorTest.php +++ b/tests/Generator/PeclUuidRandomGeneratorTest.php @@ -5,36 +5,25 @@ declare(strict_types=1); namespace Ramsey\Uuid\Test\Generator; use Ramsey\Uuid\Generator\PeclUuidRandomGenerator; -use phpmock\mockery\PHPMockery; +use Ramsey\Uuid\Rfc4122\Fields; +use Ramsey\Uuid\Test\TestCase; +use Ramsey\Uuid\Uuid; -use const UUID_TYPE_RANDOM; - -class PeclUuidRandomGeneratorTest extends PeclUuidTestCase +class PeclUuidRandomGeneratorTest extends TestCase { /** - * @var int - */ - private $length = 10; - - /** - * @runInSeparateProcess - * @preserveGlobalState disabled + * @requires extension uuid */ public function testGenerateCreatesUuidUsingPeclUuidMethods(): void { - PHPMockery::mock('Ramsey\Uuid\Generator', 'uuid_create') - ->once() - ->with(UUID_TYPE_RANDOM) - ->andReturn($this->uuidString); - - PHPMockery::mock('Ramsey\Uuid\Generator', 'uuid_parse') - ->once() - ->with($this->uuidString) - ->andReturn($this->uuidBinary); - $generator = new PeclUuidRandomGenerator(); - $uuid = $generator->generate($this->length); + $bytes = $generator->generate(10); + $uuid = Uuid::fromBytes($bytes); - $this->assertSame($this->uuidBinary, $uuid); + /** @var Fields $fields */ + $fields = $uuid->getFields(); + + $this->assertSame(16, strlen($bytes)); + $this->assertSame(Uuid::UUID_TYPE_RANDOM, $fields->getVersion()); } } diff --git a/tests/Generator/PeclUuidTestCase.php b/tests/Generator/PeclUuidTestCase.php deleted file mode 100644 index cb0f6b7..0000000 --- a/tests/Generator/PeclUuidTestCase.php +++ /dev/null @@ -1,20 +0,0 @@ -once() - ->with(UUID_TYPE_TIME) - ->andReturn($this->uuidString); - - PHPMockery::mock('Ramsey\Uuid\Generator', 'uuid_parse') - ->once() - ->with($this->uuidString) - ->andReturn($this->uuidBinary); - $generator = new PeclUuidTimeGenerator(); - $uuid = $generator->generate(); + $bytes = $generator->generate(); + $uuid = Uuid::fromBytes($bytes); - $this->assertSame($this->uuidBinary, $uuid); + /** @var Fields $fields */ + $fields = $uuid->getFields(); + + $this->assertSame(16, strlen($bytes)); + $this->assertSame(Uuid::UUID_TYPE_TIME, $fields->getVersion()); } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 92e8a4c..fe4a80d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -9,5 +9,4 @@ // Ensure floating-point precision is set to 14 (the default) for tests. ini_set('precision', '14'); -require_once __DIR__ . '/../vendor/autoload.php'; // composer autoload -require_once __DIR__ . '/phpstan-bootstrap.php'; +require_once __DIR__ . '/../vendor/autoload.php'; diff --git a/tests/phpstan-bootstrap.php b/tests/phpstan-bootstrap.php deleted file mode 100644 index f7aaf53..0000000 --- a/tests/phpstan-bootstrap.php +++ /dev/null @@ -1,67 +0,0 @@ -getBytes(); - } -} - -if (!function_exists('uuid_generate_md5')) { - /** - * @param string $ns - * @param string $name - * @return string - */ - function uuid_generate_md5($ns, $name) - { - return \Ramsey\Uuid\v3($ns, $name); - } -} - -if (!function_exists('uuid_generate_sha1')) { - /** - * @param string $ns - * @param string $name - * @return string - */ - function uuid_generate_sha1($ns, $name) - { - return \Ramsey\Uuid\v5($ns, $name); - } -} - -if (!defined('UUID_TYPE_TIME')) { - define('UUID_TYPE_TIME', 1); -} - -if (!defined('UUID_TYPE_RANDOM')) { - define('UUID_TYPE_RANDOM', 4); -} diff --git a/tests/static-analysis/stubs.php b/tests/static-analysis/stubs.php new file mode 100644 index 0000000..a8e9047 --- /dev/null +++ b/tests/static-analysis/stubs.php @@ -0,0 +1,33 @@ +