akalongman /
laravel-lodash
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Tests\Unit\Testing; |
||
| 6 | |||
| 7 | use Illuminate\Testing\Assert as PHPUnit; |
||
| 8 | use Tests\Unit\TestCase; |
||
| 9 | |||
| 10 | use function is_array; |
||
| 11 | |||
| 12 | class DataStructuresBuilderTest extends TestCase |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @test |
||
| 16 | * |
||
| 17 | * @dataProvider provideData |
||
| 18 | */ |
||
| 19 | public function it_should_return_corrct_data_structures(array $structure, array $data): void |
||
| 20 | { |
||
| 21 | $this->assertStructure($structure, $data); |
||
| 22 | } |
||
| 23 | |||
| 24 | public function provideData(): array |
||
| 25 | { |
||
| 26 | $provider = new ItemStructuresProvider(); |
||
| 27 | |||
| 28 | return [ |
||
| 29 | 'user' => [ |
||
| 30 | $provider->getUserStructure(), |
||
| 31 | [ |
||
| 32 | 'id' => '', |
||
| 33 | 'type' => '', |
||
| 34 | 'attributes' => [ |
||
| 35 | 'uid' => '', |
||
| 36 | 'firstName' => '', |
||
| 37 | 'lastName' => '', |
||
| 38 | 'fullName' => '', |
||
| 39 | 'email' => '', |
||
| 40 | 'avatar' => '', |
||
| 41 | 'photoUrl' => '', |
||
| 42 | ], |
||
| 43 | ], |
||
| 44 | ], |
||
| 45 | 'user_with_profiles' => [ |
||
| 46 | $provider->getUserStructure(['[profiles:userProfile]']), |
||
| 47 | [ |
||
| 48 | 'id' => '', |
||
| 49 | 'type' => '', |
||
| 50 | 'attributes' => [ |
||
| 51 | 'uid' => '', |
||
| 52 | 'firstName' => '', |
||
| 53 | 'lastName' => '', |
||
| 54 | 'fullName' => '', |
||
| 55 | 'email' => '', |
||
| 56 | 'avatar' => '', |
||
| 57 | 'photoUrl' => '', |
||
| 58 | ], |
||
| 59 | 'relationships' => [ |
||
| 60 | 'profiles' => [ |
||
| 61 | 'data' => [ |
||
| 62 | [ |
||
| 63 | 'type' => '', |
||
| 64 | 'id' => '', |
||
| 65 | 'attributes' => [ |
||
| 66 | 'type' => '', |
||
| 67 | 'degree' => '', |
||
| 68 | ], |
||
| 69 | ], |
||
| 70 | ], |
||
| 71 | ], |
||
| 72 | ], |
||
| 73 | ], |
||
| 74 | ], |
||
| 75 | 'user_with_profiles_and_status' => [ |
||
| 76 | $provider->getUserStructure([ |
||
| 77 | '[profiles:userProfile]', |
||
| 78 | '[profiles].profileStatus', |
||
| 79 | ]), |
||
| 80 | [ |
||
| 81 | 'id' => '', |
||
| 82 | 'type' => '', |
||
| 83 | 'attributes' => [ |
||
| 84 | 'uid' => '', |
||
| 85 | 'firstName' => '', |
||
| 86 | 'lastName' => '', |
||
| 87 | 'fullName' => '', |
||
| 88 | 'email' => '', |
||
| 89 | 'avatar' => '', |
||
| 90 | 'photoUrl' => '', |
||
| 91 | ], |
||
| 92 | 'relationships' => [ |
||
| 93 | 'profiles' => [ |
||
| 94 | 'data' => [ |
||
| 95 | [ |
||
| 96 | 'type' => '', |
||
| 97 | 'id' => '', |
||
| 98 | 'attributes' => [ |
||
| 99 | 'type' => '', |
||
| 100 | 'degree' => '', |
||
| 101 | ], |
||
| 102 | 'relationships' => [ |
||
| 103 | 'profileStatus' => [ |
||
| 104 | 'data' => [ |
||
| 105 | 'type' => '', |
||
| 106 | 'id' => '', |
||
| 107 | 'attributes' => [ |
||
| 108 | 'status' => '', |
||
| 109 | 'message' => '', |
||
| 110 | ], |
||
| 111 | ], |
||
| 112 | ], |
||
| 113 | ], |
||
| 114 | ], |
||
| 115 | ], |
||
| 116 | ], |
||
| 117 | ], |
||
| 118 | ], |
||
| 119 | ], |
||
| 120 | 'user_with_profiles_and_status_and_sub_sub' => [ |
||
| 121 | $provider->getUserStructure([ |
||
| 122 | '[profiles:userProfile]', |
||
| 123 | '[profiles].profileStatus', |
||
| 124 | '[profiles].profileStatus.[lecturers:user]', |
||
| 125 | ]), |
||
| 126 | [ |
||
| 127 | 'id' => '', |
||
| 128 | 'type' => '', |
||
| 129 | 'attributes' => [ |
||
| 130 | 'uid' => '', |
||
| 131 | 'firstName' => '', |
||
| 132 | 'lastName' => '', |
||
| 133 | 'fullName' => '', |
||
| 134 | 'email' => '', |
||
| 135 | 'avatar' => '', |
||
| 136 | 'photoUrl' => '', |
||
| 137 | ], |
||
| 138 | 'relationships' => [ |
||
| 139 | 'profiles' => [ |
||
| 140 | 'data' => [ |
||
| 141 | [ |
||
| 142 | 'type' => '', |
||
| 143 | 'id' => '', |
||
| 144 | 'attributes' => [ |
||
| 145 | 'type' => '', |
||
| 146 | 'degree' => '', |
||
| 147 | ], |
||
| 148 | 'relationships' => [ |
||
| 149 | 'profileStatus' => [ |
||
| 150 | 'data' => [ |
||
| 151 | 'type' => '', |
||
| 152 | 'id' => '', |
||
| 153 | 'attributes' => [ |
||
| 154 | 'status' => '', |
||
| 155 | 'message' => '', |
||
| 156 | ], |
||
| 157 | 'relationships' => [ |
||
| 158 | 'lecturers' => [ |
||
| 159 | 'data' => [ |
||
| 160 | [ |
||
| 161 | 'id' => '', |
||
| 162 | 'type' => '', |
||
| 163 | 'attributes' => [ |
||
| 164 | 'uid' => '', |
||
| 165 | 'firstName' => '', |
||
| 166 | 'lastName' => '', |
||
| 167 | 'fullName' => '', |
||
| 168 | 'email' => '', |
||
| 169 | 'avatar' => '', |
||
| 170 | 'photoUrl' => '', |
||
| 171 | ], |
||
| 172 | ], |
||
| 173 | ], |
||
| 174 | ], |
||
| 175 | ], |
||
| 176 | ], |
||
| 177 | ], |
||
| 178 | ], |
||
| 179 | ], |
||
| 180 | ], |
||
| 181 | ], |
||
| 182 | ], |
||
| 183 | ], |
||
| 184 | ], |
||
| 185 | ]; |
||
| 186 | } |
||
| 187 | |||
| 188 | private function assertStructure(array $structure, array $responseData): self |
||
| 189 | { |
||
| 190 | foreach ($structure as $key => $value) { |
||
| 191 | if (is_array($value) && $key === '*') { |
||
| 192 | PHPUnit::assertIsArray($responseData); |
||
| 193 | |||
| 194 | foreach ($responseData as $responseDataItem) { |
||
| 195 | $this->assertStructure($structure['*'], $responseDataItem); |
||
| 196 | } |
||
| 197 | } elseif (is_array($value)) { |
||
| 198 | PHPUnit::assertArrayHasKey($key, $responseData); |
||
| 199 | |||
| 200 | $this->assertStructure($structure[$key], $responseData[$key]); |
||
| 201 | } else { |
||
| 202 | PHPUnit::assertArrayHasKey($value, $responseData); |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | return $this; |
||
| 207 | } |
||
| 208 | } |
||
| 209 |