Skip to content

Commit

Permalink
Merge pull request #36 from Mr-Basirnia:develop
Browse files Browse the repository at this point in the history
🧪 test(database): delete record
  • Loading branch information
Mr-Basirnia authored Oct 20, 2022
2 parents f0d5043 + 8d9dc93 commit 0b8390f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tdd-project/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
24 changes: 24 additions & 0 deletions tdd-project/tests/functional/CrudTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 0b8390f

Please sign in to comment.