* added some example tests
This commit is contained in:
104
test/AppTest/Action/CiConfigActionTest.php
Normal file
104
test/AppTest/Action/CiConfigActionTest.php
Normal file
@@ -0,0 +1,104 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\CiConfigAction;
|
||||
use App\Entity\CiConfig;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\CiConfigService;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
use Zend\Diactoros\Stream;
|
||||
|
||||
class CiConfigActionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $testEntity = [
|
||||
'id' => 12,
|
||||
'configItems' => []
|
||||
];
|
||||
|
||||
/** @var CiConfigService */
|
||||
protected $ciConfigService;
|
||||
|
||||
/** @var CiConfig */
|
||||
protected $entity;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->entity = $this->prophesize(CiConfig::class);
|
||||
$this->ciConfigService = $this->prophesize(CiConfigService::class);
|
||||
|
||||
$this->ciConfigService->getList()->willReturn([$this->testEntity]);
|
||||
$this->ciConfigService->get(12)->willReturn($this->testEntity);
|
||||
$this->ciConfigService->create($this->testEntity)->willReturn($this->testEntity);
|
||||
$this->ciConfigService->delete(12)->willReturn(true);
|
||||
}
|
||||
|
||||
public function testResponse()
|
||||
{
|
||||
$ciConfigPage = new CiConfigAction($this->ciConfigService->reveal());
|
||||
$response = $ciConfigPage(new ServerRequest(), new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof Response);
|
||||
}
|
||||
|
||||
public function testGetList()
|
||||
{
|
||||
$ciConfigPage = new CiConfigAction($this->ciConfigService->reveal());
|
||||
$response = $ciConfigPage(new ServerRequest(), new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof JsonCorsResponse);
|
||||
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$this->assertTrue(is_array($json));
|
||||
$first = array_shift($json);
|
||||
$this->assertObjectHasAttribute("id", $first);
|
||||
$this->assertObjectHasAttribute("configItems", $first);
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
{
|
||||
$ciConfigPage = new CiConfigAction($this->ciConfigService->reveal());
|
||||
$request = new ServerRequest();
|
||||
$response = $ciConfigPage($request->withAttribute("id", 12), new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof JsonCorsResponse);
|
||||
$json = json_decode((string) $response->getBody(), true);
|
||||
$this->assertTrue($json == $this->testEntity);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$ciConfigPage = new CiConfigAction($this->ciConfigService->reveal());
|
||||
$request = new ServerRequest();
|
||||
|
||||
$body = new Stream("php://temp", "r+");
|
||||
$body->write(json_encode($this->testEntity));
|
||||
$body->rewind();
|
||||
|
||||
$changedRequest = $request->withHeader("Content-type", "application/json")
|
||||
->withMethod("POST")
|
||||
->withBody($body);
|
||||
$response = $ciConfigPage($changedRequest, new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof JsonCorsResponse);
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$this->assertObjectHasAttribute("id", $json);
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$ciConfigPage = new CiConfigAction($this->ciConfigService->reveal());
|
||||
$request = new ServerRequest();
|
||||
$response = $ciConfigPage($request->withMethod("DELETE")->withAttribute("id", 12), new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof JsonCorsResponse);
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$this->assertTrue($json);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user