You've already forked Php-Template
tests
This commit is contained in:
@@ -16,9 +16,12 @@ class CorsMiddlewareTest extends Unit
|
||||
public function testAllowsConfiguredOrigin(): void
|
||||
{
|
||||
Config::shouldReceive('get')
|
||||
->with('CORS_ALLOWED_ORIGINS', 'https://example.com,https://another.com')
|
||||
->with('cors.allowed_origins')
|
||||
->andReturn('https://example.com,https://another.com');
|
||||
|
||||
Config::shouldReceive('get')->with('cors.allow_credentials')->andReturn(false);
|
||||
Config::shouldReceive('get')->with('cors.max_age')->andReturn('');
|
||||
|
||||
$middleware = new CorsMiddleware();
|
||||
$request = new ServerRequest('GET', '/')->withHeader('Origin', 'https://example.com');
|
||||
$handler = $this->mockHandler(new Response(200));
|
||||
@@ -31,7 +34,7 @@ class CorsMiddlewareTest extends Unit
|
||||
public function testBlocksUnconfiguredOrigin(): void
|
||||
{
|
||||
Config::shouldReceive('get')
|
||||
->with('CORS_ALLOWED_ORIGINS', 'https://example.com,https://another.com')
|
||||
->with('cors.allowed_origins')
|
||||
->andReturn('https://example.com,https://another.com');
|
||||
|
||||
$middleware = new CorsMiddleware();
|
||||
@@ -40,14 +43,14 @@ class CorsMiddlewareTest extends Unit
|
||||
|
||||
$response = $middleware->process($request, $handler);
|
||||
|
||||
$this->assertEquals('null', $response->getHeaderLine('Access-Control-Allow-Origin'));
|
||||
$this->assertEmpty($response->getHeaderLine('Access-Control-Allow-Origin'));
|
||||
}
|
||||
|
||||
public function testHandlesOptionsRequest(): void
|
||||
{
|
||||
Config::shouldReceive('get')->with('CORS_ALLOWED_ORIGINS', '...')->andReturn('https://example.com');
|
||||
Config::shouldReceive('get')->with('CORS_ALLOW_CREDENTIALS', 'bool')->andReturn(false);
|
||||
Config::shouldReceive('get')->with('CORS_MAX_AGE')->andReturn('86400');
|
||||
Config::shouldReceive('get')->with('cors.allowed_origins')->andReturn('https://example.com');
|
||||
Config::shouldReceive('get')->with('cors.allow_credentials')->andReturn(false);
|
||||
Config::shouldReceive('get')->with('cors.max_age')->andReturn('86400');
|
||||
|
||||
$middleware = new CorsMiddleware();
|
||||
$request = new ServerRequest('OPTIONS', '/')->withHeader('Origin', 'https://example.com');
|
||||
@@ -61,8 +64,13 @@ class CorsMiddlewareTest extends Unit
|
||||
|
||||
public function testAddsAllowCredentialsHeader(): void
|
||||
{
|
||||
Config::shouldReceive('get')->with('CORS_ALLOWED_ORIGINS', '...')->andReturn('https://example.com');
|
||||
Config::shouldReceive('get')->with('CORS_ALLOW_CREDENTIALS', 'bool')->andReturn(true);
|
||||
Config::shouldReceive('get')
|
||||
->with('cors.allowed_origins')
|
||||
->andReturn('https://example.com');
|
||||
|
||||
Config::shouldReceive('get')->with('cors.allowed_origins')->andReturn('https://example.com');
|
||||
Config::shouldReceive('get')->with('cors.allow_credentials')->andReturn(true);
|
||||
Config::shouldReceive('get')->with('cors.max_age')->andReturn('86400');
|
||||
|
||||
$middleware = new CorsMiddleware();
|
||||
$request = new ServerRequest('GET', '/')->withHeader('Origin', 'https://example.com');
|
||||
@@ -91,3 +99,4 @@ class CorsMiddlewareTest extends Unit
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,22 @@ declare(strict_types=1);
|
||||
|
||||
namespace Siteworxpro\Tests;
|
||||
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Support\Facades\Facade;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Siteworxpro\App\Facades\Config;
|
||||
|
||||
abstract class Unit extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$container = new Container();
|
||||
Facade::setFacadeApplication($container);
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
Config::clearResolvedInstances();
|
||||
Facade::setFacadeApplication(null);
|
||||
}
|
||||
}
|
||||
|
||||
1
tests/reports/.gitignore
vendored
Normal file
1
tests/reports/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
html/
|
||||
Reference in New Issue
Block a user