mover-io / phpusable-phpunit
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 26 384
Dependents: 1
Suggesters: 0
Security: 0
Stars: 17
Watchers: 14
Forks: 3
Open Issues: 0
Requires
- jacobstr/esperance: >=0.1
- phpunit/phpunit: ~5.7
This package is not auto-updated.
Last update: 2019-05-28 11:34:42 UTC
README
Motivation
The goal of this project is to provide a more usuable syntax ontop of PHPUnit, while still being compatible with PHPUnit.
Much of the inspiration for the DSL and syntax is drawn from the ruby testing framework RSpec.
Installation
PHPUsable can be installed using Composer.
At first, save below as composer.json
at the root of your project.
{ "require": { "mover-io/phpusable-phpunit": "dev-master" } }
And run these commands.
$ wget http://getcomposer.org/composer.phar
$ php composer.phar install
Then PHPUsable will be installed in ./vendor
directory and also ./vendor/autoload.php
is generated.
Usage
PHPUsable is (almost) fully PHPUnit compatible. To run a PHPUsable test file, simply run it using phpunit.
$ phpunit test/test.php PHPUnit 3.7.20 by Sebastian Bergmann. .... Time: 0 seconds, Memory: 4.50Mb OK (4 tests, 4 assertions)
It even supports phpunit debug output.
$ phpunit --debug test/test.php PHPUnit 3.7.20 by Sebastian Bergmann. Starting test 'with esperance style assertions::with a true value::should be true'. . Starting test 'with esperance style assertions::with a false value::should be false'. . Starting test 'with phpunit style assertions::with a true value::should be true'. . Starting test 'with phpunit style assertions::with a false value::should be false'. . Time: 0 seconds, Memory: 4.50Mb OK (4 tests, 4 assertions)
Usage Example
<?php namespace PHPUsable; require 'vendor/autoload.php'; class PHPTest extends PHPUsableTest { public function tests() { PHPUsableTest::$current_test = $this; describe('with esperance style assertions', function($test) { describe('with a true value', function($test) { before(function($test) { //Arbitratry variables can be stored on test to pass between blocks $test->my_value = true; }); it ('should be true', function($test) { $test->expect($test->my_value)->to->be->ok(); }); }); describe('with a false value', function($test) { before(function($test) { $test->my_value = false; }); it ('should be false', function($test) { $test->expect($test->my_value)->to->be(false); }); }); }); describe('with phpunit style assertions', function($test) { describe('with a true value', function($test) { before(function($test) { $test->my_value = true; }); it ('should be true', function($test) { $test->assertTrue($test->my_value); }); }); describe('with a false value', function($test) { before(function($test) { $test->my_value = false; }); it ('should be false', function($test) { $test->assertFalse($test->my_value); }); }); }); } }
Team
This library was created by the Mover team for use in testing our PHP code base when we got tired of the PHPUnit syntax.
Expectations
PHPUsable uses Esperance to offer an expectation based syntax for assertions.
License
MIT License (or buy me a beer)