2017 © Pedro Peláez
 

library phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

image

matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  • Monday, June 11, 2018
  • by matthiasnoback
  • Repository
  • 4 Watchers
  • 19 Stars
  • 15,507 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 15 Versions
  • 9 % Grown

The README.md

Asynchronicity

Using this library you can make a test wait for certain conditions, e.g. to test the output of another process., (*1)

See my blog post on the subject for an explanation of the concepts and some code samples. Please note that this article covers version 1 of the library., (*2)

Usage

With PHPUnit

use Asynchronicity\PHPUnit\Asynchronicity;
use PHPUnit\Framework\Assert;
use PHPUnit\Framework\TestCase;

final class ProcessTest extends TestCase
{
    use Asynchronicity;

    /**
     * @test
     */
    public function it_creates_a_pid_file(): void
    {
        // start the asynchronous process that will eventually create a PID file...

        self::assertEventually(
            function (): void {
                Assert::assertFileExists(__DIR__ . '/pid');
            }
        );
    }
}

With Behat

Within a Behat FeatureContext you could use it for example that a page eventually contains some text:, (*3)

use Asynchronicity\PHPUnit\Asynchronicity;
use Behat\MinkExtension\Context\MinkContext;
use PHPUnit\Framework\Assert;

final class FeatureContext extends MinkContext
{
    use Asynchronicity;

    /**
     * @Then the stock level has been updated to :expectedStockLevel
     */
    public function thenTheFileHasBeenCreated(string $expectedStockLevel): void
    {
        self::assertEventually(function () use ($expectedStockLevel): void {
            $this->visit('/stock-levels');

            $actualStockLevel = $this->getSession()->getPage())->find('css', '.stock-level')->getText();

            Assert::assertEquals($expectedStockLevel, $actualStockLevel);
        });
    }
}

Comments and suggestions

  • You can use $this inside these callables.
  • You can add use ($...) to pass in extra data.
  • You can throw any type of exception inside the callable to indicate that what you're looking for is not yet the case.
  • Often it's convenient to just use the usual assertion methods (PHPUnit or otherwise) inside the callable. They will often provide the right amount of detail in their error messages too.
  • assertEventually() supports extra arguments for setting the timeout and wait time in milliseconds.
  • You can use any callable as the first argument to assertEventually(), including objects with an __invoke() method or something like [$object, 'methodName'].

The Versions

11/06 2018

dev-master

9999999-dev http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

phpunit assertion asynchronicity

11/06 2018

dev-next_major_release

dev-next_major_release http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

phpunit assertion asynchronicity

11/06 2018

v2.0.0

2.0.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

phpunit assertion asynchronicity

13/04 2018

v1.4.1

1.4.1.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

13/04 2018

v1.4.0

1.4.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

13/04 2018

v1.3.0

1.3.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

31/10 2017

v1.2.1

1.2.1.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

01/10 2017

dev-upgrade

dev-upgrade http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

01/10 2017

v1.2.0

1.2.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

30/09 2017

dev-cmodijk-patch-2

dev-cmodijk-patch-2 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

30/09 2017

v1.1.0

1.1.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

30/09 2017

v1.0.2

1.0.2.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

22/06 2015

v1.0.1

1.0.1.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

23/03 2014

v0.1.0

0.1.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity

23/03 2014

v1.0.0

1.0.0.0 http://github.com/matthiasnoback/phpunit-asynchronicity

Library for asserting things that happen asynchronously with PHPUnit

  Sources   Download

MIT

The Requires

 

phpunit assertion asynchronicity