Skip to content

Commit 80f6a8e

Browse files
committed
Add assertResponseHasNoView macro to TestCase
1 parent 9b9c5eb commit 80f6a8e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tests/TestCase.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use CodeZero\LocalizedRoutes\LocalizedRoutesServiceProvider;
66
use CodeZero\Localizer\LocalizerServiceProvider;
7+
use Illuminate\Contracts\View\View;
8+
use Illuminate\Foundation\Testing\Assert as PHPUnit;
9+
use Illuminate\Foundation\Testing\TestResponse;
710
use Illuminate\Support\Collection;
811
use Illuminate\Support\Facades\App;
912
use Illuminate\Support\Facades\Config;
@@ -12,6 +15,24 @@
1215

1316
abstract class TestCase extends BaseTestCase
1417
{
18+
/**
19+
* Setup the test environment.
20+
*
21+
* @return void
22+
*/
23+
protected function setUp(): void
24+
{
25+
parent::setUp();
26+
27+
TestResponse::macro('assertResponseHasNoView', function () {
28+
if (isset($this->original) && $this->original instanceof View) {
29+
return PHPUnit::fail('The response has a view.');
30+
}
31+
32+
return $this;
33+
});
34+
}
35+
1536
/**
1637
* Set the app locale.
1738
*

0 commit comments

Comments
 (0)