TestCase.php
1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace Tests;
use Illuminate\Support\Arr;
use PHPUnit\Framework\Assert;
use Illuminate\Foundation\Testing\TestResponse;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp(): void
{
parent::setUp();
TestResponse::macro('props', function ($key = null) {
$props = json_decode(json_encode($this->original->getData()['page']['props']), JSON_OBJECT_AS_ARRAY);
if ($key) {
return Arr::get($props, $key);
}
return $props;
});
TestResponse::macro('assertHasProp', function ($key) {
Assert::assertTrue(Arr::has($this->props(), $key));
return $this;
});
TestResponse::macro('assertPropValue', function ($key, $value) {
$this->assertHasProp($key);
if (is_callable($value)) {
$value($this->props($key));
} else {
Assert::assertEquals($this->props($key), $value);
}
return $this;
});
TestResponse::macro('assertPropCount', function ($key, $count) {
$this->assertHasProp($key);
Assert::assertCount($count, $this->props($key));
return $this;
});
}
}