Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sebastianbergmann/phpunit-example-extension

Example of an extension for PHPUnit
https://github.com/sebastianbergmann/phpunit-example-extension

phpunit

Last synced: 5 days ago
JSON representation

Example of an extension for PHPUnit

Awesome Lists containing this project

README

        

# PHPUnit Example Extension

Example of an extension for [PHPUnit](https://phpunit.de/).

## Installation

### Composer

If you use [Composer](https://getcomposer.org/) to manage the dependencies of your project then you can add the PHPUnit example extension as a development-time dependency to your project:

```
$ composer require --dev phpunit/example-extension
```

### PHP Archive (PHAR)

If you use PHPUnit 5.7 (or later) from a [PHP Archive (PHAR)](https://php.net/phar) then you can download a PHAR of the PHPUnit example extension:

```
$ wget https://phar.phpunit.de/phpunit-example-extension.phar
```

The example below shows how to configure PHPUnit to load all `*.phar` files found in a given directory (`tools/phpunit.d` in this example):

```xml

```

PHPUnit will only load a an extension PHAR if it provides valid manifest information in a `manifest.xml` file:

```xml








```

Of course, the extension to be loaded must also be compatible with the version of PHPUnit trying to load it. The extension provides the information required for this compatbility check in its manifest.

When verbose output is activated, PHPUnit will print loaded extension PHARs:

```
$ phpunit --verbose tests
PHPUnit 6.3.0 by Sebastian Bergmann and contributors.

Runtime: PHP 7.1.8 with Xdebug 2.5.5
Configuration: /home/sb/example/phpunit.xml
Extension: phpunit/phpunit-example-extension 3.0.0

. 1 / 1 (100%)

Time: 32 ms, Memory: 4.00MB

OK (1 test, 1 assertion)
```

The `--no-extensions` commandline option can be used to suppress the loading of extensions from the directory configured using `extensionsDirectory`:

```
$ phpunit --no-extensions
PHP Fatal error: Trait 'PHPUnit\ExampleExtension\TestCaseTrait' not found in ...
```