# Ecrire ses tests API en HTTP --- Test case API écrit avec MaSuperLibDeTest ```php // lib de test: Codeception public function getDocumentationActionTest(ApiTester $I) { $I->haveHttpHeader('x-auth-token', 'api12345-449c-4e49-87ff-82db2da75715'); $I->haveHttpHeader('Content-Type', 'application/json'); $I->sendPost('/internal/catalog/documentation', [ 'partner_id' => '2', 'offer_type' => 'all_inclusive', ]); $I->seeResponseCodeIsSuccessful(); $I->seeResponseIsJson(); $I->grabResponse(); $I->seeResponseContains('"name":"Tarifs"'); } ``` --- Inconvénients d' écrire un test case avec MaSuperLibDeTest * **connaître l'API** de MaSuperLibDeTest parmi les dizaines avec lequels nous devons jongler sur d'autres projets * difficile à lire * synchroniser notre travail entre Postman et nos tests cases est fastidieux --- Test API PhpUnit, HTTP (markdown) ![](https://i.imgur.com/Wv52x7W.png) --- vi post_with_valid_input.md ![](https://i.imgur.com/GZDxjRT.png) --- Avantages d' écrire un test case HTTP (md) * dynamic response content thks to https://github.com/coduo/php-matcher * bénéfices de la notation HTTP * nous n'avons pas besoin de savoir lire du PHP * facile à lire * nous pouvons facilement exporter notre test case vers Postman - [pas encore implemente](https://github.com/postmanlabs/postman-app-support/issues/9081) * nous pouvons facilement importer une requête Postman vers un test case --- Postman ![](https://i.imgur.com/2qRrCb0.png) --- Gitlab ![](https://i.imgur.com/j1SpjOK.png) --- phpunit ![](https://i.imgur.com/69CgRd8.png) --- References * [Travaux initiaux menés par Alexander Schranz](https://github.com/alexander-schranz/markdown-based-api-testing) * [Progrès non released d'Alexander Schranz](https://github.com/alexander-schranz/markdown-based-api-testing/pull/2#issuecomment-1118471853) --- ![](https://i.imgur.com/djyGBCa.png)
{"metaMigratedAt":"2023-06-17T02:25:05.544Z","metaMigratedFrom":"YAML","title":"Ecrire ses tests APIs en HTTP","breaks":true,"description":"View the slide with \"Slide Mode\".","contributors":"[{\"id\":\"90d1cbfc-f7d6-4f9c-b2eb-42d2c1e2f52f\",\"add\":4336,\"del\":4599}]"}
    233 views