phine/test

A PHP library for improving unit testing.

1.0.1 2013-12-30 23:23 UTC

README

Build Status Coverage Status Latest Stable Version Total Downloads

A PHP library for improving unit testing.

Usage

use Phine\Test\Method;
use Phine\Test\Property;
use Phine\Test\Temp;

class Example
{
    private static $isStatic = 'original';

    private $nonStatic = 'original';

    protected static function isStatic($arg)
    {
        return "Static: $arg";
    }

    protected function nonStatic($arg)
    {
        return "Non static: $arg";
    }
}

$example = new Example();

// retrieve hidden values
echo Property::get('Example', 'isStatic'); // "original"
echo Property::get($example, 'nonStatic'); // "original"

// change hidden values
Property::set('Example', 'isStatic', 'changed');
Property::set($example, 'nonStatic', 'changed');

echo Property::get('Example', 'isStatic'); // "changed"
echo Property::get($example, 'nonStatic'); // "changed"

// invoke hidden methods
echo Method::invoke('Example', 'isStatic', 123); // "Static: 123"
echo Method::invoke($example, 'nonStatic', 456); // "Non static: 456"

echo Method::invokeArgs('Example', 'isStatic', array(123)); // "Static: 123"
echo Method::invokeArgs($example, 'nonStatic', array(456)); // "Static: 456"

$temp = new Temp();

// create temporary paths
$dir = $temp->createDir();
$file = $temp->createFile();

// copy existing paths to temporary ones (names are preserved)
$dir = $temp->copyDir('/path/to/dir');
$file = $temp->copyFile('/path/to/file');

// purge all temporary paths
$temp->purgePaths();

Requirement

Installation

Via Composer:

$ composer require "phine/test=~1.0"

Documentation

You can find the documentation in the docs/ directory.

License

This library is available under the MIT license.