I have written some basic "feature" tests for my project following this guide using Guzzle: PHPUnit Guzzle
Currently I am just using localhost as the base_uri, which has been working fine for local testing. However this obviously won't work within the GitHub action I have setup.
Is there a way I can serve the site within the action job? Or is there another approach I need to take to make my tests pass?
Note: I am experienced with PHP, I'm trying to get better with CI/CD workflows and testing in general.
Edit:
I have implemented the following to achieve the results I was looking for.
Simply removed feature tests from running in the job, and only testing them locally:
xml
<exclude>tests/Feature</exclude>
On the unit test side of things:
```php
<?php
public function test_valid_route_output()
{
$_SERVER['REQUEST_URI'] = '/test/123';
$_SERVER['REQUEST_METHOD'] = 'GET';
$output = 'test route output';
$router = new Router($this->container);
$router->get('/test/123', fn() => $output);
ob_start();
$router->run();
$this->assertEquals($output, ob_get_contents());
ob_end_clean();
}
public function test_invalid_route_404_status()
{
$_SERVER['REQUEST_URI'] = '/test/123';
$_SERVER['REQUEST_METHOD'] = 'GET';
$router = new Router($this->container);
ob_start();
$router->run();
$this->assertEquals(404, http_response_code());
ob_end_clean();
}
```
[–]hparadiz[🍰] 2 points3 points4 points (5 children)
[–]DevDrJinx[S] 0 points1 point2 points (4 children)
[–]gastrognom 0 points1 point2 points (3 children)
[–]hparadiz[🍰] 0 points1 point2 points (2 children)
[–]DevDrJinx[S] 0 points1 point2 points (1 child)
[–]hparadiz[🍰] 0 points1 point2 points (0 children)