Laravel-Backpack /
CRUD
We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Backpack\CRUD\Tests\Unit\CrudPanel; |
||
| 4 | |||
| 5 | use Backpack\CRUD\Tests\config\CrudPanel\BaseCrudPanel; |
||
| 6 | use Backpack\CRUD\Tests\config\Models\TestModel; |
||
| 7 | use Illuminate\Database\Eloquent\Builder; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * @covers Backpack\CRUD\app\Library\CrudPanel\CrudPanel |
||
| 11 | */ |
||
| 12 | class CrudPanelTest extends BaseCrudPanel |
||
| 13 | { |
||
| 14 | public function testSetModelFromModelClass() |
||
| 15 | { |
||
| 16 | $this->crudPanel->setModel(TestModel::class); |
||
| 17 | |||
| 18 | $this->assertEquals($this->model, $this->crudPanel->model); |
||
| 19 | $this->assertInstanceOf(TestModel::class, $this->crudPanel->model); |
||
| 20 | $this->assertInstanceOf(Builder::class, $this->crudPanel->query); |
||
| 21 | } |
||
| 22 | |||
| 23 | public function testSetModelFromModelClassName() |
||
| 24 | { |
||
| 25 | $modelClassName = '\Backpack\CRUD\Tests\config\Models\TestModel'; |
||
| 26 | |||
| 27 | $this->crudPanel->setModel($modelClassName); |
||
| 28 | |||
| 29 | $this->assertEquals($this->model, $this->crudPanel->model); |
||
| 30 | $this->assertInstanceOf($modelClassName, $this->crudPanel->model); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 31 | $this->assertInstanceOf(Builder::class, $this->crudPanel->query); |
||
| 32 | } |
||
| 33 | |||
| 34 | public function testSetUnknownModel() |
||
| 35 | { |
||
| 36 | $this->expectException(\Exception::class); |
||
| 37 | |||
| 38 | $this->crudPanel->setModel('\Foo\Bar'); |
||
| 39 | } |
||
| 40 | |||
| 41 | public function testSetUnknownRouteName() |
||
| 42 | { |
||
| 43 | $this->expectException(\Exception::class); |
||
| 44 | |||
| 45 | $this->crudPanel->setRouteName('unknown.route.name'); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function testItThrowsExceptionIfModelIsNotUsingCrudTrait() |
||
| 49 | { |
||
| 50 | try { |
||
| 51 | $this->crudPanel->setModel('\Backpack\CRUD\Tests\config\Models\ModelWithoutCrudTrait'); |
||
| 52 | } catch (\Throwable $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
|
|||
| 53 | } |
||
| 54 | $this->assertEquals( |
||
| 55 | new \Exception('Please use CrudTrait on the model.', 500), |
||
| 56 | $e |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 57 | ); |
||
| 58 | } |
||
| 59 | } |
||
| 60 |