skyzyx/phpt

此包已被废弃且不再维护。未建议替代包。

将PHPT单元测试文件解析为键值对形式的节。

1.1 2012-02-08 17:20 UTC

This package is auto-updated.

Last update: 2022-02-01 12:20:07 UTC


README

将PHPT单元测试文件解析为键值对形式的节。

示例

例如,您有这个PHPT单元测试

--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"
}

您决定要获取FILE头的内容

<?php
use Skyzyx\Components\PHPT;

$file = file_get_contents('sample.phpt');
$phpt = new PHPT($file);
$results = $phpt->get_section('FILE');

echo $results;

这将显示以下内容

<?php
var_dump(array(
	'hello' => 'World',
	'goodbye' => 'MrChips'
));
?>

安装

从GitHub安装源代码

要安装源代码

git clone git://github.com/skyzyx/phpt.git

并将其包含在您的脚本中

require_once '/path/to/phpt/src/PHPT.php';

使用Composer安装

如果您使用Composer来管理依赖项,您可以添加PHP。

{
	"require": {
		"skyzyx/phpt": ">=1.1"
	}
}

使用类加载器

如果您使用类加载器(例如,Symfony Class Loader

$loader->registerNamespace('Skyzyx\\Components\\PHPT', 'path/to/vendor/phpt/src');

测试

测试是用PHPT格式编写的。您可以使用PEAR Test Runner或PHPUnit 3.6+运行它们。

cd tests/
pear run-tests .

...或者...

cd tests/
phpunit .

许可证 & 版权

版权所有(c)2010-2012 Ryan Parman。根据MIT许可证许可使用。