This commit is contained in:
Marcel Pociot
2020-05-01 20:52:12 +02:00
parent ea394c8e54
commit c717683634
16 changed files with 145 additions and 96 deletions

View File

@@ -27,6 +27,9 @@ class AdminTest extends TestCase
parent::setUp();
$this->browser = new Browser($this->loop);
$this->browser = $this->browser->withOptions([
'followRedirects' => false,
]);
$this->startServer();
}
@@ -54,11 +57,11 @@ class AdminTest extends TestCase
public function it_accepts_valid_credentials()
{
/** @var ResponseInterface $response */
$response = $this->await($this->browser->get('http://127.0.0.1:8080', [
$response = $this->await($this->browser->get('http://127.0.0.1:8080/', [
'Host' => 'expose.localhost',
'Authorization' => base64_encode("username:secret"),
]));
$this->assertSame(200, $response->getStatusCode());
$this->assertSame(301, $response->getStatusCode());
}
/** @test */
@@ -116,6 +119,7 @@ class AdminTest extends TestCase
protected function startServer()
{
$this->app['config']['expose.admin.subdomain'] = 'expose';
$this->app['config']['expose.admin.database'] = ':memory:';
$this->app['config']['expose.admin.users'] = [

View File

@@ -33,6 +33,13 @@ class TunnelTest extends TestCase
$this->startServer();
}
public function tearDown(): void
{
$this->serverFactory->getSocket()->close();
parent::tearDown();
}
/** @test */
public function it_returns_404_for_non_existing_clients()
{

View File

@@ -4,7 +4,9 @@ namespace Tests\Unit;
use App\Logger\LoggedRequest;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Laminas\Http\Request as LaminasRequest;
use Laminas\Http\Response as LaminasResponse;
use Tests\TestCase;
use function GuzzleHttp\Psr7\str;
@@ -22,6 +24,33 @@ class LoggedRequestTest extends TestCase
$this->assertSame('example-request', $loggedRequest->id());
}
/** @test */
public function it_returns_post_data_for_json_payloads()
{
$postData = [
'name' => 'Marcel',
'project' => 'expose'
];
$rawRequest = str(new Request(200, '/expose', [
'Content-Type' => 'application/json'
], json_encode($postData)));
$parsedRequest = LaminasRequest::fromString($rawRequest);
$loggedRequest = new LoggedRequest($rawRequest, $parsedRequest);
$this->assertSame([
[
'name' => 'name',
'value' => 'Marcel'
],
[
'name' => 'project',
'value' => 'expose'
]
], $loggedRequest->getPostData());
}
/** @test */
public function it_returns_the_raw_request()
{