Skip to content

Commit

Permalink
Laravel 10.x Compatibility (#122)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Dyrynda <michael@dyrynda.com.au>
  • Loading branch information
laravel-shift and michaeldyrynda authored Feb 16, 2023
1 parent ce78fce commit 1034d77
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 47 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [8.1, 8.0, 7.4, 7.3]
laravel: [^8.0, ^9.0]
php: [8.2, 8.1]
laravel: [10.0]
exclude:
- php: 7.3
laravel: '^9.0'
- php: 7.4
laravel: '^9.0'

name: P${{ matrix.php }} - L${{ matrix.laravel }}

Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ Take a look at [laravel-efficient-uuid](https://github.com/michaeldyrynda/larave

If you require compatibility with `ramsey/uuid` >= 4.1, please use version >= 6.2.0 of this package.

As of version 6.2.0, this package supports only UUID versions 1 (`uuid1`), 4 (`uuid4`), 6 (`uuid6` - ordered) and `ordered` ([Laravels ordered UUID v4](https://laravel.com/docs/master/helpers#method-str-ordered-uuid)).
As of version 6.2.0, this package supports only UUID versions 1 (`uuid1`), 4 (`uuid4`), 6 (`uuid6` - ordered) and `ordered` ([Laravel's ordered UUID v4](https://laravel.com/docs/master/helpers#method-str-ordered-uuid)).

As of version 7.0.0, this package supports Laravel 10 and PHP 8.1 as minimum.

## Code Samples

Expand Down Expand Up @@ -79,7 +81,10 @@ class Post extends Model
{
use GeneratesUuid;

protected $uuidVersion = 'uuid5';
public function uuidVersion(): string
{
return 'uuid5';
}
}
```

Expand Down
20 changes: 10 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@
}
],
"require": {
"php": "^7.3|^8.0",
"illuminate/database": "^8.12|^9.0",
"illuminate/events": "^8.12|^9.0",
"illuminate/support": "^8.12|^9.0",
"ramsey/uuid": "^4.1"
"php": "^8.1",
"illuminate/database": "^10.0",
"illuminate/events": "^10.0",
"illuminate/support": "^10.0",
"ramsey/uuid": "^4.7"
},
"autoload": {
"psr-4": {
"Dyrynda\\Database\\Support\\": "src/"
}
},
"require-dev": {
"dyrynda/laravel-efficient-uuid": "^4.5.2",
"laravel/legacy-factories": "^1.0.4",
"orchestra/testbench": "^6.0|^7.0",
"phpunit/phpunit": "^9.3"
"dyrynda/laravel-efficient-uuid": "^5.0",
"laravel/legacy-factories": "^1.3",
"orchestra/testbench": "^8.0",
"phpunit/phpunit": "^9.6.0 || ^10.0.7"
},
"autoload-dev": {
"psr-4": {
Expand All @@ -48,7 +48,7 @@
},
"extra": {
"branch-alias": {
"dev-main": "6.x-dev"
"dev-main": "7.x-dev"
}
}
}
13 changes: 1 addition & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
Expand Down
13 changes: 11 additions & 2 deletions src/GeneratesUuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,24 @@ public function resolveUuid(): UuidInterface
return call_user_func([Uuid::class, $this->resolveUuidVersion()]);
}

public function uuidVersion(): string
{
return 'uuid4';
}

/**
* Resolve the UUID version to use when setting the UUID value. Default to uuid4.
*
* @return string
*/
public function resolveUuidVersion(): string
{
if (property_exists($this, 'uuidVersion') && in_array($this->uuidVersion, $this->uuidVersions)) {
return $this->uuidVersion === 'ordered' ? 'uuid6' : $this->uuidVersion;
if (($uuidVersion = $this->uuidVersion()) === 'ordered') {
$uuidVersion = 'uuid6';
}

if (in_array($uuidVersion, $this->uuidVersions)) {
return $uuidVersion;
}

return 'uuid4';
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public function it_handles_queries_with_multiple_uuid_columns()
});
}

public function factoriesWithUuidProvider(): array
public static function factoriesWithUuidProvider(): array
{
return [
'regular uuid' => [Post::class, 'uuid'],
Expand All @@ -293,7 +293,7 @@ public function factoriesWithUuidProvider(): array
];
}

public function uuidVersionsProvider(): array
public static function uuidVersionsProvider(): array
{
return [
'uuid1' => [Uuid1Post::class, Uuid::UUID_TYPE_TIME],
Expand Down
5 changes: 4 additions & 1 deletion tests/Fixtures/OrderedPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@

class OrderedPost extends Model
{
protected $uuidVersion = 'ordered';
public function uuidVersion(): string
{
return 'ordered';
}
}
5 changes: 4 additions & 1 deletion tests/Fixtures/Uuid1Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ class Uuid1Post extends Model
{
use GeneratesUuid;

protected $uuidVersion = 'uuid1';
public function uuidVersion(): string
{
return 'uuid1';
}
}
5 changes: 4 additions & 1 deletion tests/Fixtures/Uuid4Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ class Uuid4Post extends Model
{
use GeneratesUuid;

protected $uuidVersion = 'uuid4';
public function uuidVersion(): string
{
return 'uuid4';
}
}
5 changes: 4 additions & 1 deletion tests/Fixtures/Uuid6Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ class Uuid6Post extends Model
{
use GeneratesUuid;

protected $uuidVersion = 'uuid6';
public function uuidVersion(): string
{
return 'uuid6';
}
}
15 changes: 6 additions & 9 deletions tests/Unit/UuidResolversTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@

class UuidResolversTest extends TestCase
{
/**
* @see \Tests\Unit\UuidResolversTest::it_handles_uuid_versions
*
* @return array
*/
public function provider_for_it_handles_uuid_versions()
public static function provider_for_it_handles_uuid_versions(): array
{
return [
['uuid1', 'uuid1'],
Expand All @@ -29,13 +24,15 @@ public function provider_for_it_handles_uuid_versions()
* @param string $version
* @param string $resolved
*
* @dataProvider \Tests\Unit\UuidResolversTest::provider_for_it_handles_uuid_versions
* @dataProvider provider_for_it_handles_uuid_versions
*/
public function it_handles_uuid_versions($version, $resolved)
{
/* @var \Dyrynda\Database\Support\GeneratesUuid $generator */
$generator = $this->getMockForTrait(GeneratesUuid::class);
$generator->uuidVersion = $version;
$generator = $this->getMockForTrait(GeneratesUuid::class, mockedMethods: [
'uuidVersion',
]);
$generator->method('uuidVersion')->willReturn($version);

$this->assertSame($resolved, $generator->resolveUuidVersion());
}
Expand Down

0 comments on commit 1034d77

Please sign in to comment.