From 8d9dc931cedd6587216f94ce63bb064222f24c6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BC=D0=BC=C4=91=20=CE=B1=D0=BC=C4=B1=D0=B8=20=E1=B4=BE?= =?UTF-8?q?=E1=B4=B4=E1=B4=BE?= <51942680+Mr-Basirnia@users.noreply.github.com> Date: Thu, 20 Oct 2022 21:20:25 +0330 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20test(database):=20delete=20recor?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Test delete request api. --- tdd-project/index.php | 5 +++++ tdd-project/tests/functional/CrudTest.php | 24 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tdd-project/index.php b/tdd-project/index.php index c4fb996..3f90080 100644 --- a/tdd-project/index.php +++ b/tdd-project/index.php @@ -47,4 +47,9 @@ function request() if ($_SERVER['REQUEST_METHOD'] === 'GET') { $result = $pdoQuery->table('bugs')->find(request()['id']); jsonResponse($result, 200); +} +if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { + + $result = $pdoQuery->table('bugs')->where('id', request()['id'])->delete(); + jsonResponse(null, 204); } \ No newline at end of file diff --git a/tdd-project/tests/functional/CrudTest.php b/tdd-project/tests/functional/CrudTest.php index 3926cac..c27f0e7 100644 --- a/tdd-project/tests/functional/CrudTest.php +++ b/tdd-project/tests/functional/CrudTest.php @@ -89,6 +89,30 @@ public function testItCanFetchDataWithApi(array $data): void $this->assertArrayHasKey('id', json_decode($response->getBody(), true)); } + /** + * test delete record with delete api request + * + * @depends testItCanCreateDataWithApi + * @param array $data created record + * @return void + */ + public function testItCanDeleteDataWithApi(array $data): void + { + $response = $this->httpClient->delete('index.php', [ + 'json' => [ + 'id' => $data['id'] + ] + ]); + + // if record is deleted, return null + $result = $this->queryBuilder + ->table('bugs') + ->find($data['id']); + + $this->assertEquals(204, $response->getStatusCode()); + $this->assertNull($result); + } + /** * @throws ConfigFileNotValidException|PdoDatabaseException */