This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'hotfix/18' into release-1.0.0
Close #18 Close zendframework/zend-expressive#569
- Loading branch information
Showing
7 changed files
with
230 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |