81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\App\Gmarche\Actions;
|
|
|
|
use App\Gmarche\Actions\GmarcheAction;
|
|
use App\Gmarche\Table\RegionTable;
|
|
use Framework\Renderer\RendererInterface;
|
|
use Framework\Router;
|
|
use GuzzleHttp\Psr7\Request;
|
|
use GuzzleHttp\Psr7\ServerRequest;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Prophecy\Argument;
|
|
|
|
class GmarcheActionTest extends TestCase
|
|
{
|
|
|
|
/**
|
|
* @var GmarcheAction
|
|
*/
|
|
private $action;
|
|
|
|
private $renderer;
|
|
|
|
private $regionTable;
|
|
|
|
private $router;
|
|
|
|
public function setUp()
|
|
{
|
|
$this->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);
|
|
}
|
|
|
|
} |