54 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			54 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace Tests;
 | |
| 
 | |
| use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
 | |
| use Illuminate\Support\Arr;
 | |
| use Illuminate\Testing\TestResponse;
 | |
| use PHPUnit\Framework\Assert;
 | |
| 
 | |
| 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;
 | |
|         });
 | |
|     }
 | |
| }
 | 
