seregazhuk / php-react-promise-testing Goto Github PK
View Code? Open in Web Editor NEWPHPUnit assertions for testing ReactPHP promises
License: MIT License
PHPUnit assertions for testing ReactPHP promises
License: MIT License
Description can be found here
It can be updated up to 7
version.
Hello.
Sergey, how to implement this PHPUnit assertions for ReactPHP with https://github.com/ratchetphp/Ratchet/blob/master/src/Ratchet/Wamp/WampServer.php
?
Thx. :)
Call of $this->addToAssertionCount(1);
should be placed at the beginning of the assetion.
Update PHP version to 7.2 and appropriate dependencies
Does the library really require 8.0 now?
I've been waiting for a new release that would update its dependency to phpunit 9.x (which also requires 7.3) but we don't yet support PHP 8.x so we're caught between two stools now!
Hi Sergey,
I think this method is wrong:
I't should look like this
/**
* @throws AssertionFailedError
*/
public function assertPromiseRejectsWith(PromiseInterface $promise, string $reasonExceptionClass, int $timeout = null): void
{
try {
$this->waitForPromise($promise, $timeout);
} catch (Exception $reason) {
$this->assertInstanceOf(
$reasonExceptionClass, $reason, 'Failed asserting that promise rejects with a specified reason.'
);
return;
}
$this->fail('Failed asserting that promise rejects. Promise was fulfilled.');
}
You reject your promise with "LogicException" and that is catched here:
That will actually create assertion like this:
$this->assertInstanceOf(\InvalidArgumentException::class, new \LogicException());
And this will not pass because InvalidArgumentException extends LogicException but not vice versa. Trying this as new test will fail with:
Failed asserting that LogicException Object (...) is an instance of class "InvalidArgumentException".
Finally your test will catch this as PHPUnit\Framework\ExpectationFailedException and assert this exception for valid messages and this is why your test passes.
I think that test should look like this:
/** @test */
public function promise_rejects_with_a_specified_reason(): void
{
$deferred = new Deferred();
$deferred->reject(new \InvalidArgumentException());
$this->assertPromiseRejectsWith($deferred->promise(), \LogicException::class);
}
This should reject promise with "InvalidArgumentException" which is actually instance of "LogicException::class"
There is some misconception of naming: verb resolve
is used instead of fulfill
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.