Closed cspray closed 5 years ago
I'd really like your Gist. I wanted to implement a custom test runner for a long time, but haven't realized it's that easy. The checkpoint assertion is also really nice and something we should have written for Amp's tests already. I'm looking forward to your PR.
Awesome, I'm planning on putting the AsyncTestCase functionality into the existing implementation unless you'd like to see the 2 responsibilities the classes are providing to be separate. I will likely be able to put some time towards this over the coming weekend.
Thanks.
@cspray I think it should be a separate class, because it changes the current behavior.
The PR for this issue has been merged in. Thank you for accepting my contribution.
Thank you for the excellent work that you've done to improve asynchronous programming in PHP. I am starting to develop a series of applications on top of amphp and I plan on developing a series of test utilities that I wanted to see if you'd like to see added to this library.
The first piece is an
AsynchronousTestCase
that would allow userland code to ensure all asynchronous operations in their test completes appropriately and that tests aren't allowed to run forever. This is accomplished by allowing tests to return a Promise to control when the test ends and setting a delay timer to ensure the test does not run past a set period of time.The second is a
TestContext
class (or something more aptly named) that would ensure a series of asynchronous tasks occur and to also act as a Deferred able to provide a Promise returned for each test in the AsyncTestCase.Here is a gist of an example implementation of the AsyncTestCase along with an example test using the TestContext object. https://gist.github.com/cspray/88ce3d550a0e5ac74c5cafbc5b85df95
Please let me know if you have any questions or any other feedback. If this is something that you would be interested in I can provide tests for it (nothing like testing the tests) and submit a PR. Before I go down that route I wanted to ensure this is something you'd like to see.
Thanks