get($this->buildUrl('CZ', $startDate, $minutesDuration, $calculateWithWorkingDays, '08:00', '16:00')); $response->assertStatus(200); $response->assertJson([ 'estimation_date' => $result, ]); } /** * @return array> */ public static function estimationDataProvider(): array { return [ [false, '2024-01-03 08:00', 60, '2024-01-03 09:00:00'], // 1H [false, '2024-01-03 08:00', 60 * 9 + 1, '2024-01-04 09:01:00'], // 1D, 1H, 1M [false, '2024-01-01 08:00', 1, '2024-01-01 08:01:00'], // 1M [false, '2024-01-01 08:00', 60 * 8, '2024-01-01 16:00:00'], // 1 working day [true, '2024-01-05 08:00', 60 * 8 * 2, '2024-01-08 16:00:00'], // 1 working day, 6,7 is weekend [true, '2024-01-05 08:00', 60 * 8, '2024-01-05 16:00:00'], // 1 working day without weekend*/ [false, '2024-01-05 15:59', 1, '2024-01-05 16:00:00'], // 1 minute before ending workday [false, '2024-01-05 15:59', 2, '2024-01-06 08:01:00'], // 2 minutes before ending workday [true, '2024-01-05 15:59', 2, '2024-01-08 08:01:00'], // 1 minute before ending workday, with weekend [true, '2024-01-03 08:00', 60 * 9 + 1, '2024-01-04 09:01:00'], // 1D, 1H, 1M [true, '2024-01-06 08:00', 60, '2024-01-08 09:00:00'] // 1 H, over weekend ]; } #[DataProvider('invalidArgumentsDataProvider')] public function testInvalidArguments(string $countryCode, string $startDate, int $minutesDuration, bool $calculateWithWorkingDays, string $startWork, string $endWork): void { $url = $this->buildUrl($countryCode, $startDate, $minutesDuration, $calculateWithWorkingDays, $startWork, $endWork); $response = $this->get($url); $response->assertStatus(400); } /** * @return array> */ public static function invalidArgumentsDataProvider(): array { return [ ['ZZ', '2024-01-03 08:00', 30, false, '08:00', '16:00'], // bad country code ['FOO', '2024-01-03 08:00', 30, false, '08:00', '16:00'], // bad country code ['CZ', '2024-01-03 00:00', 30, false, '08:00', '16:00'], // missing seconds ['CZ', '2024-01-03 08:00', -1000, false, '08:00', '16:00'], // negative duration ['CZ', '2024-01-03 08:00', 30, false, '08:0?', '16:00'], // ? in start work time ['CZ', '2024-01-03 08:00', 30, false, '08:00', '16:X0'], // X in end work time ['CZ', '2024-01-03 08:00', 30, false, '08:00', 'FOO:00'], // FOO in end work time ['CZ', '2024-01-03 08:00', 30, false, '09:00', '16:00'], // 08:00 is before workday ['CZ', '2024-01-03 11:00', 30, false, '09:00', '10:00'], // 11 is after workday ['CZ', '2024-01-03 09:00', 30, false, '09:00', '08:00'], // 09:00 > 08:00 ['CZ', '2024-01-03 08:00', 30, false, '09:00', '09:00'], // equal startDate and endDate ]; } private function buildUrl(string $countryCode, string $startDate, int $minutesDuration, bool $calculateWithWorkingDays, string $startWork, string $endWork): string { $uri = []; $uri[] = "api"; $uri[] = "v1"; $uri[] = "task-estimation"; $uri[] = $countryCode; $uri[] = $startDate; $uri[] = $minutesDuration; $uri[] = (($calculateWithWorkingDays === false) ? '0' : '1'); $uri[] = $startWork; $uri[] = $endWork; return implode('/', array_map(function ($part) { return rawurlencode((string) $part); }, $uri)); } }