-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from seregazhuk/add-assertions-for-instances
Add assertions for instances
- Loading branch information
Showing
7 changed files
with
189 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace seregazhuk\React\PromiseTesting\tests; | ||
|
||
use Exception; | ||
use React\Promise\Deferred; | ||
use function React\Promise\Timer\resolve; | ||
use seregazhuk\React\PromiseTesting\TestCase; | ||
|
||
final class PromiseFulfillsWithInstanceOfTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function promise_fulfills_with_a_value_of_a_specified_class(): void | ||
{ | ||
try { | ||
$deferred = new Deferred(); | ||
$deferred->resolve(new MyClass()); | ||
$this->assertPromiseFulfillsWithInstanceOf($deferred->promise(), MyClass::class, 1); | ||
} catch (Exception $exception) { | ||
$this->assertRegExp( | ||
'/Failed asserting that promise fulfills with a value of class ' . preg_quote(MyClass::class, '/') .'/', | ||
$exception->getMessage() | ||
); | ||
|
||
$this->assertRegExp( | ||
'/Failed asserting that .+ matches expected .+/', | ||
$exception->getMessage() | ||
); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_fails_when_promise_rejects(): void | ||
{ | ||
try { | ||
$deferred = new Deferred(); | ||
|
||
$deferred->reject(); | ||
$this->assertPromiseFulfillsWithInstanceOf($deferred->promise(), MyClass::class, 1); | ||
} catch (Exception $exception) { | ||
$this->assertRegExp( | ||
'/Failed asserting that promise fulfills with a value of class ' . preg_quote(MyClass::class, '/') .'/', | ||
$exception->getMessage() | ||
); | ||
|
||
$this->assertRegExp( | ||
'/Promise was rejected/', | ||
$exception->getMessage() | ||
); | ||
} | ||
} | ||
|
||
/** @test */ | ||
public function it_fails_when_promise_doesnt_fulfill_in_a_specified_timeout(): void | ||
{ | ||
try { | ||
$deferred = new Deferred(); | ||
|
||
$deferred->reject(); | ||
$promise = resolve($timeToResolve = 3, $this->eventLoop()); | ||
|
||
$promise->then( | ||
static function() use ($deferred){ | ||
$deferred->resolve(new MyClass()); | ||
} | ||
); | ||
|
||
$this->assertPromiseFulfillsWithInstanceOf($promise, MyClass::class, 1); | ||
} catch (Exception $exception) { | ||
$this->assertRegExp( | ||
'/Failed asserting that promise fulfills with a value of class ' . preg_quote(MyClass::class, '/') .'/', | ||
$exception->getMessage() | ||
); | ||
|
||
$this->assertRegExp( | ||
'/Promise was cancelled due to timeout/', | ||
$exception->getMessage() | ||
); | ||
} | ||
} | ||
} | ||
|
||
final class MyClass { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters