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

Commit 0832c05

Browse files
committed
Merge branch 'hotfix/18' into release-1.0.0
Close #18 Close zendframework/zend-expressive#569
2 parents a32c76d + 888d011 commit 0832c05

7 files changed

+230
-3
lines changed

CHANGELOG.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,30 @@
22

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

5+
## 1.0.0alpha3 - 2018-02-24
6+
7+
### Added
8+
9+
- Nothing.
10+
11+
### Changed
12+
13+
- Nothing.
14+
15+
### Deprecated
16+
17+
- Nothing.
18+
19+
### Removed
20+
21+
- Nothing.
22+
23+
### Fixed
24+
25+
- [#18](https://github.com/zendframework/zend-expressive-authentication/pull/18)
26+
uses the ResponseInterface as a factory. This was recently changed in
27+
[zend-expressive#561](https://github.com/zendframework/zend-expressive/pull/561).
28+
529
## 1.0.0alpha2 - 2018-02-22
630

731
### Added

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@
2929
"require-dev": {
3030
"phpunit/phpunit": "^6.5.5",
3131
"roave/security-advisories": "dev-master",
32-
"zendframework/zend-coding-standard": "~1.0.0"
32+
"zendframework/zend-coding-standard": "~1.0.0",
33+
"zendframework/zend-diactoros": "^1.7"
3334
},
3435
"conflict": {
3536
"container-interop/container-interop": "<1.2.0"

composer.lock

Lines changed: 53 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml.dist

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
colors="true"
66
stderr="true">
77
<testsuites>
8+
<testsuite name="without diactoros">
9+
<file>./test/ResponsePrototypeTraitWithoutDiactorosTest.php</file>
10+
</testsuite>
811
<testsuite name="zend-expressive-authentication">
912
<directory>./test</directory>
13+
<exclude>./test/ResponsePrototypeTraitWithoutDiactorosTest.php</exclude>
1014
</testsuite>
1115
</testsuites>
1216

src/ResponsePrototypeTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ protected function getResponsePrototype(ContainerInterface $container) : Respons
3333
));
3434
}
3535
return $container->has(ResponseInterface::class)
36-
? $container->get(ResponseInterface::class)
36+
? $container->get(ResponseInterface::class)()
3737
: new Response();
3838
}
3939
}

test/ResponsePrototypeTraitTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Authentication;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Prophecy\Prophecy\ObjectProphecy;
14+
use Psr\Container\ContainerInterface;
15+
use Psr\Http\Message\ResponseInterface;
16+
use ReflectionObject;
17+
use Zend\Expressive\Authentication\ResponsePrototypeTrait;
18+
use Zend\Diactoros\Response;
19+
20+
class ResponsePrototypeTraitTest extends TestCase
21+
{
22+
/** @var ContainerInterface|ObjectProphecy */
23+
private $container;
24+
25+
protected function setUp() : void
26+
{
27+
$this->container = $this->prophesize(ContainerInterface::class);
28+
}
29+
30+
public function testContainerHasDefinedResponseFactory()
31+
{
32+
$this->container->has(ResponseInterface::class)->willReturn(true);
33+
$this->container->get(ResponseInterface::class)->willReturn(function () {
34+
return $this->prophesize(ResponseInterface::class)->reveal();
35+
});
36+
37+
$response = $this->getResponsePrototype();
38+
$this->assertInstanceOf(ResponseInterface::class, $response);
39+
$this->assertNotInstanceOf(Response::class, $response);
40+
}
41+
42+
public function testContainerDoesNotHaveResponseFactoryButDiactorosIsInstalled()
43+
{
44+
$this->container->has(ResponseInterface::class)->willReturn(false);
45+
46+
$response = $this->getResponsePrototype();
47+
$this->assertInstanceOf(Response::class, $response);
48+
}
49+
50+
private function getResponsePrototype()
51+
{
52+
$class = new class () {
53+
use ResponsePrototypeTrait;
54+
};
55+
56+
$r = new ReflectionObject($class);
57+
$m = $r->getMethod('getResponsePrototype');
58+
$m->setAccessible(true);
59+
60+
return $m->invoke($class, $this->container->reveal());
61+
}
62+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-expressive-authentication for the canonical source repository
4+
* @copyright Copyright (c) 2018 Zend Technologies USA Inc. (https://www.zend.com)
5+
* @license https://github.com/zendframework/zend-expressive-authentication/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace ZendTest\Expressive\Authentication;
11+
12+
use PHPUnit\Framework\TestCase;
13+
use Psr\Container\ContainerInterface;
14+
use Psr\Http\Message\ResponseInterface;
15+
use ReflectionMethod;
16+
use ReflectionObject;
17+
use Zend\Expressive\Authentication\Exception\InvalidConfigException;
18+
use Zend\Expressive\Authentication\ResponsePrototypeTrait;
19+
20+
class ResponsePrototypeTraitWithoutDiactorosTest extends TestCase
21+
{
22+
/** @var ContainerInterface */
23+
private $container;
24+
25+
/** @var object */
26+
private $class;
27+
28+
/** @var ReflectionMethod */
29+
private $method;
30+
31+
/** @var array */
32+
private $autoloadFunctions = [];
33+
34+
protected function setUp()
35+
{
36+
class_exists(InvalidConfigException::class);
37+
interface_exists(ResponseInterface::class);
38+
39+
$this->container = new class () implements ContainerInterface
40+
{
41+
public function get($id)
42+
{
43+
return null;
44+
}
45+
46+
public function has($id)
47+
{
48+
return false;
49+
}
50+
};
51+
52+
$this->class = new class () {
53+
use ResponsePrototypeTrait;
54+
};
55+
56+
$r = new ReflectionObject($this->class);
57+
$this->method = $r->getMethod('getResponsePrototype');
58+
$this->method->setAccessible(true);
59+
60+
$this->autoloadFunctions = spl_autoload_functions();
61+
foreach ($this->autoloadFunctions as $autoloader) {
62+
spl_autoload_unregister($autoloader);
63+
}
64+
}
65+
66+
private function reloadAutoloaders()
67+
{
68+
foreach ($this->autoloadFunctions as $autoloader) {
69+
spl_autoload_register($autoloader);
70+
}
71+
}
72+
73+
public function testRaisesAnExceptionIfDiactorosIsNotLoaded()
74+
{
75+
$this->expectException(InvalidConfigException::class);
76+
$this->expectExceptionMessage('zendframework/zend-diactoros');
77+
78+
try {
79+
$this->method->invoke($this->class, $this->container);
80+
} finally {
81+
$this->reloadAutoloaders();
82+
}
83+
}
84+
}

0 commit comments

Comments
 (0)