- just create a PR on Github and let me know
It is a bit tricky process, so I made a helper script for that. Basically, you can do the following steps to cover new functionality with unit test. Feel free to improve this guide as well.
- implement new functionality in
Php2Curlclass - configure new Postman request to approach new functionality (if you are testing PATCH requests, then configure Postman to send PATCH, etc.)
- include a GET parameter
nameto that request, something like?name=simple_patch. Stringsimple_patchwill be used as an identifier of the test case. - start php dev server, e.g.
cd php2curl; php -S localhost:8000 test/persist_test_case.php - send a request from step#2 to the server from step#4 (here, to http://localhost:8000)
- everything (PHP globals, php input data, etc.) will be saved into
postman_outcome/postman_<identifier>.php - create new test case in
Php2CurlTest.phpfile following the template:
/**
* @test
*/
public function it_can_handle_<test case identifier>() // test case name is it_can_handle_<test case identifier>
{
$expectedCurl = ''; // this is intentionally empty string at the beginning
$sut = $this->createSut('<identifer>'); // test case identifier here as an argument
$this->assertEquals($expectedCurl, $sut->doAll());
}- run the new test case, and you will see the curl command returned by
doAll()on the screen. - copy/paste it to terminal and run
- if the command is correct, you should find a file with the same format under
curl_outcome/curl_<identifier>.php. Copy the content of this file and carefully compare it withpostman_outcome/postman_<identifier>.php(via "compare with clipboard" from PHPStorm, or just http://www.quickdiff.com/), treating the postman one as the source of truth. - if those two files are equal functionality-wise (
$_SERVER['REQUEST_TIME']is different and anything else like that) you can copy the curl command to$exceptedCurlvariable in the test. - run the test again to make sure it is green now
- make sure other tests are still green
- done!