|
64 | 64 | ->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
65 | 65 | ->inject('response')
|
66 | 66 | ->action(function (Response $response) {
|
67 |
| - $response->json(['version' => '1.0.0']); |
| 67 | + $response->json([ 'version' => '1.0.0' ]); |
68 | 68 | });
|
69 | 69 |
|
70 | 70 | // Mock Routes
|
|
292 | 292 | ->label('sdk.mock', true)
|
293 | 293 | ->inject('response')
|
294 | 294 | ->action(function (Response $response) {
|
| 295 | + |
295 | 296 | $response
|
296 | 297 | ->setContentType('text/plain')
|
297 | 298 | ->addHeader('Content-Disposition', 'attachment; filename="test.txt"')
|
|
316 | 317 | ->param('x', '', new Text(100), 'Sample string param')
|
317 | 318 | ->param('y', '', new Integer(true), 'Sample numeric param')
|
318 | 319 | ->param('z', null, new ArrayList(new Text(256), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Sample array param')
|
319 |
| - ->param('file', [], new File(), 'Sample file param', skipValidation: true) |
| 320 | + ->param('payload', [], new File(), 'Sample file param', skipValidation: true) |
320 | 321 | ->inject('request')
|
321 | 322 | ->inject('response')
|
322 | 323 | ->action(function (string $x, int $y, array $z, mixed $file, Request $request, Response $response) {
|
| 324 | + |
323 | 325 | $file = $request->getFiles('payload');
|
324 | 326 |
|
325 | 327 | $contentRange = $request->getHeader('content-range');
|
|
364 | 366 | if ($end !== $size - 1) {
|
365 | 367 | $response->json([
|
366 | 368 | '$id' => ID::custom('newfileid'),
|
367 |
| - 'chunksTotal' => (int)ceil($size / ($end + 1 - $start)), |
| 369 | + 'chunksTotal' => (int) ceil($size / ($end + 1 - $start)), |
368 | 370 | 'chunksUploaded' => ceil($start / $chunkSize) + 1
|
369 | 371 | ]);
|
370 | 372 | }
|
|
401 | 403 | ->label('sdk.mock', true)
|
402 | 404 | ->inject('response')
|
403 | 405 | ->action(function (Response $response) {
|
404 |
| - $file = \fread(\fopen(\getcwd() . '/resources/file.png', 'r'), \filesize(\getcwd() . '/resources/file.png')); |
| 406 | + $file = \file_get_contents(\getcwd() . '/resources/file.png'); |
405 | 407 |
|
406 | 408 | $response->multipart([
|
407 | 409 | 'x' => 'abc',
|
|
410 | 412 | ]);
|
411 | 413 | });
|
412 | 414 |
|
413 |
| - |
414 | 415 | App::get('/v1/mock/tests/general/redirect')
|
415 | 416 | ->desc('Redirect')
|
416 | 417 | ->groups(['mock'])
|
|
424 | 425 | ->label('sdk.response.model', Response::MODEL_MOCK)
|
425 | 426 | ->label('sdk.mock', true)
|
426 | 427 | ->inject('response')
|
427 |
| - ->action(function (UtopiaSwooleResponse $response) { |
| 428 | + ->action(function (Response $response) { |
428 | 429 | $response->redirect('/v1/mock/tests/general/redirect/done');
|
429 | 430 | });
|
430 | 431 |
|
|
457 | 458 | ->label('sdk.mock', true)
|
458 | 459 | ->inject('response')
|
459 | 460 | ->inject('request')
|
460 |
| - ->action(function (UtopiaSwooleResponse $response, Request $request) { |
| 461 | + ->action(function (Response $response, Request $request) { |
461 | 462 | $response->addCookie('cookieName', 'cookieValue', \time() + 31536000, '/', $request->getHostname(), true, true);
|
462 | 463 | });
|
463 | 464 |
|
|
492 | 493 | ->label('sdk.response.model', Response::MODEL_NONE)
|
493 | 494 | ->label('sdk.mock', true)
|
494 | 495 | ->inject('response')
|
495 |
| - ->action(function (UtopiaSwooleResponse $response) { |
| 496 | + ->action(function (Response $response) { |
496 | 497 | $response->noContent();
|
497 | 498 | });
|
498 | 499 |
|
|
569 | 570 | ->label('sdk.response.model', Response::MODEL_ANY)
|
570 | 571 | ->label('sdk.mock', true)
|
571 | 572 | ->inject('response')
|
572 |
| - ->action(function (UtopiaSwooleResponse $response) { |
| 573 | + ->action(function (Response $response) { |
| 574 | + |
573 | 575 | $response
|
574 | 576 | ->setStatusCode(502)
|
575 | 577 | ->text('This is a text error');
|
|
590 | 592 | ->param('success', '', new Text(1024), 'OAuth2 success redirect URI.')
|
591 | 593 | ->param('failure', '', new Text(1024), 'OAuth2 failure redirect URI.')
|
592 | 594 | ->inject('response')
|
593 |
| - ->action(function (string $clientId, array $scopes, string $state, string $success, string $failure, UtopiaSwooleResponse $response) { |
| 595 | + ->action(function (string $clientId, array $scopes, string $state, string $success, string $failure, Response $response) { |
594 | 596 | $response->redirect($success . '?' . \http_build_query(['code' => 'abcdef', 'state' => $state]));
|
595 | 597 | });
|
596 | 598 |
|
|
608 | 610 | ->param('code', '', new Text(100), 'OAuth2 state.', true)
|
609 | 611 | ->param('refresh_token', '', new Text(100), 'OAuth2 refresh token.', true)
|
610 | 612 | ->inject('response')
|
611 |
| - ->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, UtopiaSwooleResponse $response) { |
| 613 | + ->action(function (string $client_id, string $client_secret, string $grantType, string $redirectURI, string $code, string $refreshToken, Response $response) { |
612 | 614 | if ($client_id != '1') {
|
613 | 615 | throw new Exception(Exception::GENERAL_MOCK, 'Invalid client ID');
|
614 | 616 | }
|
|
647 | 649 | ->label('docs', false)
|
648 | 650 | ->param('token', '', new Text(100), 'OAuth2 Access Token.')
|
649 | 651 | ->inject('response')
|
650 |
| - ->action(function (string $token, UtopiaSwooleResponse $response) { |
| 652 | + ->action(function (string $token, Response $response) { |
651 | 653 | if ($token != '123456') {
|
652 | 654 | throw new Exception(Exception::GENERAL_MOCK, 'Invalid token');
|
653 | 655 | }
|
|
665 | 667 | ->label('scope', 'public')
|
666 | 668 | ->label('docs', false)
|
667 | 669 | ->inject('response')
|
668 |
| - ->action(function (UtopiaSwooleResponse $response) { |
| 670 | + ->action(function (Response $response) { |
| 671 | + |
669 | 672 | $response->json([
|
670 | 673 | 'result' => 'success',
|
671 | 674 | ]);
|
|
677 | 680 | ->label('scope', 'public')
|
678 | 681 | ->label('docs', false)
|
679 | 682 | ->inject('response')
|
680 |
| - ->action(function (UtopiaSwooleResponse $response) { |
| 683 | + ->action(function (Response $response) { |
| 684 | + |
681 | 685 | $response
|
682 | 686 | ->setStatusCode(Response::STATUS_CODE_BAD_REQUEST)
|
683 | 687 | ->json([
|
|
690 | 694 | ->inject('utopia')
|
691 | 695 | ->inject('response')
|
692 | 696 | ->inject('request')
|
693 |
| - ->action(function (App $utopia, UtopiaSwooleResponse $response, Request $request) { |
| 697 | + ->action(function (App $utopia, Response $response, Request $request) { |
| 698 | + |
694 | 699 | $result = [];
|
695 |
| - $route = $utopia->getRoute(); |
696 |
| - $path = APP_STORAGE_CACHE . '/tests.json'; |
697 |
| - $tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : []; |
| 700 | + $route = $utopia->getRoute(); |
| 701 | + $path = APP_STORAGE_CACHE . '/tests.json'; |
| 702 | + $tests = (\file_exists($path)) ? \json_decode(\file_get_contents($path), true) : []; |
698 | 703 |
|
699 | 704 | if (!\is_array($tests)) {
|
700 | 705 | throw new Exception(Exception::GENERAL_MOCK, 'Failed to read results', 500);
|
|
708 | 713 | throw new Exception(Exception::GENERAL_MOCK, 'Failed to save results', 500);
|
709 | 714 | }
|
710 | 715 |
|
711 |
| - $response->json(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']); |
| 716 | + if ($route->getPath() !== '/v1/mock/tests/general/multipart') { |
| 717 | + $response->json(['result' => $route->getMethod() . ':' . $route->getPath() . ':passed']); |
| 718 | + } |
712 | 719 | });
|
713 | 720 |
|
714 | 721 | App::error()
|
@@ -798,6 +805,7 @@ function () use ($http) {
|
798 | 805 | $http->on(Constant::EVENT_REQUEST, function (SwooleRequest $swooleRequest, SwooleResponse $swooleResponse) {
|
799 | 806 | $request = new Request($swooleRequest);
|
800 | 807 | $response = new Response($swooleResponse);
|
| 808 | + |
801 | 809 | $app = new App('UTC');
|
802 | 810 |
|
803 | 811 | $app->run($request, $response);
|
|
0 commit comments