Added first tests to Rest module

This commit is contained in:
Alejandro Celaya 2016-07-19 18:19:05 +02:00
parent fe8ef2030f
commit f917697b8e
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,54 @@
<?php
namespace ShlinkioTest\Shlink\Rest\Middleware;
use PHPUnit_Framework_TestCase as TestCase;
use Shlinkio\Shlink\Rest\Middleware\CrossDomainMiddleware;
use Zend\Diactoros\Response;
use Zend\Diactoros\ServerRequestFactory;
class CrossDomainMiddlewareTest extends TestCase
{
/**
* @var CrossDomainMiddleware
*/
protected $middleware;
public function setUp()
{
$this->middleware = new CrossDomainMiddleware();
}
/**
* @test
*/
public function anyRequestIncludesTheAllowAccessHeader()
{
$response = $this->middleware->__invoke(
ServerRequestFactory::fromGlobals(),
new Response(),
function ($req, $resp) {
return $resp;
}
);
$headers = $response->getHeaders();
$this->assertArrayHasKey('Access-Control-Allow-Origin', $headers);
$this->assertArrayNotHasKey('Access-Control-Allow-Headers', $headers);
}
/**
* @test
*/
public function optionsRequestIncludesMoreHeaders()
{
$request = ServerRequestFactory::fromGlobals(['REQUEST_METHOD' => 'OPTIONS']);
$response = $this->middleware->__invoke($request, new Response(), function ($req, $resp) {
return $resp;
});
$headers = $response->getHeaders();
$this->assertArrayHasKey('Access-Control-Allow-Origin', $headers);
$this->assertArrayHasKey('Access-Control-Allow-Headers', $headers);
}
}

View File

@ -6,6 +6,9 @@
<testsuite name="Core"> <testsuite name="Core">
<directory>./module/Core/test</directory> <directory>./module/Core/test</directory>
</testsuite> </testsuite>
<testsuite name="Rest">
<directory>./module/Rest/test</directory>
</testsuite>
</testsuites> </testsuites>
<filter> <filter>