Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions src/Plugin/Tests/Promise/GeocoderFulfilledPromiseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder\Plugin\Tests\Promise;

use Geocoder\Collection;
use Geocoder\Exception\Exception;
use Geocoder\Exception\LogicException;
use Geocoder\Plugin\Promise\GeocoderFulfilledPromise;
use Geocoder\Plugin\Promise\GeocoderRejectedPromise;
use Http\Promise\Promise;
use PHPUnit\Framework\TestCase;

class GeocoderFulfilledPromiseTest extends TestCase
{
public function testItReturnsAFulfilledPromise(): void
{
$collection = $this->createStub(Collection::class);
$promise = new GeocoderFulfilledPromise($collection);

$returnPromise = $promise->then(function (Collection $collection) {
return $collection;
});

$this->assertInstanceOf(GeocoderFulfilledPromise::class, $returnPromise);
$this->assertSame(Promise::FULFILLED, $returnPromise->getState());
$this->assertSame($collection, $returnPromise->wait());
}

public function testItReturnsARejectedPromise(): void
{
$collection = $this->createStub(Collection::class);
$promise = new GeocoderFulfilledPromise($collection);

$returnPromise = $promise->then(function () {
throw new LogicException();
});

$this->assertInstanceOf(GeocoderRejectedPromise::class, $returnPromise);
$this->assertSame(Promise::REJECTED, $returnPromise->getState());

$this->expectException(Exception::class);
$returnPromise->wait();
}

public function testItReturnsItselfWhenNoOnRejectedCallbackIsPassed(): void
{
$collection = $this->createStub(Collection::class);
$promise = new GeocoderFulfilledPromise($collection);

$returnPromise = $promise->then();
$this->assertSame($promise, $returnPromise);
}
}
64 changes: 64 additions & 0 deletions src/Plugin/Tests/Promise/GeocoderRejectedPromiseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

/*
* This file is part of the Geocoder package.
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT License
*/

namespace Geocoder\Plugin\Tests\Promise;

use Geocoder\Collection;
use Geocoder\Exception\Exception;
use Geocoder\Exception\LogicException;
use Geocoder\Plugin\Promise\GeocoderFulfilledPromise;
use Geocoder\Plugin\Promise\GeocoderRejectedPromise;
use Http\Promise\Promise;
use PHPUnit\Framework\TestCase;

class GeocoderRejectedPromiseTest extends TestCase
{
public function testItReturnsAFulfilledPromise(): void
{
$exception = $this->createStub(Exception::class);
$promise = new GeocoderRejectedPromise($exception);
$collection = $this->createStub(Collection::class);

$returnPromise = $promise->then(null, function () use ($collection) {
return $collection;
});

$this->assertInstanceOf(GeocoderFulfilledPromise::class, $returnPromise);
$this->assertSame(Promise::FULFILLED, $returnPromise->getState());
$this->assertSame($collection, $returnPromise->wait());
}

public function testItReturnsARejectedPromise(): void
{
$collection = $this->createStub(Exception::class);
$promise = new GeocoderRejectedPromise($collection);

$returnPromise = $promise->then(null, function () {
throw new LogicException();
});

$this->assertInstanceOf(GeocoderRejectedPromise::class, $returnPromise);
$this->assertSame(Promise::REJECTED, $returnPromise->getState());

$this->expectException(Exception::class);
$returnPromise->wait();
}

public function testItReturnsItselfWhenNoOnRejectedCallbackIsPassed(): void
{
$collection = $this->createStub(Exception::class);
$promise = new GeocoderRejectedPromise($collection);

$returnPromise = $promise->then();
$this->assertSame($promise, $returnPromise);
}
}