Working on test suite

This commit is contained in:
Sergio 2020-09-04 17:17:57 +02:00
parent 75c7c644aa
commit 61efafc991
3 changed files with 28 additions and 11 deletions

View file

@ -11,11 +11,15 @@ class Client extends AbstractBrowser
{
protected function doRequest($request)
{
define('BASE_DIR', realpath(__DIR__.'/../').DIRECTORY_SEPARATOR);
define('PLATFORM_VERSION', json_decode(file_get_contents(BASE_DIR.'composer.json'))->version);
if (!defined('BASE_DIR')) {
define('BASE_DIR', realpath(__DIR__.'/../').DIRECTORY_SEPARATOR);
}
if (!defined('PLATFORM_VERSION')) {
define('PLATFORM_VERSION', json_decode(file_get_contents(BASE_DIR.'composer.json'))->version);
}
/** @var \Slim\App $app */
$app = require_once BASE_DIR.'bootstrap/app.php';
$app = require BASE_DIR.'bootstrap/app.php';
$response = $app->handle(new ServerRequest($request->getMethod(), $request->getUri(), [], $request->getContent()));

View file

@ -8,10 +8,15 @@ use Tests\TestCase;
class LoginControllerTest extends TestCase
{
/** @test */
public function it_loads_the_login_page()
public function test_it_loads_the_login_page(): void
{
$response = $this->get('/login');
$this->assertSame(200, $response->getStatusCode());
self::assertSame(200, $response->getStatusCode());
}
public function test_it_redirect_back_to_login_page_with_no_credentials(): void
{
$response = $this->post('/login');
self::assertSame(200, $response->getStatusCode());
}
}

View file

@ -2,8 +2,8 @@
namespace Tests;
use GuzzleHttp\Psr7\Response;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Symfony\Component\BrowserKit\Response;
abstract class TestCase extends BaseTestCase
{
@ -21,22 +21,30 @@ abstract class TestCase extends BaseTestCase
/**
* @param string $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param string|null $content
* @param bool $changeHistory
* @return Response|object
*/
public function get(string $uri, array $parameters = [])
protected function get(string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true)
{
$this->client->request('GET', $uri, $parameters);
$this->client->request('GET', $uri, $parameters, $files, $server, $content, $changeHistory);
return $this->client->getResponse();
}
/**
* @param string $uri
* @param array $parameters
* @param array $files
* @param array $server
* @param string|null $content
* @param bool $changeHistory
* @return Response|object
*/
public function post(string $uri, array $parameters = [])
protected function post(string $uri, array $parameters = [], array $files = [], array $server = [], string $content = null, bool $changeHistory = true)
{
$this->client->request('POST', $uri, $parameters);
$this->client->request('POST', $uri, $parameters, $files, $server, $content, $changeHistory);
return $this->client->getResponse();
}
}