renderer = $this->prophesize(RendererInterface::class); $this->regionTable = $this->prophesize(RegionTable::class); // PDO $this->router = $this->prophesize(Router::class); $this->action = new GmarcheAction( $this->renderer->reveal(), $this->router->reveal(), $this->regionTable->reveal() ); } public function makeRegion(int $id, string $slug): \stdClass { // RĂ©gion $region = new \stdClass(); $region->id = $id; $region->slug = $slug; return $region; } public function testShowRedirect() { $region = $this->makeRegion(9, "azezae-azeazae"); $request = (new ServerRequest('GET', '/')) ->withAttribute('id', $region->id) ->withAttribute('slug', 'demo'); $this->router->generateUri( 'gmarche.show', ['id' => $region->id, 'slug' => $region->slug] )->willReturn('/demo2'); $this->regionTable->find($region->id)->willReturn($region); $response = call_user_func_array($this->action, [$request]); $this->assertEquals(301, $response->getStatusCode()); $this->assertEquals(['/demo2'], $response->getHeader('location')); } public function testShowRender() { $region = $this->makeRegion(9, "azezae-azeazae"); $request = (new ServerRequest('GET', '/')) ->withAttribute('id', $region->id) ->withAttribute('slug', $region->slug); $this->regionTable->find($region->id)->willReturn($region); $this->renderer->render('@gmarche/show', ['region' => $region])->willReturn(''); $response = call_user_func_array($this->action, [$request]); $this->assertEquals(true, true); } }