データベースからオブジェクトを削除するために Silex のルートを使用しています。オブジェクトが存在しない場合は、404 エラーがスローされます。これはブラウザで正常に機能し、それに応じて応答が受信されます。
これは私のソースです:
$app->delete("/{entity}/{id}", function(\Silex\Application $app, HttpFoundation\Request $request, $entity, $id) {
// some prep code is here
$deleteObject = $this->em->getRepository($entityClass)->find($id);
if (empty($deleteObject))
$app->abort(404, "$ucEntity with ID $id not found");
// other code comes here...
}
これは私のテストケースです:
// deleting the same object again should not work
$client->request("DELETE", "/ccrud/channel/$id");
$this->assertTrue($response->getStatusCode() == 404);
現在、phpunit は次のエラーで失敗します: 1) CrudEntityTest::testDelete Symfony\Component\HttpKernel\Exception\HttpException: Channel with ID 93 not found
404 がスローされたことはメッセージからわかりますが、応答オブジェクトを計画どおりにテストできません。理論的には例外自体をアサートできることはわかっていますが、それは私がやりたいことではありません。(ブラウザーも同様に) 応答を取得し、ステータス コード自体をテストしたいと考えています。
それに到達する方法、またはこれをテストするより良い方法があるかどうか、誰かアイデアはありますか?
ありがとう、ダニエル