guitarneck/taphp
Composer 安装命令:
composer require guitarneck/taphp
包简介
TAP producer library for PHP.
README 文档
README
taphp
TAP producer library for PHP. Based on tape for node.
This library is not psr-0/4 compliant. Indeed, its contains functions to organize the running tests that make it unfriendly with composer's autoload way.
Tested on PHP versions : 5.6.9, 7.4.13 ,8.0.0
example
with composer :
require dirname(__DIR__).'/vendor/guitarneck/taphp/taphp.lib.php';
without composer :
require_once 'taphp.lib.php';
test('timing test', function ($t) { $t->plan(2); $t->equal(get_class($t), 'TAPHP'); $start = time(); sleep(1); $t->equal(time() - $start, 0); });
$ php .\test.php
TAP version 13
# timing test
ok 1 it should strictly be equal
not ok 2 it should strictly be equal
---
actual : 1
expected: 0
...
1..2
# tests 2 (1.0868s)
# pass 1
# fail 1
TAPHP
This class is a singleton.
instance()
Returns the instance for this class. If realy you need it.
discardExit ()
This method prevents TAPHP to terminate with an exit code. It can be usefull in some circonstances, when tasks still to be done.
functions
The functions and methods are nearly the same than in tape, with some differents due to PHP language.
The so called deep methods are here for compliance with tape. PHP does it nativly.
only ( [$name], [$options], $callback )
Declare a test that will be the only one to be runned.
skip ( [$name], [$options], $callback )
Declare a test that will be skipped. It won't run.
test ( [$name], [$options], $callback )
Declare a new test. $name and $options are optional. $callback will be fired after preceding one's,
with a parameter giving access to TAPHP object's methods.
todo ( [$name], [$options], $callback )
Declare a test that still needs to do. Failure will be allowed.
options
Available options are:
- 'todo' => true|false. See function todo and method todo.
- 'skip' => true|false. See function skip and method skip.
- 'only' => true|false. See function only.
- 'timeout' => null|integer. Sets a timeout for the test, after which it will fail. See method timeout.
methods
assert ( $condition, [$text] )
Assert that condition is truthy with an optional description of the assertion $text.
Aliases: ok, true
bailout ( [$text] )
Generate an immediate exit and stop of all the tests with and optional $text as reason.
comment ( $text )
Generate a comment with a message $text.
deepEqual ( $any, $val, [$text] )
Assert that $any === $val with an optional description of the assertion $text.
Aliases: deepEquals, isEquivalent, same, deep_equal
deepLooseEqual ( $any, $val, [$text] )
Assert that $any == $val with an optional description of the assertion $text.
Aliases: deep_loose_equal
end ( [$error] )
Declare the end of a test, with an optional generated $error.
error ( $error, [$text] )
Generate a failure for a given $error, as an object type of Exception, with an optional $test description.
Aliases: ifError, ifErr, iferror, if_error
exception ( $exception, [$text] )
Generate a failure for a given $exception, as an object type of Exception, with an optional $test description.
Aliases: ifException, ifExcept, ifExpt, ifExp, ifexception, if_exception
fail ( [$text], [$options] )
Generate a failing assertion with a message $text.
looseEqual ( $any, $val, [$text] )
Assert that $any == $val with an optional description of the assertion $text.
Aliases: looseEquals, loose_equal
no ( $condition, [$text] )
Assert that condition is falsy with an optional description of the assertion $text.
Aliases: notOK, false, notok, not_ok
notDeepEqual ( $any, $val, [$text] )
Assert that $any !== $val with an optional description of the assertion $text.
Aliases: notDeepEquals, notEquivalent, notDeeply, notSame, isNotDeepEqual, isNotDeeply, isNotEquivalent, isInequivalent, not_deep_equal, not_same
notDeepLooseEqual ( $any, $val, [$text] )
Assert that $any != $val with an optional description of the assertion $text.
Aliases: not_deep_loose_equal
notLooseEqual ( $any, $val, [$text] )
Assert that $any != $val with an optional description of the assertion $text.
Aliases: notLooseEquals, not_loose_equal
notStrictEqual ( $any, $val, [$text] )
Assert that $any !== $val with an optional description of the assertion $text.
Aliases: notEqual, notEquals, isNotEqual, doesNotEqual, isInequal, notStrictEquals, isNot, not, not_strict_equal, not_equal, is_not_equal, is_not
pass ( [$text], [$options] )
Generate a passing assertion with a message $text.
plan ( $n )
Declare the number of assertions that's about to be runned. end() will be called
automatically after, or an error occurs if the number of assertions doesn't match.
restoreTimeLimit ()
Restore PHP max_execution_time.
setTimeLimit ( $seconds )
Change PHP max_execution_time.
skip ( [$text], [$options] )
Generate a skip with and optional $text ane leaving the running test.
strictEqual ( $any, $val, [$text] )
Assert that $any === $val with an optional description of the assertion $text.
Aliases: equal, equals, isEqual, strictEquals, is, strict_equal, is_equal
test ( [$name], [$options], $callback )
Generate a new test at run time.
throws ( $thrower, [$throwed], [$text] )
Assert that the function call $thrower throws an exception. $throwed can be a string, a regular expression, an exception, an array describing some exception properties, or null.
timeout ( $callback, $ms, [$text] )
Generate an assertion that should run before $ms microseconds are elapse. Or it fails with an optional $text.
todo ( [$text], [$options] )
Generate a todo with and optional $text inside a test, switching the next assertions to todo mode.
License
guitarneck/taphp 适用场景与选型建议
guitarneck/taphp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 70 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 01 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「unit-test」 「tap」 「tape」 「testing-tools」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 guitarneck/taphp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 guitarneck/taphp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 guitarneck/taphp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Provides a TAP result printer for PHPUnit.
Stand alone port of Laravel's tap method.
Arcanist util to run tests and generate code coverage reports for phpunit7 format.
PMVC Test Framework
A library that makes unit testing database-driven code in PHP a breeze. Mock the native PDO class, define query results, and inspect executed statements.
A lightweight package to add Google One Tap login to Laravel applications using Socialite
统计信息
- 总下载量: 70
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-19