Permalink
Browse files

Add tests

  • Loading branch information...
stringerbell committed May 29, 2016
1 parent cd6bda5 commit f66c9e316f1069b16b0b866b44fbad28d9d3adf1
Showing with 53 additions and 0 deletions.
  1. +1 −0 src/App/Validator/ValidateBody.php
  2. +52 −0 test/AppTest/Validator/ValidateBodyTest.php
@@ -14,6 +14,7 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
if (!$body) {
throw new InvalidArgumentException("Invalid Body");
}
return $next($request, $response);
}
}
@@ -0,0 +1,52 @@
<?php
namespace AppTest\Validator;
use App\Validator\ValidateBody;
use Psr\Http\Message\ServerRequestInterface;
use Zend\Expressive\Container\Exception\InvalidArgumentException;
use Zend\Stratigility\Http\ResponseInterface;
class ValidateBodyTest extends \PHPUnit_Framework_TestCase
{
private $validateBody;
public function setUp()
{
$this->validateBody = new ValidateBody();
}
/**
* @test
* * @expectedException InvalidArgumentException
*/
public function itWillThrowAnExceptionWhenBodyIsInvalid()
{
/** @var ServerRequestInterface $request */
$request = $this->prophesize(ServerRequestInterface::class);
/** @var ResponseInterface $response */
$response = $this->prophesize(ResponseInterface::class);
$next = function ($request, $response) {
return $response;
};
$request->getParsedBody()->shouldBeCalled()->willReturn([]);
$result = $this->validateBody->__invoke($request->reveal(), $response->reveal(), $next);
}
/**
* @test
*/
public function itWillNotThrowAnExceptionForValidBody()
{
/** @var ServerRequestInterface $request */
$request = $this->prophesize(ServerRequestInterface::class);
/** @var ResponseInterface $response */
$response = $this->prophesize(ResponseInterface::class);
$next = function ($request, $response) {
return $response;
};
$request->getParsedBody()->shouldBeCalled()->willReturn(["foo" => "bar"]);
$result = $this->validateBody->__invoke($request->reveal(), $response->reveal(), $next);
$this->assertInstanceOf(ResponseInterface::class, $result);
}
}

0 comments on commit f66c9e3

Please sign in to comment.