refactor: replace custom CRM with Monica fork
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
Some checks failed
Build & Push Monica Image to Gitea Registry / build-and-push (push) Failing after 9s
This commit is contained in:
121
tests/Unit/Services/BaseServiceTest.php
Normal file
121
tests/Unit/Services/BaseServiceTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Unit\Services;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Tests\TestCase;
|
||||
use App\Services\BaseService;
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
|
||||
class BaseServiceTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/** @test */
|
||||
public function it_returns_an_empty_rule_array(): void
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass(BaseService::class);
|
||||
|
||||
$this->assertIsArray(
|
||||
$stub->rules()
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_validates_rules(): void
|
||||
{
|
||||
$rules = [
|
||||
'street' => 'nullable|string|max:255',
|
||||
];
|
||||
|
||||
$stub = $this->getMockForAbstractClass(BaseService::class);
|
||||
$stub->rules([$rules]);
|
||||
|
||||
$this->assertTrue(
|
||||
$stub->validate([
|
||||
'street' => 'la rue du bonheur',
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_returns_null_or_the_actual_value(): void
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass(BaseService::class);
|
||||
$array = [
|
||||
'value' => 'this',
|
||||
];
|
||||
|
||||
$this->assertEquals(
|
||||
'this',
|
||||
$stub->nullOrValue($array, 'value')
|
||||
);
|
||||
|
||||
$array = [
|
||||
'otherValue' => '',
|
||||
];
|
||||
|
||||
$this->assertNull(
|
||||
$stub->nullOrValue($array, 'otherValue')
|
||||
);
|
||||
|
||||
$array = [];
|
||||
|
||||
$this->assertNull(
|
||||
$stub->nullOrValue($array, 'value')
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_returns_null_or_the_actual_date(): void
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass(BaseService::class);
|
||||
$array = [
|
||||
'value' => '1990-01-01',
|
||||
];
|
||||
|
||||
$this->assertInstanceOf(
|
||||
Carbon::class,
|
||||
$stub->nullOrDate($array, 'value')
|
||||
);
|
||||
|
||||
$array = [
|
||||
'otherValue' => '',
|
||||
];
|
||||
|
||||
$this->assertNull(
|
||||
$stub->nullOrDate($array, 'otherValue')
|
||||
);
|
||||
|
||||
$array = [];
|
||||
|
||||
$this->assertNull(
|
||||
$stub->nullOrDate($array, 'value')
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function it_returns_the_default_value_or_the_given_value(): void
|
||||
{
|
||||
$stub = $this->getMockForAbstractClass(BaseService::class);
|
||||
$array = [
|
||||
'value' => true,
|
||||
];
|
||||
|
||||
$this->assertTrue(
|
||||
$stub->valueOrFalse($array, 'value')
|
||||
);
|
||||
|
||||
$array = [
|
||||
'value' => false,
|
||||
];
|
||||
|
||||
$this->assertFalse(
|
||||
$stub->valueOrFalse($array, 'value')
|
||||
);
|
||||
|
||||
$this->assertFalse(
|
||||
$stub->valueOrFalse([], 'value')
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user