mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-12 02:02:15 +01:00
Added more imports
This commit is contained in:
66
tests/Unit/Rules/ColorRuleTest.php
Normal file
66
tests/Unit/Rules/ColorRuleTest.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
use App\Rules\ColorRule;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ColorRuleTest extends TestCase
|
||||
{
|
||||
public function test_validation_passes_if_value_is_valid_color(): void
|
||||
{
|
||||
// Arrange
|
||||
$validator = Validator::make([
|
||||
'color' => '#ef5350',
|
||||
], [
|
||||
'color' => [new ColorRule()],
|
||||
]);
|
||||
|
||||
// Act
|
||||
$isValid = $validator->passes();
|
||||
$messages = $validator->messages()->toArray();
|
||||
|
||||
// Assert
|
||||
$this->assertTrue($isValid);
|
||||
$this->assertArrayNotHasKey('color', $messages);
|
||||
}
|
||||
|
||||
public function test_validation_fails_if_value_is_not_a_string(): void
|
||||
{
|
||||
// Arrange
|
||||
$validator = Validator::make([
|
||||
'color' => true,
|
||||
], [
|
||||
'color' => [new ColorRule()],
|
||||
]);
|
||||
|
||||
// Act
|
||||
$isValid = $validator->passes();
|
||||
$messages = $validator->messages()->toArray();
|
||||
|
||||
// Assert
|
||||
$this->assertFalse($isValid);
|
||||
$this->assertEquals('The color field must be a string.', $messages['color'][0]);
|
||||
}
|
||||
|
||||
public function test_validation_fails_if_value_is_not_a_valid_color(): void
|
||||
{
|
||||
// Arrange
|
||||
$validator = Validator::make([
|
||||
'color' => 'rgb(0,0,0)',
|
||||
], [
|
||||
'color' => [new ColorRule()],
|
||||
]);
|
||||
|
||||
// Act
|
||||
$isValid = $validator->passes();
|
||||
$messages = $validator->messages()->toArray();
|
||||
|
||||
// Assert
|
||||
$this->assertFalse($isValid);
|
||||
$this->assertEquals('The color field must be a valid color.', $messages['color'][0]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user