This commit is contained in:
johny
2026-01-12 12:37:16 +01:00
commit 516e51e0e9
76 changed files with 11962 additions and 0 deletions

View File

@@ -0,0 +1,61 @@
<?php
namespace Tests\Unit;
use App\Service\Entities\FailureReport;
use App\Service\Entities\InputEntity;
use PHPUnit\Framework\TestCase;
class FailureReportTest extends TestCase
{
public function testPriorityIsKrytyczny() {
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test Bardzo pilne zgłoszenie',
]);
$inspection = new FailureReport($inputEntity);
$this->assertEquals('krytyczny', $inspection->priority->value);
}
public function testPriorityIsWysoki() {
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test pilne zgłoszenie',
]);
$inspection = new FailureReport($inputEntity);
$this->assertEquals('wysoki', $inspection->priority->value);
}
public function testPriorityIsNormalny() {
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test zwykłego zgłoszenia',
]);
$inspection = new FailureReport($inputEntity);
$this->assertEquals('normalny', $inspection->priority->value);
}
public function testStatusIsTermin()
{
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-01',
]);
$inspection = new FailureReport($inputEntity);
$this->assertEquals('termin', $inspection->status->value);
}
public function testStatusIsNowy()
{
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test',
'dueDate' => '',
]);
$inspection = new FailureReport($inputEntity);
$this->assertEquals('nowy', $inspection->status->value);
}
}

View File

@@ -0,0 +1,227 @@
<?php
namespace Tests\Unit;
use App\Service\Entities\InputEntity;
use PHPUnit\Framework\TestCase;
class InputEntityTest extends TestCase
{
public function testValidatesCorrectNumber()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '',
];
$entity = new InputEntity($data);
$this->assertEquals(1, $entity->number);
}
public function testThrowsExceptionOnInvalidNumber()
{
$data = [
'number' => 'abc',
'description' => 'Test',
'dueDate' => '',
'phone' => '',
];
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid number');
new InputEntity($data);
}
public function testThrowsExceptionOnMissedNumberField()
{
$data = [
'description' => 'Test',
'dueDate' => '',
'phone' => '',
];
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid number');
new InputEntity($data);
}
public function testValidatesCorrectDescription()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '',
];
$entity = new InputEntity($data);
$this->assertEquals('Test', $entity->description);
}
public function testThrowsExceptionOnEmptyDescription()
{
$data = [
'number' => 1,
'description' => '',
'dueDate' => '',
'phone' => '',
];
$this->expectException(\InvalidArgumentException::class);
new InputEntity($data);
}
public function testThrowsExceptionOnMissedDescriptionField()
{
$data = [
'number' => 1,
'dueDate' => '',
'phone' => '',
];
$this->expectException(\InvalidArgumentException::class);
new InputEntity($data);
}
public function testValidatesCorrectDate()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-01',
'phone' => '',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('2020-01-01', $inputEntity->date->format('Y-m-d'));
}
public function testValidatesCorrectDateHour()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-01 12:00',
'phone' => '',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('2020-01-01 12:00', $inputEntity->date->format('Y-m-d H:i'));
}
public function testValidatesCorrectDateHourSecond()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-01 12:00:01',
'phone' => '',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('2020-01-01 12:00:01', $inputEntity->date->format('Y-m-d H:i:s'));
}
public function testAllowNullDate()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => null,
'phone' => '',
];
$inputEntity = new InputEntity($data);
$this->assertNull($inputEntity->date);
}
public function testAllowEmptyDate()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '',
];
$inputEntity = new InputEntity($data);
$this->assertNull($inputEntity->date);
}
public function testThrowsExceptionOnInvalidDate()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-01 12:00:aa',
'phone' => '',
];
$this->expectException(\InvalidArgumentException::class);
new InputEntity($data);
}
public function testValidatesCorrectPhone()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '123456789',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('123456789', $inputEntity->phone);
}
public function testValidatesCorrectPhoneWithDashes()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '123-456-789',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('123-456-789', $inputEntity->phone);
}
public function testValidatesCorrectPhoneWithSpaces()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '123 456 789',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('123 456 789', $inputEntity->phone);
}
public function testValidatesCorrectPhoneWithContryCode()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '+48 123 456 789',
];
$inputEntity = new InputEntity($data);
$this->assertEquals('+48 123 456 789', $inputEntity->phone);
}
public function testThrowsExceptionOnInvalidPhone()
{
$data = [
'number' => 1,
'description' => 'Test',
'dueDate' => '',
'phone' => '4',
];
$this->expectException(\InvalidArgumentException::class);
new InputEntity($data);
}
}

View File

@@ -0,0 +1,61 @@
<?php
namespace Tests\Unit;
use App\Service\Entities\InputEntity;
use App\Service\Entities\Inspection;
use Tests\TestCase;
class InspectionTest extends TestCase
{
public function testStatusIsNowyWhenDateIsEmpty()
{
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test',
'dueDate' => '',
]);
$inspection = new Inspection($inputEntity);
$this->assertEquals('nowy', $inspection->status->value);
}
public function testStatusIsZaplanowanyWhenDateIsNotEmpty()
{
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-01',
]);
$inspection = new Inspection($inputEntity);
$this->assertEquals('zaplanowany', $inspection->status->value);
}
public function testThereIsWeekOfYearWhenDateIsSet()
{
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test',
'dueDate' => '2020-01-07',
]);
$inspection = new Inspection($inputEntity);
$this->assertNotNull($inspection->serviceWeek);
$this->assertEquals(2, $inspection->serviceWeek);
}
public function testThereIsNoWeekOfYearWhenDateIsNotSet()
{
$inputEntity = new InputEntity([
'number' => 1,
'description' => 'Test',
'dueDate' => '',
]);
$inspection = new Inspection($inputEntity);
$this->assertNull($inspection->serviceWeek);
}
}