|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Geocoder package. |
| 7 | + * For the full copyright and license information, please view the LICENSE |
| 8 | + * file that was distributed with this source code. |
| 9 | + * |
| 10 | + * @license MIT License |
| 11 | + */ |
| 12 | + |
| 13 | +namespace Geocoder\Plugin\Tests\Promise; |
| 14 | + |
| 15 | +use Geocoder\Collection; |
| 16 | +use Geocoder\Exception\Exception; |
| 17 | +use Geocoder\Exception\LogicException; |
| 18 | +use Geocoder\Plugin\Promise\GeocoderFulfilledPromise; |
| 19 | +use Geocoder\Plugin\Promise\GeocoderRejectedPromise; |
| 20 | +use Http\Promise\Promise; |
| 21 | +use PHPUnit\Framework\TestCase; |
| 22 | + |
| 23 | +class GeocoderRejectedPromiseTest extends TestCase |
| 24 | +{ |
| 25 | + public function testItReturnsAFulfilledPromise(): void |
| 26 | + { |
| 27 | + $exception = $this->createStub(Exception::class); |
| 28 | + $promise = new GeocoderRejectedPromise($exception); |
| 29 | + $collection = $this->createStub(Collection::class); |
| 30 | + |
| 31 | + $returnPromise = $promise->then(null, function () use ($collection) { |
| 32 | + return $collection; |
| 33 | + }); |
| 34 | + |
| 35 | + $this->assertInstanceOf(GeocoderFulfilledPromise::class, $returnPromise); |
| 36 | + $this->assertSame(Promise::FULFILLED, $returnPromise->getState()); |
| 37 | + $this->assertSame($collection, $returnPromise->wait()); |
| 38 | + } |
| 39 | + |
| 40 | + public function testItReturnsARejectedPromise(): void |
| 41 | + { |
| 42 | + $collection = $this->createStub(Exception::class); |
| 43 | + $promise = new GeocoderRejectedPromise($collection); |
| 44 | + |
| 45 | + $returnPromise = $promise->then(null, function () { |
| 46 | + throw new LogicException(); |
| 47 | + }); |
| 48 | + |
| 49 | + $this->assertInstanceOf(GeocoderRejectedPromise::class, $returnPromise); |
| 50 | + $this->assertSame(Promise::REJECTED, $returnPromise->getState()); |
| 51 | + |
| 52 | + $this->expectException(Exception::class); |
| 53 | + $returnPromise->wait(); |
| 54 | + } |
| 55 | + |
| 56 | + public function testItReturnsItselfWhenNoOnRejectedCallbackIsPassed(): void |
| 57 | + { |
| 58 | + $collection = $this->createStub(Exception::class); |
| 59 | + $promise = new GeocoderRejectedPromise($collection); |
| 60 | + |
| 61 | + $returnPromise = $promise->then(); |
| 62 | + $this->assertSame($promise, $returnPromise); |
| 63 | + } |
| 64 | +} |
0 commit comments