Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/18' into release-1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
geerteltink committed Feb 24, 2018
2 parents a32c76d + 888d011 commit 0832c05
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 3 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.0.0alpha3 - 2018-02-24

### Added

- Nothing.

### Changed

- Nothing.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#18](https://github.com/zendframework/zend-expressive-authentication/pull/18)
uses the ResponseInterface as a factory. This was recently changed in
[zend-expressive#561](https://github.com/zendframework/zend-expressive/pull/561).

## 1.0.0alpha2 - 2018-02-22

### Added
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"require-dev": {
"phpunit/phpunit": "^6.5.5",
"roave/security-advisories": "dev-master",
"zendframework/zend-coding-standard": "~1.0.0"
"zendframework/zend-coding-standard": "~1.0.0",
"zendframework/zend-diactoros": "^1.7"
},
"conflict": {
"container-interop/container-interop": "<1.2.0"
Expand Down
54 changes: 53 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
colors="true"
stderr="true">
<testsuites>
<testsuite name="without diactoros">
<file>./test/ResponsePrototypeTraitWithoutDiactorosTest.php</file>
</testsuite>
<testsuite name="zend-expressive-authentication">
<directory>./test</directory>
<exclude>./test/ResponsePrototypeTraitWithoutDiactorosTest.php</exclude>
</testsuite>
</testsuites>

Expand Down
2 changes: 1 addition & 1 deletion src/ResponsePrototypeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function getResponsePrototype(ContainerInterface $container) : Respons
));
}
return $container->has(ResponseInterface::class)
? $container->get(ResponseInterface::class)
? $container->get(ResponseInterface::class)()
: new Response();
}
}
62 changes: 62 additions & 0 deletions test/ResponsePrototypeTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

namespace ZendTest\Expressive\Authentication;

use PHPUnit\Framework\TestCase;
use Prophecy\Prophecy\ObjectProphecy;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use ReflectionObject;
use Zend\Expressive\Authentication\ResponsePrototypeTrait;
use Zend\Diactoros\Response;

class ResponsePrototypeTraitTest extends TestCase
{
/** @var ContainerInterface|ObjectProphecy */
private $container;

protected function setUp() : void
{
$this->container = $this->prophesize(ContainerInterface::class);
}

public function testContainerHasDefinedResponseFactory()
{
$this->container->has(ResponseInterface::class)->willReturn(true);
$this->container->get(ResponseInterface::class)->willReturn(function () {
return $this->prophesize(ResponseInterface::class)->reveal();
});

$response = $this->getResponsePrototype();
$this->assertInstanceOf(ResponseInterface::class, $response);
$this->assertNotInstanceOf(Response::class, $response);
}

public function testContainerDoesNotHaveResponseFactoryButDiactorosIsInstalled()
{
$this->container->has(ResponseInterface::class)->willReturn(false);

$response = $this->getResponsePrototype();
$this->assertInstanceOf(Response::class, $response);
}

private function getResponsePrototype()
{
$class = new class () {
use ResponsePrototypeTrait;
};

$r = new ReflectionObject($class);
$m = $r->getMethod('getResponsePrototype');
$m->setAccessible(true);

return $m->invoke($class, $this->container->reveal());
}
}
84 changes: 84 additions & 0 deletions test/ResponsePrototypeTraitWithoutDiactorosTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License
*/

declare(strict_types=1);

namespace ZendTest\Expressive\Authentication;

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use ReflectionMethod;
use ReflectionObject;
use Zend\Expressive\Authentication\Exception\InvalidConfigException;
use Zend\Expressive\Authentication\ResponsePrototypeTrait;

class ResponsePrototypeTraitWithoutDiactorosTest extends TestCase
{
/** @var ContainerInterface */
private $container;

/** @var object */
private $class;

/** @var ReflectionMethod */
private $method;

/** @var array */
private $autoloadFunctions = [];

protected function setUp()
{
class_exists(InvalidConfigException::class);
interface_exists(ResponseInterface::class);

$this->container = new class () implements ContainerInterface
{
public function get($id)
{
return null;
}

public function has($id)
{
return false;
}
};

$this->class = new class () {
use ResponsePrototypeTrait;
};

$r = new ReflectionObject($this->class);
$this->method = $r->getMethod('getResponsePrototype');
$this->method->setAccessible(true);

$this->autoloadFunctions = spl_autoload_functions();
foreach ($this->autoloadFunctions as $autoloader) {
spl_autoload_unregister($autoloader);
}
}

private function reloadAutoloaders()
{
foreach ($this->autoloadFunctions as $autoloader) {
spl_autoload_register($autoloader);
}
}

public function testRaisesAnExceptionIfDiactorosIsNotLoaded()
{
$this->expectException(InvalidConfigException::class);
$this->expectExceptionMessage('zendframework/zend-diactoros');

try {
$this->method->invoke($this->class, $this->container);
} finally {
$this->reloadAutoloaders();
}
}
}

0 comments on commit 0832c05

Please sign in to comment.