* added some example tests
This commit is contained in:
parent
c28fe6bd96
commit
217c1b599f
@ -47,7 +47,7 @@ class CiConfigService
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @return bool|object
|
||||
* @return bool|CiConfig
|
||||
*/
|
||||
public function get(int $id)
|
||||
{
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
30
test/AppTest/Action/CiConfigFactoryTest.php
Normal file
30
test/AppTest/Action/CiConfigFactoryTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\CiConfigAction;
|
||||
use App\Action\CiConfigFactory;
|
||||
use App\Service\CiConfigService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class CiConfigFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$ciConfigService = $this->prophesize(CiConfigService::class);
|
||||
|
||||
$this->container->get(CiConfigService::class)->willReturn($ciConfigService);
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new CiConfigFactory();
|
||||
$this->assertTrue($factory instanceof CiConfigFactory);
|
||||
$actionPage = $factory($this->container->reveal());
|
||||
$this->assertTrue($actionPage instanceof CiConfigAction);
|
||||
}
|
||||
}
|
||||
54
test/AppTest/Action/JcatPackageActionTest.php
Normal file
54
test/AppTest/Action/JcatPackageActionTest.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\JcatPackageAction;
|
||||
use App\Response\JsonCorsResponse;
|
||||
use App\Service\CiExecutorService;
|
||||
use Zend\Diactoros\Response;
|
||||
use Zend\Diactoros\ServerRequest;
|
||||
|
||||
class JcatPackageActionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $testJcatVersions = [
|
||||
"TSP_JCAT-138.3",
|
||||
"TSP_JCAT-138.2",
|
||||
"TSP_JCAT-138.1_TSPBUG-10203",
|
||||
"TSP_JCAT-138.1",
|
||||
"TSP_JCAT-138.0_CORE",
|
||||
"TSP_JCAT-138.0_COMMON",
|
||||
"TSP_JCAT-138.0",
|
||||
];
|
||||
|
||||
/** @var CiExecutorService */
|
||||
protected $ciExecutorService;
|
||||
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->ciExecutorService = $this->prophesize(CiExecutorService::class);
|
||||
$this->ciExecutorService->getJcatPackages()->willReturn($this->testJcatVersions);
|
||||
}
|
||||
|
||||
public function testResponse()
|
||||
{
|
||||
$ciConfigPage = new JcatPackageAction($this->ciExecutorService->reveal());
|
||||
$response = $ciConfigPage(new ServerRequest(), new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof Response);
|
||||
}
|
||||
|
||||
public function testGetList()
|
||||
{
|
||||
$ciConfigPage = new JcatPackageAction($this->ciExecutorService->reveal());
|
||||
$response = $ciConfigPage(new ServerRequest(), new Response(), function () {
|
||||
});
|
||||
|
||||
$this->assertTrue($response instanceof JsonCorsResponse);
|
||||
|
||||
$json = json_decode((string) $response->getBody());
|
||||
$this->assertTrue(is_array($json));
|
||||
$this->assertTrue($json == $this->testJcatVersions);
|
||||
}
|
||||
}
|
||||
30
test/AppTest/Action/JcatPackageFactoryTest.php
Normal file
30
test/AppTest/Action/JcatPackageFactoryTest.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace AppTest\Action;
|
||||
|
||||
use App\Action\JcatPackageAction;
|
||||
use App\Action\JcatPackageFactory;
|
||||
use App\Service\CiExecutorService;
|
||||
use Interop\Container\ContainerInterface;
|
||||
|
||||
class JcatPackageFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var ContainerInterface */
|
||||
protected $container;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->container = $this->prophesize(ContainerInterface::class);
|
||||
$ciExecutorService = $this->prophesize(CiExecutorService::class);
|
||||
|
||||
$this->container->get(CiExecutorService::class)->willReturn($ciExecutorService);
|
||||
}
|
||||
|
||||
public function testFactory()
|
||||
{
|
||||
$factory = new JcatPackageFactory();
|
||||
$this->assertTrue($factory instanceof JcatPackageFactory);
|
||||
$actionPage = $factory($this->container->reveal());
|
||||
$this->assertTrue($actionPage instanceof JcatPackageAction);
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user