Skip to content
This repository has been archived by the owner on Jul 28, 2024. It is now read-only.

Commit

Permalink
Add flash message assert
Browse files Browse the repository at this point in the history
  • Loading branch information
jfilla committed Oct 18, 2019
1 parent cd03f99 commit 4b1c82b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/NetteTests/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,9 @@ public static function getConfiguratorFactory(): callable
return self::$configuratorFactory;
}

public static function setup(): void
{
ob_start();
}

}
12 changes: 12 additions & 0 deletions src/NetteTests/TestCases/Parts/PresenterAsserts.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ protected function extractForwardResponseRequest(PresenterResponse $presenterRes
return $this->extractForwardResponse($presenterResponse)->getRequest();
}

/**
* @return array<mixed>
*/
protected function extractFlashMessages(PresenterResponse $presenterResponse): array
{
$flashes = [];
foreach ($presenterResponse->getPresenterRequest()->getPresenter()->getTemplate()->flashes as $flash) {
$flashes[] = (array)$flash;
}
return $flashes;
}

protected function runPresenter(PresenterRequest $presenterRequest): PresenterResponse
{
$this->presenters->setup($presenterRequest);
Expand Down
1 change: 1 addition & 0 deletions tests/app/config/common.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ application:

session:
expiration: 14 days
autoStart: true


services:
Expand Down
6 changes: 6 additions & 0 deletions tests/app/src/Presenters/ExamplePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ public function actionForwardResponse(): void
$this->forward('default');
}

public function actionFlash(): void
{
$this->flashMessage('Hello there!', 'warning');
$this->terminate();
}

}
15 changes: 15 additions & 0 deletions tests/app/tests/Presenters/ExamplePresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,21 @@
class ExamplePresenterTest extends PresenterTestCase
{

public function testFlashMessage(): void
{
$this->assertSame(
[
[
'message' => 'Hello there!',
'type' => 'warning',
],
],
$this->extractFlashMessages(
$this->runPresenter(new PresenterRequest(ExamplePresenter::class, 'flash'))
)
);
}

public function testAjaxRequest(): void
{
$this->assertInstanceOf(
Expand Down
1 change: 0 additions & 1 deletion tests/app/tests/Presenters/FormPresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class FormPresenterTest extends PresenterTestCase

public function testSubmitForm(): void
{
$this->assertEquals([], []);
$this->assertValidForm(
$this->submitForm(
new SubmitFormRequest(
Expand Down
1 change: 1 addition & 0 deletions tests/app/tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Wavevision\NetteTests\Configuration;

require __DIR__ . '/../../../vendor/autoload.php';
Configuration::setup();
Configuration::setConfiguratorFactory(
function (): Configurator {
$configurator = new Configurator();
Expand Down

0 comments on commit 4b1c82b

Please sign in to comment.