Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
116 additions
and
0 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
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,31 @@ | ||
<?php | ||
|
||
namespace Reinfi\DependencyInjection\Service\AutoWiring\Resolver; | ||
use ReflectionParameter; | ||
use Reinfi\DependencyInjection\Injection\AutoWiring; | ||
use Zend\Stdlib\ResponseInterface; | ||
|
||
/** | ||
* @package Reinfi\DependencyInjection\Service\AutoWiring\Resolver | ||
*/ | ||
class ResponseResolver implements ResolverInterface | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function resolve(ReflectionParameter $parameter) | ||
{ | ||
if ($parameter->getClass() === null) { | ||
return null; | ||
} | ||
|
||
$reflectionClass = $parameter->getClass(); | ||
$interfaceNames = $reflectionClass->getInterfaceNames(); | ||
|
||
if (!in_array(ResponseInterface::class, $interfaceNames)) { | ||
return null; | ||
} | ||
|
||
return new AutoWiring('Response'); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
test/Unit/Service/AutoWiring/Resolver/ResponseResolverTest.php
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,82 @@ | ||
<?php | ||
|
||
namespace Reinfi\DependencyInjection\Unit\Service\AutoWiring\Resolver; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Reinfi\DependencyInjection\Injection\AutoWiring; | ||
use Reinfi\DependencyInjection\Service\AutoWiring\Resolver\ResponseResolver; | ||
use Zend\Http\Response; | ||
use Zend\Stdlib\ResponseInterface; | ||
|
||
/** | ||
* @package Reinfi\DependencyInjection\Unit\Service\AutoWiring\Resolver | ||
*/ | ||
class ResponseResolverTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function itReturnsInjectionInterfaceForResponseInterface() | ||
{ | ||
$resolver = new ResponseResolver(); | ||
|
||
$class = $this->prophesize(\ReflectionClass::class); | ||
$class->getInterfaceNames()->willReturn([ ResponseInterface::class ]); | ||
$parameter = $this->prophesize(\ReflectionParameter::class); | ||
$parameter->getClass()->willReturn($class->reveal()); | ||
|
||
$injection = $resolver->resolve($parameter->reveal()); | ||
|
||
$this->assertInstanceOf(AutoWiring::class, $injection); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itReturnsInjectionInterfaceForResponseClass() | ||
{ | ||
$resolver = new ResponseResolver(); | ||
|
||
$class = new \ReflectionClass(Response::class); | ||
$parameter = $this->prophesize(\ReflectionParameter::class); | ||
$parameter->getClass()->willReturn($class); | ||
|
||
$injection = $resolver->resolve($parameter->reveal()); | ||
|
||
$this->assertInstanceOf(AutoWiring::class, $injection); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itReturnsNullIfNoResponse() | ||
{ | ||
$resolver = new ResponseResolver(); | ||
|
||
$class = $this->prophesize(\ReflectionClass::class); | ||
$class->getInterfaceNames()->willReturn([]); | ||
$parameter = $this->prophesize(\ReflectionParameter::class); | ||
$parameter->getClass()->willReturn($class->reveal()); | ||
|
||
$this->assertNull( | ||
$resolver->resolve($parameter->reveal()), | ||
'return value should be null if not found' | ||
); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function itReturnsNullIfParameterHasNoClass() | ||
{ | ||
$resolver = new ResponseResolver(); | ||
|
||
$parameter = $this->prophesize(\ReflectionParameter::class); | ||
$parameter->getClass()->willReturn(null); | ||
|
||
$this->assertNull( | ||
$resolver->resolve($parameter->reveal()), | ||
'return value should be null if not found' | ||
); | ||
} | ||
} |