Implemented RequestAttribut

This commit is contained in:
Kevin Frantz 2019-01-27 11:15:07 +01:00
parent 7701bf86a8
commit 49cba2866a
3 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace App\Attribut;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*
* @see RequestAttributInterface
*/
trait RequestAttribut
{
/**
* @var Request
*/
protected $request;
/**
* @param Request $request
*/
public function setRequest(Request $request): void
{
$this->request = $request;
}
/**
* @return Request
*/
public function getRequest(): Request
{
return $this->request;
}
}

View File

@ -0,0 +1,21 @@
<?php
namespace App\Attribut;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
interface RequestAttributInterface
{
/**
* @param Request $request
*/
public function setRequest(Request $request): void;
/**
* @return Request
*/
public function getRequest(): Request;
}

View File

@ -0,0 +1,39 @@
<?php
namespace Tests\Unit\Attribut;
use PHPUnit\Framework\TestCase;
use App\Attribut\RequestAttributInterface;
use App\Attribut\RequestAttribut;
use Symfony\Component\HttpFoundation\Request;
/**
* @author kevinfrantz
*/
class RequestAttributTest extends TestCase
{
/**
* @var RequestAttributInterface
*/
protected $requestAttribut;
public function setUp(): void
{
$this->requestAttribut = new class() implements RequestAttributInterface {
use RequestAttribut;
};
}
public function testConstruct(): void
{
$this->expectException(\TypeError::class);
$this->requestAttribut->getRequest();
}
public function testAccessors(): void
{
$request = $this->createMock(Request::class);
$this->assertNull($this->requestAttribut->setRequest($request));
$this->assertEquals($request, $this->requestAttribut->getRequest());
}
}