2022-10-13 20:23:22 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Engelsystem\Test\Unit\Controllers;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Engelsystem\Config\Config;
|
|
|
|
use Engelsystem\Test\Unit\Controllers\Stub\ChecksArrivalsAndDeparturesImplementation;
|
|
|
|
use Engelsystem\Test\Unit\TestCase;
|
|
|
|
|
|
|
|
class ChecksArrivalsAndDeparturesTest extends TestCase
|
|
|
|
{
|
2022-12-04 14:08:06 +01:00
|
|
|
private Config $config;
|
|
|
|
|
2022-10-15 23:08:45 +02:00
|
|
|
public function invalidArrivalCombinations(): array
|
2022-10-13 20:23:22 +02:00
|
|
|
{
|
|
|
|
return [
|
2022-10-15 23:08:45 +02:00
|
|
|
[null, null, null, null], # arrival being null
|
|
|
|
[null, null, '2022-01-16', '2022-01-15'], # arrival greater than departure
|
|
|
|
['2022-01-15', null, '2022-01-14', null], # arrival before buildup
|
|
|
|
[null, '2022-01-14', '2022-01-15', null], # arrival after teardown
|
2022-10-13 20:23:22 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-10-15 23:08:45 +02:00
|
|
|
public function invalidDepartureCombinations(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[null, null, '2022-01-16', '2022-01-15'], # departure smaller than arrival
|
|
|
|
['2022-01-15', null, null, '2022-01-14'], # departure before buildup
|
|
|
|
[null, '2022-01-14', null, '2022-01-15'], # departure after teardown
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validArrivalCombinations(): array
|
2022-10-13 20:23:22 +02:00
|
|
|
{
|
|
|
|
return [
|
|
|
|
[null, null, '2022-01-15', '2022-01-15'], # arrival equals departure
|
|
|
|
[null, null, '2022-01-14', '2022-01-15'], # arrival smaller than departure
|
|
|
|
['2022-01-14', null, '2022-01-14', '2022-01-15'], # arrival on buildup
|
|
|
|
['2022-01-13', null, '2022-01-14', '2022-01-15'], # arrival after buildup
|
2022-10-15 23:08:45 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function validDepartureCombinations(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[null, null, '2022-01-15', null], # departure being null
|
|
|
|
[null, null, '2022-01-15', '2022-01-15'], # departure equals arrival
|
|
|
|
[null, null, '2022-01-14', '2022-01-15'], # departure greater than arrival
|
2022-10-13 20:23:22 +02:00
|
|
|
[null, '2022-01-15', '2022-01-14', '2022-01-15'], # departure on teardown
|
|
|
|
[null, '2022-01-16', '2022-01-14', '2022-01-15'], # departure before teardown
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isArrivalDateValid
|
2022-10-15 23:08:45 +02:00
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
|
|
|
|
* @dataProvider invalidArrivalCombinations
|
2022-10-13 20:23:22 +02:00
|
|
|
*/
|
|
|
|
public function testCheckInvalidDatesForArrival($buildup, $teardown, $arrival, $departure)
|
|
|
|
{
|
2022-10-15 23:08:45 +02:00
|
|
|
config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
|
|
|
|
config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
|
2022-10-13 20:23:22 +02:00
|
|
|
|
|
|
|
$check = new ChecksArrivalsAndDeparturesImplementation();
|
|
|
|
$this->assertFalse($check->checkArrival($arrival, $departure));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isDepartureDateValid
|
2022-10-15 23:08:45 +02:00
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
|
|
|
|
* @dataProvider invalidDepartureCombinations
|
2022-10-13 20:23:22 +02:00
|
|
|
*/
|
|
|
|
public function testCheckInvalidDatesForDeparture($buildup, $teardown, $arrival, $departure)
|
|
|
|
{
|
2022-10-15 23:08:45 +02:00
|
|
|
config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
|
|
|
|
config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
|
2022-10-13 20:23:22 +02:00
|
|
|
|
|
|
|
$check = new ChecksArrivalsAndDeparturesImplementation();
|
|
|
|
$this->assertFalse($check->checkDeparture($arrival, $departure));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isArrivalDateValid
|
2022-10-15 23:08:45 +02:00
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
|
|
|
|
* @dataProvider validArrivalCombinations
|
2022-10-13 20:23:22 +02:00
|
|
|
*/
|
|
|
|
public function testCheckValidDatesForArrival($buildup, $teardown, $arrival, $departure)
|
|
|
|
{
|
2022-10-15 23:08:45 +02:00
|
|
|
config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
|
|
|
|
config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
|
2022-10-13 20:23:22 +02:00
|
|
|
|
|
|
|
$check = new ChecksArrivalsAndDeparturesImplementation();
|
|
|
|
$this->assertTrue($check->checkArrival($arrival, $departure));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isDepartureDateValid
|
2022-10-15 23:08:45 +02:00
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::toCarbon
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isBeforeBuildup
|
|
|
|
* @covers \Engelsystem\Controllers\ChecksArrivalsAndDepartures::isAfterTeardown
|
|
|
|
* @dataProvider validDepartureCombinations
|
2022-10-13 20:23:22 +02:00
|
|
|
*/
|
|
|
|
public function testCheckValidDatesForDeparture($buildup, $teardown, $arrival, $departure)
|
|
|
|
{
|
2022-10-15 23:08:45 +02:00
|
|
|
config(['buildup_start' => is_null($buildup) ? null : new Carbon($buildup)]);
|
|
|
|
config(['teardown_end' => is_null($teardown) ? null : new Carbon($teardown)]);
|
2022-10-13 20:23:22 +02:00
|
|
|
|
|
|
|
$check = new ChecksArrivalsAndDeparturesImplementation();
|
|
|
|
$this->assertTrue($check->checkDeparture($arrival, $departure));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUp(): void
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
$this->config = new Config();
|
|
|
|
$this->app->instance('config', $this->config);
|
|
|
|
$this->app->instance(Config::class, $this->config);
|
|
|
|
}
|
|
|
|
}
|