Files
PHP-App-Timekeeping/api/tests/unit/Controller/AbstractControllerTest.php
T
2025-05-03 09:27:39 +02:00

53 lines
1.8 KiB
PHP

<?php
namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
use Codeception\Test\Unit;
use Exception;
use PDO;
use PHPUnit\Framework\MockObject\MockObject;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\StreamInterface;
use Slim\Psr7\Request;
use Slim\Psr7\Response;
class AbstractControllerTest extends Unit
{
protected const FICTIONAL_STATUS_CODE = 666;
protected ContainerInterface $container;
protected Request $request;
protected Response|MockObject $response;
/**
* @throws Exception
* @throws \PHPUnit\Framework\MockObject\Exception
*/
protected function _before(): void
{
parent::_before();
/** @noinspection SpellCheckingInspection */
$this->container = $this->makeEmpty(ContainerInterface::class, [
'has' => true,
'get' => new PDO(
'pgsql:host=psql.torsten-hettstedt.net;port=5432;dbname=testdb;user=bruce;password=mypass'
),
]);
$this->response = $this->createMock(Response::class);
$this->response->expects($this->any())->method('getStatusCode')->willReturn(self::FICTIONAL_STATUS_CODE);
$this->response->expects($this->any())->method('getBody')->willReturn(
$this->makeEmpty(StreamInterface::class, [
'write' => function (mixed $data) {
$this->assertIsString($data);
$this->assertJson($data);
return strlen($data);
},
'getContents' => 'abc',
])
);
$this->response->expects($this->any())->method('withHeader')->willReturn($this->response);
$this->response->expects($this->any())->method('withStatus')->willReturn($this->response);
}
}