Files
gorilla/tests/Unit/InputEntityTest.php
2026-01-12 12:37:16 +01:00

228 lines
5.7 KiB
PHP

<?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);
}
}