|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | +/** |
| 5 | + * This file is part of Hyperf. |
| 6 | + * |
| 7 | + * @link https://www.hyperf.io |
| 8 | + * @document https://hyperf.wiki |
| 9 | + * @contact group@hyperf.io |
| 10 | + * @license https://github.com/hyperf/hyperf/blob/master/LICENSE |
| 11 | + */ |
| 12 | +namespace HyperfTest\Cases; |
| 13 | + |
| 14 | +use App\ApiJson\Parse\Parse; |
| 15 | +use PHPUnit\Framework\TestCase; |
| 16 | + |
| 17 | +/** |
| 18 | + * @internal |
| 19 | + * @coversNothing |
| 20 | + */ |
| 21 | +class GetTest extends TestCase |
| 22 | +{ |
| 23 | + protected string $method = 'GET'; |
| 24 | + |
| 25 | + public function testColumn() |
| 26 | + { |
| 27 | + $json = [ |
| 28 | + 'User' => [ |
| 29 | + 'id' => 1, |
| 30 | + '@column' => 'id' |
| 31 | + ] |
| 32 | + ]; |
| 33 | + $parse = new Parse($json, $this->method, ''); |
| 34 | + $result = $parse->handle(); |
| 35 | + |
| 36 | + $this->assertSame([ |
| 37 | + 'User' => [ |
| 38 | + 'id' => 1 |
| 39 | + ] |
| 40 | + ], $result); |
| 41 | + } |
| 42 | + |
| 43 | + public function testWhere() |
| 44 | + { |
| 45 | + $json = [ |
| 46 | + 'User' => [ |
| 47 | + 'id' => 1 |
| 48 | + ] |
| 49 | + ]; |
| 50 | + $parse = new Parse($json, $this->method, ''); |
| 51 | + $result = $parse->handle(); |
| 52 | + |
| 53 | + $this->assertSame([ |
| 54 | + 'User' => [ |
| 55 | + 'id' => 1, |
| 56 | + 'username' => 'abigeater', |
| 57 | + 'email' => 'abigeater@163.com', |
| 58 | + 'password' => '1', |
| 59 | + 'create_time' => '2021-11-02 06:57:56' |
| 60 | + ] |
| 61 | + ], $result); |
| 62 | + } |
| 63 | + |
| 64 | + public function testWhereIn() |
| 65 | + { |
| 66 | + $json = [ |
| 67 | + 'User[]' => [ |
| 68 | + 'id{}' => [1,2] |
| 69 | + ] |
| 70 | + ]; |
| 71 | + $parse = new Parse($json, $this->method, ''); |
| 72 | + $result = $parse->handle(); |
| 73 | + |
| 74 | + $this->assertSame([ |
| 75 | + 'User[]' => [ |
| 76 | + [ |
| 77 | + 'id' => 1, |
| 78 | + 'username' => 'abigeater', |
| 79 | + 'email' => 'abigeater@163.com', |
| 80 | + 'password' => '1', |
| 81 | + 'create_time' => '2021-11-02 06:57:56' |
| 82 | + ] |
| 83 | + ] |
| 84 | + ], $result); |
| 85 | + } |
| 86 | + |
| 87 | + public function testWhereQueryMany() |
| 88 | + { |
| 89 | + $json = [ |
| 90 | + 'User[]' => [ |
| 91 | + ] |
| 92 | + ]; |
| 93 | + $parse = new Parse($json, $this->method, ''); |
| 94 | + $result = $parse->handle(); |
| 95 | + |
| 96 | + $this->assertSame([ |
| 97 | + 'User[]' => [ |
| 98 | + [ |
| 99 | + 'id' => 1, |
| 100 | + 'username' => 'abigeater', |
| 101 | + 'email' => 'abigeater@163.com', |
| 102 | + 'password' => '1', |
| 103 | + 'create_time' => '2021-11-02 06:57:56' |
| 104 | + ] |
| 105 | + ] |
| 106 | + ], $result); |
| 107 | + } |
| 108 | + |
| 109 | + public function testWhereCondition() |
| 110 | + { |
| 111 | + $json = [ |
| 112 | + 'User' => [ |
| 113 | + 'id{}' => '>0,<=1' |
| 114 | + ] |
| 115 | + ]; |
| 116 | + $parse = new Parse($json, $this->method, ''); |
| 117 | + $result = $parse->handle(); |
| 118 | + |
| 119 | + $this->assertSame([ |
| 120 | + 'User' => [ |
| 121 | + 'id' => 1, |
| 122 | + 'username' => 'abigeater', |
| 123 | + 'email' => 'abigeater@163.com', |
| 124 | + 'password' => '1', |
| 125 | + 'create_time' => '2021-11-02 06:57:56' |
| 126 | + ] |
| 127 | + ], $result); |
| 128 | + |
| 129 | + $json = [ |
| 130 | + 'User' => [ |
| 131 | + 'id{}' => '>1,<1' |
| 132 | + ] |
| 133 | + ]; |
| 134 | + $parse = new Parse($json, $this->method, ''); |
| 135 | + $result = $parse->handle(); |
| 136 | + |
| 137 | + $this->assertSame([ |
| 138 | + 'User' => [] |
| 139 | + ], $result); |
| 140 | + } |
| 141 | + |
| 142 | + public function testWhereArray() |
| 143 | + { |
| 144 | + $json = [ |
| 145 | + '[]' => [ |
| 146 | + 'count'=> 10, |
| 147 | + 'page' => 1, |
| 148 | + 'User' => [ |
| 149 | + 'username' => 'abigeater' |
| 150 | + ] |
| 151 | + ] |
| 152 | + ]; |
| 153 | + $parse = new Parse($json, $this->method, ''); |
| 154 | + $result = $parse->handle(); |
| 155 | + |
| 156 | + $this->assertSame([ |
| 157 | + '[]' => [ |
| 158 | + [ |
| 159 | + 'User' => [ |
| 160 | + 'id' => 1, |
| 161 | + 'username' => 'abigeater', |
| 162 | + 'email' => 'abigeater@163.com', |
| 163 | + 'password' => '1', |
| 164 | + 'create_time' => '2021-11-02 06:57:56' |
| 165 | + ] |
| 166 | + ] |
| 167 | + ] |
| 168 | + ], $result); |
| 169 | + } |
| 170 | + |
| 171 | + public function testQueryManyTable() |
| 172 | + { |
| 173 | + $json = [ |
| 174 | + 'User' => [ |
| 175 | + 'username' => 'abigeater' |
| 176 | + ], |
| 177 | + 'Message' => [ |
| 178 | + ], |
| 179 | + ]; |
| 180 | + $parse = new Parse($json, $this->method, ''); |
| 181 | + $result = $parse->handle(); |
| 182 | + |
| 183 | + $this->assertSame([ |
| 184 | + 'User' => [ |
| 185 | + 'id' => 1, |
| 186 | + 'username' => 'abigeater', |
| 187 | + 'email' => 'abigeater@163.com', |
| 188 | + 'password' => '1', |
| 189 | + 'create_time' => '2021-11-02 06:57:56' |
| 190 | + ], |
| 191 | + 'Message' => [ |
| 192 | + 'id' => 12, |
| 193 | + 'user_id' => 1, |
| 194 | + 'watched_message_id' => '2' |
| 195 | + ] |
| 196 | + ], $result); |
| 197 | + } |
| 198 | + |
| 199 | + public function testQueryOneOne() |
| 200 | + { |
| 201 | + $json = [ |
| 202 | + 'Message' => [ |
| 203 | + ], |
| 204 | + 'User' => [ |
| 205 | + 'id@' => 'Message/user_id' |
| 206 | + ], |
| 207 | + ]; |
| 208 | + $parse = new Parse($json, $this->method, ''); |
| 209 | + $result = $parse->handle(); |
| 210 | + |
| 211 | + $this->assertSame([ |
| 212 | + 'Message' => [ |
| 213 | + 'id' => 12, |
| 214 | + 'user_id' => 1, |
| 215 | + 'watched_message_id' => '2' |
| 216 | + ], |
| 217 | + 'User' => [ |
| 218 | + 'id' => 1, |
| 219 | + 'username' => 'abigeater', |
| 220 | + 'email' => 'abigeater@163.com', |
| 221 | + 'password' => '1', |
| 222 | + 'create_time' => '2021-11-02 06:57:56' |
| 223 | + ] |
| 224 | + ], $result); |
| 225 | + } |
| 226 | + |
| 227 | + public function testQueryOneMany() |
| 228 | + { |
| 229 | + $json = [ |
| 230 | + 'User' => [ |
| 231 | + 'id' => 1 |
| 232 | + ], |
| 233 | + '[]' => [ |
| 234 | + 'Message' => [ |
| 235 | + "user_id@" => "User/id" |
| 236 | + ], |
| 237 | + ] |
| 238 | + ]; |
| 239 | + $parse = new Parse($json, $this->method, ''); |
| 240 | + $result = $parse->handle(); |
| 241 | + |
| 242 | + $this->assertSame([ |
| 243 | + 'User' => [ |
| 244 | + 'id' => 1, |
| 245 | + 'username' => 'abigeater', |
| 246 | + 'email' => 'abigeater@163.com', |
| 247 | + 'password' => '1', |
| 248 | + 'create_time' => '2021-11-02 06:57:56' |
| 249 | + ], |
| 250 | + '[]' => [ |
| 251 | + [ |
| 252 | + 'Message' => [ |
| 253 | + 'id' => 12, |
| 254 | + 'user_id' => 1, |
| 255 | + 'watched_message_id' => '2' |
| 256 | + ], |
| 257 | + ] |
| 258 | + ] |
| 259 | + ], $result); |
| 260 | + } |
| 261 | + |
| 262 | + public function testQueryArrayOneOne() |
| 263 | + { |
| 264 | + $json = [ |
| 265 | + '[]' => [ |
| 266 | + 'Message' => [], |
| 267 | + 'User' => [ |
| 268 | + "id@" => "[]/Message/user_id" |
| 269 | + ], |
| 270 | + ] |
| 271 | + ]; |
| 272 | + $parse = new Parse($json, $this->method, ''); |
| 273 | + $result = $parse->handle(); |
| 274 | + |
| 275 | + $this->assertSame([ |
| 276 | + '[]' => [ |
| 277 | + [ |
| 278 | + 'Message' => [ |
| 279 | + 'id' => 12, |
| 280 | + 'user_id' => 1, |
| 281 | + 'watched_message_id' => '2' |
| 282 | + ], |
| 283 | + 'User' => [ |
| 284 | + 'id' => 1, |
| 285 | + 'username' => 'abigeater', |
| 286 | + 'email' => 'abigeater@163.com', |
| 287 | + 'password' => '1', |
| 288 | + 'create_time' => '2021-11-02 06:57:56' |
| 289 | + ] |
| 290 | + ] |
| 291 | + ] |
| 292 | + ], $result); |
| 293 | + } |
| 294 | +} |
0 commit comments