Parses PHPT unit test files into sections as key-value pairs.
Say, for example, you have this PHPT unit test:
--TEST--
Test that my code works!
--DESCRIPTION--
This test covers [blah, blah, blah...]
--CREDITS--
Zoe Slattery zoe@php.net
# TestFest Munich 2009-05-19
--FILE--
<?php
var_dump(array(
'hello' => 'World',
'goodbye' => 'MrChips'
));
?>
--EXPECT--
array(2) {
["hello"]=>
string(5) "World"
["goodbye"]=>
string(7) "MrChips"
}
You decide that you want to grab the contents of the FILE
header:
<?php
use Skyzyx\Components\PHPT;
$file = file_get_contents('sample.phpt');
$phpt = new PHPT($file);
$results = $phpt->get_section('FILE');
echo $results;
This would display the following:
<?php
var_dump(array(
'hello' => 'World',
'goodbye' => 'MrChips'
));
?>
To install the source code:
git clone git://github.com/skyzyx/phpt.git
And include it in your scripts:
require_once '/path/to/phpt/src/PHPT.php';
If you're using Composer to manage dependencies, you can add PHP with it.
{
"require": {
"skyzyx/phpt": ">=1.1"
}
}
If you're using a class loader (e.g., Symfony Class Loader):
$loader->registerNamespace('Skyzyx\\Components\\PHPT', 'path/to/vendor/phpt/src');
Tests are written in PHPT format. You can run them with either the PEAR Test Runner or with PHPUnit 3.6+.
cd tests/
pear run-tests .
...or...
cd tests/
phpunit .
Copyright (c) 2010-2012 Ryan Parman. Licensed for use under the terms of the MIT license.