-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
1 parent
fd69ce1
commit 86aba7e
Showing
4 changed files
with
58 additions
and
2 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
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Datasets; | ||
|
||
use Illuminate\Database\Eloquent\Model; | ||
use WendellAdriel\Virtue\Models\Attributes\Cast; | ||
use WendellAdriel\Virtue\Models\Attributes\Database; | ||
use WendellAdriel\Virtue\Models\Attributes\Fillable; | ||
use WendellAdriel\Virtue\Models\Attributes\Hidden; | ||
use WendellAdriel\Virtue\Models\Concerns\Virtue; | ||
|
||
#[Fillable([ | ||
'name', | ||
'price', | ||
'random_number', | ||
'another_random_number', | ||
'expires_at', | ||
])] | ||
#[Hidden([ | ||
'random_number', | ||
'another_random_number', | ||
])] | ||
#[Cast(field: 'price', type: 'float')] | ||
#[Cast(field: 'random_number', type: 'int')] | ||
#[Cast(field: 'another_random_number', type: 'int')] | ||
#[Cast(field: 'expires_at', type: 'immutable_datetime')] | ||
#[Database(table: 'products')] | ||
final class ProductHidden extends Model | ||
{ | ||
use Virtue; | ||
} |
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
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tests\Datasets\ProductHidden; | ||
|
||
it('set properties to hidden', function () { | ||
$product = ProductHidden::create([ | ||
'name' => 'Product 1', | ||
'price' => '10.99', | ||
'random_number' => '123', | ||
'another_random_number' => '123', | ||
'expires_at' => '2023-12-31 23:59:59', | ||
]); | ||
|
||
expect($product->name)->toBe('Product 1') | ||
->and($product->price)->toBe(10.99) | ||
->and($product->random_number)->toBe(123) | ||
->and($product->expires_at)->toBeInstanceOf(Carbon\CarbonImmutable::class) | ||
->and($product->expires_at->format('Y-m-d H:i:s'))->toBe('2023-12-31 23:59:59') | ||
->and($product->toArray())->not->toHaveKey('random_number') | ||
->and($product->toArray())->not->toHaveKey('another_random_number'); | ||
}); |