|
141 | 141 | }); |
142 | 142 |
|
143 | 143 | it('can download a file', function () { |
144 | | - $expectedResponse = $this->getMockBuilder(StreamInterface::class) |
145 | | - ->getMock(); |
| 144 | + $expectedResponse = $this->createMock(StreamInterface::class); |
146 | 145 | $expectedResponse->expects($this->once()) |
147 | 146 | ->method('isReadable') |
148 | 147 | ->willReturn(true); |
|
165 | 164 | }); |
166 | 165 |
|
167 | 166 | it('can download a folder as zip', function () { |
168 | | - $expectedResponse = $this->getMockBuilder(StreamInterface::class) |
169 | | - ->getMock(); |
| 167 | + $expectedResponse = $this->createMock(StreamInterface::class); |
170 | 168 | $expectedResponse->expects($this->once()) |
171 | 169 | ->method('isReadable') |
172 | 170 | ->willReturn(true); |
|
231 | 229 | }); |
232 | 230 |
|
233 | 231 | it('can get a thumbnail', function () { |
234 | | - $expectedResponse = $this->getMockBuilder(StreamInterface::class) |
235 | | - ->getMock(); |
| 232 | + $expectedResponse = $this->createMock(StreamInterface::class); |
236 | 233 |
|
237 | 234 | $mockGuzzle = $this->mockGuzzleRequest( |
238 | 235 | $expectedResponse, |
|
404 | 401 | ->and($uploadSessionCursor->offset)->toBe(32); |
405 | 402 | }); |
406 | 403 |
|
407 | | -it('can upload a file string chunked', function () { |
408 | | - $content = 'chunk0chunk1chunk2rest'; |
409 | | - $mockClient = $this->mockChunkedUploadClient($content, 6); |
410 | | - |
411 | | - expect($mockClient->uploadChunked('Homework/math/answers.txt', $content, 'add', 6)) |
412 | | - ->toBe(['name' => 'answers.txt']); |
413 | | -})->skip('Must fix method "mockChunkedUploadClient".'); |
414 | | - |
415 | | -it('can upload a file resource chunked', function () { |
416 | | - $content = 'chunk0chunk1chunk2rest'; |
417 | | - $resource = fopen('php://memory', 'r+'); |
418 | | - fwrite($resource, $content); |
419 | | - rewind($resource); |
420 | | - |
421 | | - $mockClient = $this->mockChunkedUploadClient($content, 6); |
422 | | - |
423 | | - expect($mockClient->uploadChunked('Homework/math/answers.txt', $resource, 'add', 6)) |
424 | | - ->toBe(['name' => 'answers.txt']); |
425 | | -})->skip('Must fix method "mockChunkedUploadClient".'); |
426 | | - |
427 | | -it('can upload a tiny file chunked', function () { |
428 | | - $content = 'smallerThenChunkSize'; |
429 | | - $resource = fopen('php://memory', 'r+'); |
430 | | - fwrite($resource, $content); |
431 | | - rewind($resource); |
432 | | - |
433 | | - $mockClient = $this->mockChunkedUploadClient($content, 21); |
434 | | - |
435 | | - expect($mockClient->uploadChunked('Homework/math/answers.txt', $resource, 'add', 21)) |
436 | | - ->toBe(['name' => 'answers.txt']); |
437 | | -})->skip('Must fix method "mockChunkedUploadClient".'); |
438 | | - |
439 | 404 | it('can finish an upload session', function () { |
440 | 405 | $mockGuzzle = $this->mockGuzzleRequest( |
441 | 406 | json_encode([ |
|
531 | 496 | }); |
532 | 497 |
|
533 | 498 | test('content endpoint request can throw exception', function () { |
534 | | - $mockGuzzle = $this->getMockBuilder(GuzzleClient::class) |
535 | | - ->onlyMethods(['request']) |
536 | | - ->getMock(); |
| 499 | + $mockGuzzle = $this->createMock(GuzzleClient::class); |
537 | 500 | $mockGuzzle->expects($this->once()) |
538 | 501 | ->method('request') |
539 | 502 | ->willThrowException(new ClientException( |
540 | 503 | 'there was an error', |
541 | | - $this->getMockBuilder(RequestInterface::class)->getMock(), |
542 | | - $this->getMockBuilder(ResponseInterface::class)->getMock(), |
| 504 | + $this->createMock(RequestInterface::class), |
| 505 | + $this->createMock(ResponseInterface::class), |
543 | 506 | )); |
544 | 507 |
|
545 | 508 | $client = new Client('test_token', $mockGuzzle); |
|
552 | 515 | 'getToken' => 'test_token', |
553 | 516 | ]); |
554 | 517 |
|
555 | | - $mockGuzzle = $this->getMockBuilder(GuzzleClient::class) |
556 | | - ->onlyMethods(['request']) |
557 | | - ->getMock(); |
| 518 | + $mockGuzzle = $this->createMock(GuzzleClient::class); |
558 | 519 |
|
559 | 520 | $mockGuzzle->expects($this->exactly(2)) |
560 | 521 | ->method('request') |
561 | 522 | ->willThrowException($e = new ClientException( |
562 | 523 | 'there was an error', |
563 | | - $this->getMockBuilder(RequestInterface::class)->getMock(), |
564 | | - $this->getMockBuilder(ResponseInterface::class)->getMock(), |
| 524 | + $this->createMock(RequestInterface::class), |
| 525 | + $this->createMock(ResponseInterface::class), |
565 | 526 | )); |
566 | 527 |
|
567 | 528 | $tokenProvider->expects($this->once()) |
|
575 | 536 | })->throws(ClientException::class); |
576 | 537 |
|
577 | 538 | test('rpc endpoint request can throw exception with 400 status code', function () { |
578 | | - $mockResponse = $this->getMockBuilder(ResponseInterface::class) |
579 | | - ->getMock(); |
580 | | - $mockResponse->expects($this->any()) |
581 | | - ->method('getStatusCode') |
582 | | - ->willReturn(400); |
| 539 | + $mockResponse = $this->createConfiguredMock(ResponseInterface::class, [ |
| 540 | + 'getStatusCode' => 400, |
| 541 | + ]); |
583 | 542 |
|
584 | | - $mockGuzzle = $this->getMockBuilder(GuzzleClient::class) |
585 | | - ->onlyMethods(['request']) |
586 | | - ->getMock(); |
| 543 | + $mockGuzzle = $this->createMock(GuzzleClient::class); |
587 | 544 |
|
588 | 545 | $mockGuzzle->expects($this->once()) |
589 | 546 | ->method('request') |
590 | 547 | ->willThrowException(new ClientException( |
591 | 548 | 'there was an error', |
592 | | - $this->getMockBuilder(RequestInterface::class)->getMock(), |
| 549 | + $this->createMock(RequestInterface::class), |
593 | 550 | $mockResponse, |
594 | 551 | )); |
595 | 552 |
|
|
606 | 563 | 'error_summary' => 'Human readable error code', |
607 | 564 | ]; |
608 | 565 |
|
609 | | - $mockResponse = $this->getMockBuilder(ResponseInterface::class) |
610 | | - ->getMock(); |
611 | | - $mockResponse->expects($this->any()) |
612 | | - ->method('getStatusCode') |
613 | | - ->willReturn(409); |
614 | | - $mockResponse->expects($this->any()) |
615 | | - ->method('getBody') |
616 | | - ->willReturn($this->createStreamFromString(json_encode($body))); |
| 566 | + $mockResponse = $this->createConfiguredMock(ResponseInterface::class, [ |
| 567 | + 'getStatusCode' => 409, |
| 568 | + 'getBody' => $this->createStreamFromString(json_encode($body)), |
| 569 | + ]); |
617 | 570 |
|
618 | | - $mockGuzzle = $this->getMockBuilder(GuzzleClient::class) |
619 | | - ->onlyMethods(['request']) |
620 | | - ->getMock(); |
| 571 | + $mockGuzzle = $this->createMock(GuzzleClient::class); |
621 | 572 |
|
622 | 573 | $mockGuzzle->expects($this->once()) |
623 | 574 | ->method('request') |
624 | 575 | ->willThrowException(new ClientException( |
625 | 576 | 'there was an error', |
626 | | - $this->getMockBuilder(RequestInterface::class)->getMock(), |
| 577 | + $this->createMock(RequestInterface::class), |
627 | 578 | $mockResponse, |
628 | 579 | )); |
629 | 580 |
|
|
649 | 600 | 'getBody' => $this->createStreamFromString(json_encode($body)), |
650 | 601 | ]); |
651 | 602 |
|
652 | | - $mockGuzzle = $this->getMockBuilder(GuzzleClient::class) |
653 | | - ->onlyMethods(['request']) |
654 | | - ->getMock(); |
| 603 | + $mockGuzzle = $this->createMock(GuzzleClient::class); |
655 | 604 |
|
656 | 605 | $mockGuzzle->expects($this->exactly(2)) |
657 | 606 | ->method('request') |
658 | 607 | ->willThrowException($e = new ClientException( |
659 | 608 | 'there was an error', |
660 | | - $this->getMockBuilder(RequestInterface::class)->getMock(), |
| 609 | + $this->createMock(RequestInterface::class), |
661 | 610 | $mockResponse, |
662 | 611 | )); |
663 | 612 |
|
|
697 | 646 | 'getBody' => $this->createStreamFromString(json_encode($successBody)), |
698 | 647 | ]); |
699 | 648 |
|
700 | | - $mockGuzzle = $this->getMockBuilder(GuzzleClient::class) |
701 | | - ->onlyMethods(['request']) |
702 | | - ->getMock(); |
| 649 | + $mockGuzzle = $this->createMock(GuzzleClient::class); |
703 | 650 |
|
704 | 651 | $e = new ClientException( |
705 | 652 | 'there was an error', |
706 | | - $this->getMockBuilder(RequestInterface::class)->getMock(), |
| 653 | + $this->createMock(RequestInterface::class), |
707 | 654 | $errorResponse, |
708 | 655 | ); |
709 | 656 |
|
| 657 | + $callCount = 0; |
710 | 658 | $mockGuzzle->expects($this->exactly(2)) |
711 | 659 | ->method('request') |
712 | | - ->willReturnOnConsecutiveCalls( |
713 | | - $this->throwException($e), |
714 | | - $successResponse, |
715 | | - ); |
| 660 | + ->willReturnCallback(function () use (&$callCount, $e, $successResponse) { |
| 661 | + $callCount++; |
| 662 | + if ($callCount === 1) { |
| 663 | + throw $e; |
| 664 | + } |
| 665 | + |
| 666 | + return $successResponse; |
| 667 | + }); |
716 | 668 |
|
717 | 669 | $tokenProvider->expects($this->once()) |
718 | 670 | ->method('refresh') |
|
0 commit comments