mirror of
https://github.com/archtechx/virtualcolumn.git
synced 2025-12-12 10:54:04 +00:00
Move EncryptedCast class to VirtualColumnTest
This commit is contained in:
parent
86b5384447
commit
89ce8851ca
2 changed files with 25 additions and 31 deletions
|
|
@ -2,11 +2,12 @@
|
||||||
|
|
||||||
namespace Stancl\VirtualColumn\Tests;
|
namespace Stancl\VirtualColumn\Tests;
|
||||||
|
|
||||||
use Stancl\VirtualColumn\Tests\Etc\EncryptedCast;
|
|
||||||
use Orchestra\Testbench\TestCase;
|
use Orchestra\Testbench\TestCase;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Crypt;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Stancl\VirtualColumn\VirtualColumn;
|
use Stancl\VirtualColumn\VirtualColumn;
|
||||||
|
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
||||||
|
|
||||||
class VirtualColumnTest extends TestCase
|
class VirtualColumnTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
@ -185,3 +186,26 @@ class FooModel extends Model
|
||||||
return 'virtual';
|
return 'virtual';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class EncryptedCast implements CastsAttributes
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Cast the given value.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $attributes
|
||||||
|
*/
|
||||||
|
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
|
||||||
|
{
|
||||||
|
return Crypt::decryptString($value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prepare the given value for storage.
|
||||||
|
*
|
||||||
|
* @param array<string, mixed> $attributes
|
||||||
|
*/
|
||||||
|
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
|
||||||
|
{
|
||||||
|
return Crypt::encryptString($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
namespace Stancl\VirtualColumn\Tests\Etc;
|
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Crypt;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
|
|
||||||
|
|
||||||
class EncryptedCast implements CastsAttributes
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Cast the given value.
|
|
||||||
*
|
|
||||||
* @param array<string, mixed> $attributes
|
|
||||||
*/
|
|
||||||
public function get(Model $model, string $key, mixed $value, array $attributes): mixed
|
|
||||||
{
|
|
||||||
return Crypt::decryptString($value);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Prepare the given value for storage.
|
|
||||||
*
|
|
||||||
* @param array<string, mixed> $attributes
|
|
||||||
*/
|
|
||||||
public function set(Model $model, string $key, mixed $value, array $attributes): mixed
|
|
||||||
{
|
|
||||||
return Crypt::encryptString($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue