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\CrudTrait; |
||
4 | |||
5 | use Backpack\CRUD\Tests\config\CrudTrait\BaseCrudTrait; |
||
6 | use Backpack\CRUD\Tests\config\Models\FakeColumnsModel; |
||
7 | |||
8 | /** |
||
9 | * Class CrudTraitFakeFieldsTest. |
||
10 | * |
||
11 | * @group CrudTraitFakeFields |
||
12 | * |
||
13 | * @covers Backpack\CRUD\app\Models\Traits\HasFakeFields |
||
14 | */ |
||
15 | class CrudTraitFakeFieldsTest extends BaseCrudTrait |
||
16 | { |
||
17 | private $locale; |
||
18 | /** |
||
19 | * @var FakeColumnsModel |
||
20 | */ |
||
21 | private $model; |
||
22 | |||
23 | // DEFINE THE DATA |
||
24 | |||
25 | private $extras = [ |
||
26 | 'extras_first' => 'Extras first', |
||
27 | 'extras_second' => 'Extras second', |
||
28 | ]; |
||
29 | |||
30 | private $extras_translatable = [ |
||
31 | 'en' => [ |
||
32 | 'extras_translatable_first' => 'extras_translatable first en', |
||
33 | 'extras_translatable_second' => 'extras_translatable second en', |
||
34 | ], |
||
35 | 'ro' => [ |
||
36 | 'extras_translatable_first' => 'extras_translatable first ro', |
||
37 | 'extras_translatable_second' => 'extras_translatable second ro', |
||
38 | ], |
||
39 | |||
40 | ]; |
||
41 | |||
42 | private $fake_object = [ |
||
43 | 'fake_object_first' => 'fake_object first', |
||
44 | 'fake_object_second' => 'fake_object second', |
||
45 | ]; |
||
46 | |||
47 | private $fake_assoc_array = [ |
||
48 | 'fake_assoc_array_first' => 'fake_assoc_array first', |
||
49 | 'fake_assoc_array_second' => 'fake_assoc_array second', |
||
50 | ]; |
||
51 | |||
52 | /** |
||
53 | * Setup function for each test. |
||
54 | */ |
||
55 | protected function setUp(): void |
||
56 | { |
||
57 | parent::setUp(); |
||
58 | |||
59 | $this->locale = \App::getLocale(); |
||
60 | |||
61 | $this->fake_object = (object) $this->fake_object; |
||
62 | |||
63 | $this->model = new FakeColumnsModel(); |
||
64 | |||
65 | $this->model->extras = json_encode($this->extras); |
||
0 ignored issues
–
show
|
|||
66 | |||
67 | $this->model->setTranslation('extras_translatable', 'en', json_encode($this->extras_translatable['en'])); |
||
68 | $this->model->setTranslation('extras_translatable', 'ro', json_encode($this->extras_translatable['ro'])); |
||
69 | |||
70 | $this->model->fake_object = $this->fake_object; |
||
0 ignored issues
–
show
|
|||
71 | $this->model->fake_assoc_array = $this->fake_assoc_array; |
||
0 ignored issues
–
show
|
|||
72 | |||
73 | $this->model = $this->model->withFakes(); |
||
74 | } |
||
75 | |||
76 | public function testExtrasGetFaked() |
||
77 | { |
||
78 | $this->assertEquals($this->extras, json_decode($this->model->extras, true)); |
||
0 ignored issues
–
show
|
|||
79 | |||
80 | $this->assertEquals($this->extras['extras_first'], $this->model->extras_first); |
||
0 ignored issues
–
show
|
|||
81 | $this->assertEquals($this->extras['extras_second'], $this->model->extras_second); |
||
0 ignored issues
–
show
|
|||
82 | } |
||
83 | |||
84 | public function testExtrasTranslatableGetFaked() |
||
85 | { |
||
86 | $this->assertEquals($this->extras_translatable[$this->locale], json_decode($this->model->extras_translatable, true)); |
||
0 ignored issues
–
show
|
|||
87 | |||
88 | $this->assertEquals($this->extras_translatable[$this->locale]['extras_translatable_first'], $this->model->extras_translatable_first); |
||
0 ignored issues
–
show
|
|||
89 | $this->assertEquals($this->extras_translatable[$this->locale]['extras_translatable_second'], $this->model->extras_translatable_second); |
||
0 ignored issues
–
show
|
|||
90 | } |
||
91 | |||
92 | public function testFakeObjectGetsFaked() |
||
93 | { |
||
94 | $this->assertEquals($this->fake_object, $this->model->fake_object); |
||
0 ignored issues
–
show
|
|||
95 | |||
96 | $this->assertEquals($this->fake_object->fake_object_first, $this->model->fake_object->fake_object_first); |
||
97 | $this->assertEquals($this->fake_object->fake_object_first, $this->model->fake_object_first); |
||
0 ignored issues
–
show
|
|||
98 | |||
99 | $this->assertEquals($this->fake_object->fake_object_second, $this->model->fake_object->fake_object_second); |
||
100 | $this->assertEquals($this->fake_object->fake_object_second, $this->model->fake_object_second); |
||
0 ignored issues
–
show
|
|||
101 | } |
||
102 | |||
103 | public function testFakeAssocArrayGetsFaked() |
||
104 | { |
||
105 | $this->assertEquals($this->fake_assoc_array, $this->model->fake_assoc_array); |
||
0 ignored issues
–
show
|
|||
106 | |||
107 | $this->assertEquals($this->fake_assoc_array['fake_assoc_array_first'], $this->model->fake_assoc_array['fake_assoc_array_first']); |
||
108 | $this->assertEquals($this->fake_assoc_array['fake_assoc_array_first'], $this->model->fake_assoc_array_first); |
||
0 ignored issues
–
show
|
|||
109 | |||
110 | $this->assertEquals($this->fake_assoc_array['fake_assoc_array_second'], $this->model->fake_assoc_array['fake_assoc_array_second']); |
||
111 | $this->assertEquals($this->fake_assoc_array['fake_assoc_array_second'], $this->model->fake_assoc_array_second); |
||
0 ignored issues
–
show
|
|||
112 | } |
||
113 | } |
||
114 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.