container = $this->makeEmpty(ContainerInterface::class, [ 'has' => true, 'get' => new PDO('pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass') ]); $this->request = $this->makeEmpty(Request::class, [ 'getParsedBody' => [ 'workingDay' => self::EXISTING_DATE, 'workingTime' => self::EXISTING_INTERVAL, ] ]); $this->response = $this->makeEmpty(Response::class, [ 'getBody' => $this->makeEmpty(StreamInterface::class, [ 'write' => function (mixed $data) { $this->assertIsString($data); $this->assertJson($data); }, ]), 'withHeader' => $this->makeEmpty(Response::class, [ 'withStatus' => $this->makeEmpty(Response::class), ]), ]); } /** * @throws NotDatabasesException * @throws Exception */ public function testConstructWithNonDatabase(): void { $this->container = $this->makeEmpty(ContainerInterface::class, [ 'has' => false ]); $this->expectException(NotDatabasesException::class); new WorkingHoursController($this->container); } /** * @throws NotDatabasesException * @throws Exception */ public function testBrowse(): void { $controller = new WorkingHoursController($this->container); $response = $controller->browse($this->request, $this->response, []); $this->assertInstanceOf(Response::class, $response); } /** * @throws NotDatabasesException * @throws HttpBadRequestException * @throws HttpNotFoundException */ public function testUpdateExistRecord(): void { $controller = new WorkingHoursController($this->container); $response = $controller->update($this->request, $this->response, [ 'id' => self::EXISTING_DATE ]); $this->assertInstanceOf(Response::class, $response); } /** * @throws NotDatabasesException * @throws HttpBadRequestException * @throws HttpNotFoundException */ 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 invalidDataProvider(): array { return [ [ self::NEW_DATE, '07:59' ], [ '2020-13-33', self::NEW_INTERVAL ], ]; } /** * @param string $date * @param string $time * * @dataProvider invalidDataProvider * * @throws HttpBadRequestException * @throws HttpConflictRequestException * @throws HttpInternalServerErrorException * @throws NotDatabasesException * @throws Exception */ 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 HttpBadRequestException * @throws NotDatabasesException * @throws HttpInternalServerErrorException * @throws HttpConflictRequestException * @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->assertInstanceOf(Response::class, $response); } /** * @throws HttpBadRequestException * @throws HttpConflictRequestException * @throws HttpInternalServerErrorException * @throws NotDatabasesException * @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 HttpInternalServerErrorException * @throws HttpNotFoundException * @throws NotDatabasesException */ public function testReadExistRecord(): void { $controller = new WorkingHoursController($this->container); $response = $controller->read($this->request, $this->response, [ 'id' => self::EXISTING_DATE ]); $this->assertInstanceOf(Response::class, $response); } /** * @throws HttpInternalServerErrorException * @throws HttpNotFoundException * @throws NotDatabasesException */ public function testReadNotExistRecord(): void { $controller = new WorkingHoursController($this->container); $this->expectException(HttpNotFoundException::class); $controller->read($this->request, $this->response, [ 'id' => self::NEW_DATE ]); } }