request = $this->makeEmpty(Request::class, [ 'getParsedBody' => [ 'workingDay' => self::EXISTING_DATE, 'workingTime' => self::EXISTING_INTERVAL, ], ]); } /** * @throws NotDatabasesException * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface * @throws Exception */ public function testConstructWithNonDatabase(): void { $this->container = $this->makeEmpty(ContainerInterface::class, [ 'has' => false, ]); $this->expectException(NotDatabasesException::class); new WorkingHoursController($this->container); } /** * @return array>> */ public function valideFilterDataProvider(): array { return [ [ [], ], [ [ 'start-date' => '2020-03-01', 'end-date' => '2020-03-31', ], ], [ [ 'start-date' => '2020-03-01', ], ], [ [ 'end-date' => '2020-03-31', ], ], ]; } /** * @param array $queryParams * * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ #[DataProvider('valideFilterDataProvider')] public function testBrowseWithValideParameter(array $queryParams): void { $this->request = $this->makeEmpty(Request::class, [ 'getQueryParams' => $queryParams, ]); $controller = new WorkingHoursController($this->container); $response = $controller->browse($this->request, $this->response, []); $this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode()); $this->assertNotEmpty($response->getBody()->getContents()); } /** * @return array>> */ public function invalideFilterDataProvider(): array { return [ [ [ 'start-date' => '', 'end-date' => '', ], ], [ [ 'start-date' => '', ], ], [ [ 'end-date' => '', ], ], [ [ 'start-date' => '2020-03-01', 'end-date' => '', ], ], [ [ 'start-date' => '', 'end-date' => '2020-03-31', ], ], // [ [ 'start-date' => '2020-03-00', 'end-date' => '2020-04-31', ], ], [ [ 'start-date' => '2020-03-00', ], ], [ [ 'end-date' => '2020-04-31', ], ], [ [ 'start-date' => '2020-03-01', 'end-date' => '2020-04-31', ], ], [ [ 'start-date' => '2020-03-00', 'end-date' => '2020-03-31', ], ], // [ [ 'start-date' => '2020-03', 'end-date' => '2020-03', ], ], [ [ 'start-date' => '2020-03', ], ], [ [ 'end-date' => '2020-03', ], ], [ [ 'start-date' => '2020-03-01', 'end-date' => '2020-03', ], ], [ [ 'start-date' => '2020-03', 'end-date' => '2020-03-31', ], ], // [ [ 'start-date' => '2020', 'end-date' => '2020', ], ], [ [ 'start-date' => '2020', ], ], [ [ 'end-date' => '2020', ], ], [ [ 'start-date' => '2020-03-01', 'end-date' => '2020', ], ], [ [ 'start-date' => '2020', 'end-date' => '2020-03-31', ], ], ]; } /** * @param array $queryParams * * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ #[DataProvider('invalideFilterDataProvider')] public function testBrowseWithInvalideParameter(array $queryParams): void { $this->request = $this->makeEmpty(Request::class, [ 'getQueryParams' => $queryParams, ]); $controller = new WorkingHoursController($this->container); $this->expectException(HttpBadRequestException::class); $controller->browse($this->request, $this->response, []); } /** * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ public function testUpdateExistRecord(): void { $controller = new WorkingHoursController($this->container); $response = $controller->update($this->request, $this->response, [ 'id' => self::EXISTING_DATE, ]); $this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode()); $this->assertNotEmpty($response->getBody()->getContents()); } /** * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ public function testUpdateNotExistRecord(): void { $controller = new WorkingHoursController($this->container); $this->expectException(HttpNotFoundException::class); $controller->update($this->request, $this->response, [ 'id' => self::NEW_DATE, ]); } /** * @return string[][] */ public function invalidCreatDataProvider(): array { return [ [ self::NEW_DATE, '07:59', ], [ '2020-13-33', self::NEW_INTERVAL, ], ]; } /** * @param string $date * @param string $time * * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ #[DataProvider('invalidCreatDataProvider')] public function testCreatInvalidData(string $date, string $time): void { $this->request = $this->makeEmpty(Request::class, [ 'getParsedBody' => [ 'workingDay' => $date, 'workingTime' => $time, ], ]); $controller = new WorkingHoursController($this->container); $this->expectException(HttpBadRequestException::class); $controller->creat($this->request, $this->response, []); } /** * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ public function testCreatNewRecord(): void { $this->request = $this->makeEmpty(Request::class, [ 'getParsedBody' => [ 'workingDay' => self::NEW_DATE, 'workingTime' => self::NEW_INTERVAL, ], ]); $controller = new WorkingHoursController($this->container); $response = $controller->creat($this->request, $this->response, []); $this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode()); $this->assertNotEmpty($response->getBody()->getContents()); } /** * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ public function testCreatExistRecord(): void { $this->request = $this->makeEmpty(Request::class, [ 'getParsedBody' => [ 'workingDay' => self::EXISTING_DATE, 'workingTime' => self::EXISTING_INTERVAL, ], ]); $controller = new WorkingHoursController($this->container); $this->expectException(HttpConflictRequestException::class); $controller->creat($this->request, $this->response, []); } /** * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ public function testReadExistRecord(): void { $controller = new WorkingHoursController($this->container); $response = $controller->read($this->request, $this->response, [ 'id' => self::EXISTING_DATE, ]); $this->assertEquals(self::FICTIONAL_STATUS_CODE, $response->getStatusCode()); $this->assertNotEmpty($response->getBody()->getContents()); } /** * @throws ContainerExceptionInterface * @throws NotDatabasesException * @throws NotFoundExceptionInterface * @throws Exception */ public function testReadNotExistRecord(): void { $controller = new WorkingHoursController($this->container); $this->expectException(HttpNotFoundException::class); $controller->read($this->request, $this->response, [ 'id' => self::NEW_DATE, ]); } }