Files
ppeasy_vg12/tests/TestCase.php
T
2026-10-09 08:21:06 +02:00

62 lines
1.4 KiB
PHP

<?php
namespace Tests;
use Facades\Tests\Setup\UserFactory;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
/**
* Assert that session has provided error.
*/
protected function assertSessionHasError($message)
{
$errors = session()->get('errors')->getBag('default');
$this->assertEquals($message, $errors->first());
}
/**
* Assert that session has provided error.
*/
protected function assertSessionHasSuccess($message)
{
$this->assertEquals($message, session()->get('success'));
}
/**
* Assert that session has the provided flashed error.
*
* The sibling above reads the error bag, which is where a failed
* validation lands. This one reads the flash key the layouts turn into a
* toast, which is where back()->with('error', ...) lands.
*/
protected function assertSessionHasFlashError($message)
{
$this->assertEquals($message, session()->get('error'));
}
/**
* Create and log in an admin user.
*
* @return TestCase
*/
protected function beAdmin()
{
return $this->actingAsAdmin();
}
/**
* Create and log in an admin user.
*
* @return TestCase
*/
protected function actingAsAdmin()
{
$this->be(UserFactory::admin()->create());
return $this;
}
}