joomla/test
Composer 安装命令:
composer require joomla/test
包简介
Joomla Test Helper Package
README 文档
README
This package is a collection of tools that make some of the jobs of unit testing easier.
TestHelper
Joomla\Test\TestHelper is a static helper class that can be used to take some of the pain out of repetitive tasks whilst unit testing with PHPUnit.
Mocking
There are two methods that help with PHPUnit mock objects.
TestHelper::assignMockCallbacks
This helper method provides an easy way to configure mock callbacks in bulk.
use Joomla\Test\TestHelper; class FooTest extends \PHPUnit_Framework_TestCase { public function testFoo() { // Create the mock. $mockFoo = $this->getMock( 'Foo', // Methods array. array(), // Constructor arguments. array(), // Mock class name. '', // Call original constructor. false ); $mockCallbacks = array( // 'Method Name' => <callback> 'method1' => array('\mockFoo', 'method1'), 'method2' => array($this, 'mockMethod2'), ); TestHelper::assignMockCallbacks($mockFoo, $this, $mockCallbacks); } public function mockMethod2($value) { return strtolower($value); } }
TestHelper::assignMockReturns
This helper method provides an easy way to configure mock returns values in bulk.
use Joomla\Test\TestHelper; class FooTest extends \PHPUnit_Framework_TestCase { public function testFoo() { // Create the mock. $mockFoo = $this->getMock( 'Foo', // Methods array. array(), // Constructor arguments. array(), // Mock class name. '', // Call original constructor. false ); $mockReturns = array( // 'Method Name' => 'Canned return value' 'method1' => 'canned result 1', 'method2' => 'canned result 2', 'method3' => 'canned result 3', ); TestHelper::assignMockReturns($mockFoo, $this, $mockReturns); } }
Reflection
There are three methods that help with reflection.
TestHelper::getValue
The TestHelper::getValue method allows you to get the value of any protected or private property.
use Joomla\Test\TestHelper; class FooTest extends \PHPUnit_Framework_TestCase { public function testFoo() { $instance = new \Foo; // Get the value of a protected `bar` property. $value = TestHelper::getValue($instance, 'bar'); } }
This method should be used sparingly. It is usually more appropriate to use PHPunit's assertAttribute* methods.
TestHelper::setValue
The TestHelper::setValue method allows you to set the value of any protected or private property.
use Joomla\Test\TestHelper; class FooTest extends \PHPUnit_Framework_TestCase { public function testFoo() { $instance = new \Foo; // Set the value of a protected `bar` property. TestHelper::setValue($instance, 'bar', 'New Value'); } }
This method is useful for injecting values into an object for the purpose of testing getter methods.
TestHelper::invoke
The TestHelper::invoke method allow you to invoke any protected or private method. After specifying the object and the method name, any remaining arguments are passed to the method being invoked.
use Joomla\Test\TestHelper; class FooTest extends \PHPUnit_Framework_TestCase { public function testFoo() { $instance = new \Foo; // Invoke the protected `bar` method. $value1 = TestHelper::invoke($instance, 'bar'); // Invoke the protected `bar` method with arguments. $value2 = TestHelper::invoke($instance, 'bar', 'arg1', 'arg2'); } }
Installation via Composer
Add "joomla/test": "~2.0" to the require block in your composer.json and then run composer install.
{
"require": {
"joomla/test": "~2.0"
}
}
Alternatively, you can simply run the following from the command line:
composer require joomla/test "~2.0"
joomla/test 适用场景与选型建议
joomla/test 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 306.52k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2013 年 03 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「unit test」 「phpunit」 「reflection」 「joomla」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 joomla/test 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 joomla/test 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 joomla/test 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
LazyPDO is a set of wrappers over PHP's standard PDO and PDOStatement classes. It enables lazy loading, serialization and decoration.
Testing Suite For Lumen like Laravel does.
Symfony bundle for unigen test generator
A cli tool which generates unit tests.
PHPUnit Testing extensions for HMTL and CSS insures valid HTML and CSS via v.Nu validator
统计信息
- 总下载量: 306.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 17
- 依赖项目数: 29
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2013-03-05