-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
153 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
vendor/ | ||
composer.lock | ||
.DS_Store | ||
.phpunit.cache/ | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,37 @@ | ||
{ | ||
"name": "kfoobar/laravel-uuid", | ||
"description": "Eloquent UUID trait for Laravel", | ||
"type": "plugin", | ||
"description": "UUID Trait for Eloquent Models in Laravel", | ||
"type": "library", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "KFoobar", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "dev", | ||
"prefer-stable": true, | ||
"require": { | ||
"php": "^7.3|^8.0", | ||
"illuminate/database": ">=5.5", | ||
"illuminate/support": ">=5.5" | ||
"ext-json": "*", | ||
"illuminate/database": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0", | ||
"illuminate/support": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0" | ||
}, | ||
"require-dev": { | ||
"orchestra/testbench": "^8.11", | ||
"phpunit/phpunit": "^10.1" | ||
}, | ||
"minimum-stability": "stable", | ||
"prefer-stable": true, | ||
"autoload": { | ||
"psr-4": { | ||
"KFoobar\\Uuid\\": "src/" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"KFoobar\\Uuid\\Test\\": "tests/" | ||
} | ||
}, | ||
"scripts": { | ||
"test": "vendor/bin/phpunit" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
backupGlobals="false" | ||
beStrictAboutTestsThatDoNotTestAnything="false" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" | ||
cacheDirectory=".phpunit.cache" | ||
backupStaticProperties="false"> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory suffix="Test.php">./tests/Unit</directory> | ||
</testsuite> | ||
</testsuites> | ||
<php> | ||
<env name="APP_ENV" value="testing"/> | ||
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/> | ||
<env name="DB_CONNECTION" value="sqlite"/> | ||
<env name="QUEUE_CONNECTION" value="array"/> | ||
<env name="DB_DATABASE" value=":memory:"/> | ||
</php> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace KFoobar\Uuid\Test\Fixtures; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use KFoobar\Uuid\Traits\HasUuid; | ||
|
||
class Post extends Model | ||
{ | ||
use HasUuid; | ||
|
||
/** | ||
* The attributes that aren't mass assignable. | ||
* | ||
* @var array | ||
*/ | ||
protected $guarded = ['id']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace KFoobar\Uuid\Test\Unit; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Support\Facades\Schema; | ||
use KFoobar\Uuid\Test\Fixtures\Post; | ||
use KFoobar\Uuid\Test\Unit\TestCase; | ||
|
||
class HasUuidTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected $regex = '/^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i'; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
Schema::create('posts', function (Blueprint $table) { | ||
$table->id('id'); | ||
$table->uuid('uuid'); | ||
$table->string('heading')->nullable(); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function testModelIsModel(): void | ||
{ | ||
$post = new Post; | ||
|
||
$this->assertInstanceOf(Model::class, $post); | ||
} | ||
|
||
public function testCreateModel() | ||
{ | ||
$post = Post::create(['heading' => 'Lorem ipsum dolor']); | ||
|
||
$this->assertMatchesRegularExpression($this->regex, $post->uuid); | ||
|
||
$post = Post::first(); | ||
|
||
$this->assertMatchesRegularExpression($this->regex, $post->uuid); | ||
} | ||
|
||
public function testUpdateModel() | ||
{ | ||
$post = Post::create(['heading' => 'Lorem ipsum dolor']); | ||
|
||
$firstUuid = $post->uuid; | ||
|
||
$post->update([ | ||
'heading' => 'Dolor ipsum lorem', | ||
]); | ||
|
||
$secondUuid = $post->uuid; | ||
|
||
$this->assertEquals($firstUuid, $secondUuid); | ||
} | ||
|
||
public function testSaveModelWithEmptyUuid() | ||
{ | ||
$post = Post::create(['heading' => 'Lorem ipsum dolor']); | ||
|
||
$post->uuid = ''; | ||
$post->save(); | ||
|
||
$post = Post::first(); | ||
|
||
$this->assertNotEmpty($post->uuid); | ||
$this->assertNotNull($post->uuid); | ||
$this->assertMatchesRegularExpression($this->regex, $post->uuid); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace KFoobar\Uuid\Test\Unit; | ||
|
||
use Orchestra\Testbench\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
|
||
protected function defineEnvironment($app) | ||
{ | ||
$app['config']->set('database.default', 'testing'); | ||
} | ||
} |