atoum / deprecated-extension
atoum 扩展,用于避免在弃用错误上失败
1.0.0
2016-01-08 17:19 UTC
Requires (Dev)
- atoum/atoum: >=1.0,<3.0
This package is auto-updated.
Last update: 2024-08-29 04:03:29 UTC
README
此扩展允许您避免将 E_USER_DEPRECATED
错误视为错误,并在测试结束时显示弃用调用列表。
当您的库使用 trigger_error
函数来指示方法已弃用,或者当您在测试中使用实现该功能的类时,您可能不希望看到测试失败。此扩展允许即使有弃用调用,您的 atoum 测试也能通过,因此您将能够以自己的速度迁移弃用调用。
示例
让我们看这个例子
<?php namespace fooNs { class foo { public function foo() { trigger_error('Deprecated since 2.0. use ->bar instead', E_USER_DEPRECATED); return "foo"; } } } namespace fooNs\tests\units { use mageekguy\atoum; class foo extends atoum\test { public function testFoo() { $this ->if($testedClass = new \fooNs\foo) ->then ->string($testedClass->foo()) ->isEqualTo('foo') ; } } }
没有扩展时测试失败,输出如下
使用扩展时测试通过,并在测试结束时显示弃用调用。
安装
使用 composer 安装扩展
composer require --dev atoum/deprecated-extension
扩展将被自动加载。如果您想卸载它,可以在配置文件中添加以下内容
<?php // .atoum.php use mageekguy\atoum\deprecated; $runner->removeExtension(deprecated\extension::class);
其他示例
错误测试
您仍然可以使用 atoum 的错误断言。但请注意,测试的错误不会在输出结束的报告中显示。例如
public function testError() { $this ->if($testedClass = new \fooNs\foo) ->then ->string($testedClass->foo()) ->error("Deprecated since 2.0. use ->bar instead", E_USER_DEPRECATED)->exists() ; }
链接
许可证
deprecated-extension 在 MIT 许可下发布。有关详细信息,请参阅捆绑的 LICENSE 文件。