Skip to content

Commit

Permalink
Refactor Request class tests
Browse files Browse the repository at this point in the history
Always mock the curl_* calls instead of relying on external HTTP services
  • Loading branch information
jwilsson committed Jul 31, 2023
1 parent 2c6cbdd commit 3e22954
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 194 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"require-dev": {
"php-coveralls/php-coveralls": "^2.5",
"php-mock/php-mock-phpunit": "^2.7",
"phpunit/phpunit": "^10.2",
"squizlabs/php_codesniffer": "^3.0"
},
Expand Down
20 changes: 18 additions & 2 deletions phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ function error_handler($errno) {
}

// Test helper functions
function get_fixture($fixture)
function load_fixture($fixture)
{
$fixture = __DIR__ . '/tests/fixtures/' . $fixture . '.json';
$fixture = file_get_contents($fixture);

return file_get_contents($fixture);
}

function get_fixture($fixture)
{
$fixture = load_fixture($fixture);

return json_decode($fixture);
}

function create_http_response($body, $status = 200)
{
return <<<END
HTTP/1.1 $status OK
Content-Type: application/json
$body
END;
}
Loading

0 comments on commit 3e22954

Please sign in to comment.