Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
neomerx committed Aug 12, 2015
2 parents 41bc2e9 + f2d2bc6 commit 4e2ffcf
Show file tree
Hide file tree
Showing 6 changed files with 226 additions and 29 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/neomerx/cors-illuminate/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/neomerx/cors-illuminate/?branch=master)
[![Code Coverage](https://scrutinizer-ci.com/g/neomerx/cors-illuminate/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/neomerx/cors-illuminate/?branch=master)
[![Build Status](https://travis-ci.org/neomerx/cors-illuminate.svg?branch=master)](https://travis-ci.org/neomerx/cors-illuminate)
[![HHVM](https://img.shields.io/hhvm/neomerx/cors-illuminate.svg)](https://travis-ci.org/neomerx/cors-illuminate)
[![License](https://img.shields.io/packagist/l/neomerx/cors-illuminate.svg)](https://packagist.org/packages/neomerx/cors-illuminate)

## Description

This package adds [Cross-Origin Resource Sharing](http://www.w3.org/TR/cors/) (CORS) support to your Laravel application.
Expand Down
34 changes: 13 additions & 21 deletions src/Adapters/IlluminateRequestToPsr7.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,117 +77,109 @@ public function getHeader($name)
*/
public function getProtocolVersion()
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withProtocolVersion($version)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function getHeaders()
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function getHeaderLine($name)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withHeader($name, $value)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withAddedHeader($name, $value)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withoutHeader($name)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function getBody()
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withBody(StreamInterface $body)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function getRequestTarget()
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withRequestTarget($requestTarget)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withMethod($method)
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function getUri()
{
$this->notImplemented();
throw new LogicException('Method is not implemented');
}

/**
* @inheritdoc
*/
public function withUri(UriInterface $uri, $preserveHost = false)
{
$this->notImplemented();
}

/**
* Throws exception. This method should never be called.
*/
private function notImplemented()
{
throw new LogicException('Method is not implemented');
}
Expand Down
7 changes: 5 additions & 2 deletions src/Providers/LaravelServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

use \Illuminate\Support\ServiceProvider;
use \Illuminate\Contracts\Config\Repository;
use \Neomerx\CorsIlluminate\Settings\Settings;

/**
Expand Down Expand Up @@ -48,13 +49,15 @@ public function register()
public function boot()
{
// publish config
$publishPath = $this->app->make('path.config') . DIRECTORY_SEPARATOR . static::CONFIG_FILE_NAME_WO_EXT . '.php';
$publishPath = $this->app['path.config'] . DIRECTORY_SEPARATOR . static::CONFIG_FILE_NAME_WO_EXT . '.php';
$this->publishes([
$this->getConfigPath() => $publishPath,
]);

// load settings
$settings = $this->app->make('config')->get(static::CONFIG_FILE_NAME_WO_EXT);
/** @var Repository $config */
$config = $this->app['config'];
$settings = $config->get(static::CONFIG_FILE_NAME_WO_EXT);
Settings::setSettings($settings);
}

Expand Down
121 changes: 121 additions & 0 deletions tests/Adapters/IlluminateRequestToPsr7Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,18 @@
* limitations under the License.
*/

use \Mockery;
use \Illuminate\Http\Request;
use \Psr\Http\Message\UriInterface;
use \Psr\Http\Message\StreamInterface;
use \Psr\Http\Message\RequestInterface;
use \Neomerx\Tests\CorsIlluminate\BaseTestCase;
use \Neomerx\CorsIlluminate\Adapters\IlluminateRequestToPsr7;

/**
* @package Neomerx\Tests\CorsIlluminate
*
* @SuppressWarnings(PHPMD.TooManyMethods)
*/
class IlluminateRequestToPsr7Test extends BaseTestCase
{
Expand Down Expand Up @@ -84,4 +89,120 @@ public function testGetHeader()
$this->request->headers->set($name, ['value 2'], false);
$this->assertEquals(['value 1', 'value 2'], $this->adapter->getHeader($name));
}

/**
* @expectedException \LogicException
*/
public function testGetProtocolVersion()
{
$this->adapter->getProtocolVersion();
}

/**
* @expectedException \LogicException
*/
public function testWithProtocolVersion()
{
$this->adapter->withProtocolVersion(null);
}

/**
* @expectedException \LogicException
*/
public function testGetHeaders()
{
$this->adapter->getHeaders();
}

/**
* @expectedException \LogicException
*/
public function testGetHeaderLine()
{
$this->adapter->getHeaderLine(null);
}

/**
* @expectedException \LogicException
*/
public function testWithHeader()
{
$this->adapter->withHeader(null, null);
}

/**
* @expectedException \LogicException
*/
public function testWithAddedHeader()
{
$this->adapter->withAddedHeader(null, null);
}

/**
* @expectedException \LogicException
*/
public function testWithoutHeader()
{
$this->adapter->withoutHeader(null);
}

/**
* @expectedException \LogicException
*/
public function testGetBody()
{
$this->adapter->getBody();
}

/**
* @expectedException \LogicException
*/
public function testWithBody()
{
/** @var StreamInterface $body */
$body = Mockery::mock(StreamInterface::class);
$this->adapter->withBody($body);
}

/**
* @expectedException \LogicException
*/
public function testGetRequestTarget()
{
$this->adapter->getRequestTarget();
}

/**
* @expectedException \LogicException
*/
public function testWithRequestTarget()
{
$this->adapter->withRequestTarget(null);
}

/**
* @expectedException \LogicException
*/
public function testWithMethod()
{
$this->adapter->withMethod(null);
}

/**
* @expectedException \LogicException
*/
public function testGetUri()
{
$this->adapter->getUri();
}

/**
* @expectedException \LogicException
*/
public function testWithUri()
{
/** @var UriInterface $uri */
$uri = Mockery::mock(UriInterface::class);
$this->adapter->withUri($uri);
}
}
27 changes: 27 additions & 0 deletions tests/CorsMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use \Illuminate\Http\Response;
use \Neomerx\CorsIlluminate\CorsMiddleware;
use \Neomerx\Cors\Contracts\AnalyzerInterface;
use \Neomerx\CorsIlluminate\Settings\Settings;
use \Neomerx\Cors\Contracts\AnalysisResultInterface;

/**
Expand Down Expand Up @@ -57,6 +58,32 @@ protected function setUp()
$this->analysisResult = Mockery::mock(AnalysisResultInterface::class);
}

/**
* Test can be created without input args.
*/
public function testCreate()
{
$middleware = new CorsMiddleware();

$oldOrigin = Settings::$serverOrigin;
$oldAllowed = Settings::$allowedOrigins;
try {
Settings::$serverOrigin = [
'scheme' => 'http',
'host' => 'localhost',
'port' => 8080,
];
Settings::$allowedOrigins = [];

$middleware->handle(new Request(), function () {
return null;
});
} finally {
Settings::$serverOrigin = $oldOrigin;
Settings::$allowedOrigins = $oldAllowed;
}
}

/**
* Test middleware handling.
*/
Expand Down

0 comments on commit 4e2ffcf

Please sign in to comment.