HummingBirdAnimeClient/tests/Ion/View/HttpViewTest.php

109 lines
2.8 KiB
PHP
Raw Permalink Normal View History

<?php declare(strict_types=1);
/**
2020-03-12 11:45:11 -04:00
* Hummingbird Anime List Client
*
2020-03-12 11:45:11 -04:00
* An API client for Kitsu to manage anime and manga watch lists
*
2023-07-13 11:08:05 -04:00
* PHP version 8.1
*
2023-07-13 11:08:05 -04:00
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2023-07-13 11:08:05 -04:00
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\Ion\Tests\View;
use Aviat\Ion\Exception\DoubleRenderException;
2022-03-04 12:19:47 -05:00
use Aviat\Ion\Friend;
use Aviat\Ion\Tests\{IonTestCase, TestHttpView};
2022-03-04 12:19:47 -05:00
class HttpViewTest extends IonTestCase
{
protected $view;
protected $friend;
2022-03-04 12:19:47 -05:00
protected function setUp(): void
{
parent::setUp();
2020-07-31 16:22:32 -04:00
$this->view = new TestHttpView();
$this->view = TestHttpView::new();
$this->friend = new Friend($this->view);
}
2022-03-04 12:19:47 -05:00
public function testGetOutput(): void
{
$this->friend->setOutput('foo');
2022-03-04 12:19:47 -05:00
$this->assertSame('foo', $this->friend->getOutput());
$this->assertFalse($this->friend->hasRendered);
2022-03-04 12:19:47 -05:00
$this->assertSame($this->friend->getOutput(), $this->friend->__toString());
$this->assertTrue($this->friend->hasRendered);
}
2022-03-04 12:19:47 -05:00
public function testSetOutput(): void
{
$same = $this->view->setOutput('<h1></h1>');
2022-03-04 12:19:47 -05:00
$this->assertSame($same, $this->view);
$this->assertSame('<h1></h1>', $this->view->getOutput());
}
2022-03-04 12:19:47 -05:00
public function testAppendOutput(): void
{
$this->view->setOutput('<h1>');
$this->view->appendOutput('</h1>');
2022-03-04 12:19:47 -05:00
$this->assertSame('<h1></h1>', $this->view->getOutput());
}
2022-03-04 12:19:47 -05:00
public function testSetStatusCode(): void
{
$view = $this->view->setStatusCode(404);
2022-03-04 12:19:47 -05:00
$this->assertSame(404, $view->response->getStatusCode());
}
2022-03-04 12:19:47 -05:00
public function testAddHeader(): void
{
$view = $this->view->addHeader('foo', 'bar');
$this->assertTrue($view->response->hasHeader('foo'));
2022-03-04 12:19:47 -05:00
$this->assertSame(['bar'], $view->response->getHeader('foo'));
}
2022-03-04 12:19:47 -05:00
public function testSendDoubleRenderException(): void
{
$this->expectException(DoubleRenderException::class);
$this->expectExceptionMessage('A view can only be rendered once, because headers can only be sent once.');
// First render
$this->view->__toString();
// Second render
$this->view->send();
}
2022-03-04 12:19:47 -05:00
public function testToStringDoubleRenderException(): void
{
$this->expectException(DoubleRenderException::class);
$this->expectExceptionMessage('A view can only be rendered once, because headers can only be sent once.');
// First render
$this->view->send();
// Second render
$this->view->__toString();
}
2020-12-10 15:59:37 -05:00
public function testRedirect(): void
{
$this->friend->redirect('http://example.com');
$this->assertInstanceOf(\Laminas\Diactoros\Response\RedirectResponse::class, $this->friend->response);
}
public function testOutput(): void
{
$this->friend->setOutput('<h1></h1>');
$this->friend->send();
$this->assertTrue($this->friend->hasRendered);
}
2022-03-04 12:19:47 -05:00
}