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); } }