atanvarno/test-util 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

atanvarno/test-util

Composer 安装命令:

composer require atanvarno/test-util

包简介

PHPUnit test case utilities

README 文档

README

Software License Latest Version

Utility traits for PHPUnit test cases for interacting with protected and private methods and properties.

Requirements

PHP >= 7.0 is required, but the latest stable version of PHP is recommended.

Installation

$ composer require atanvarno/test-util:^0.1.0

Basic Usage

class YourTest extends \PHPUnit\Framework\TestCase
{
    // Include the traits
    use Atanvarno\PHPUnit\{CallProtectedMethodTrait, SetProtectedPropertyTrait};
    
    // Write your tests
    public function testYourMethod()
    {
        $testObject = new SomeClass();
        
        // Set an inaccessible property
        $this->setProtectedProperty($testObject, 'propertyName', 'value');
        
        // Call an inaccessible method
        $result = $this->callProtectedMethod(
            $testObject,
            'methodName',
            ['argument 1', 'argument 2', '...']
        );
        
        // Do your assertations
        // ...
    }
}

Atanvarno\PHPUnit\CallProtectedMethodTrait

Provides means to call a protected or private method of an object for test purposes.

public function callProtectedMethod($object, string $method, array $arguments = [])

Calls a protected or private method and returns its result.

Parameters

  • object $object

    Required. The instance containing the method to call.

  • string $method

    Required. The method name.

  • mixed[] $arguments

    Optional. Defaults to []. Arguments to pass to the method.

Throws

Returns

  • mixed

    The return value of the method call.

Atanvarno\PHPUnit\SetProtectedPropertyTrait

Provides means to set a protected or private property of an object for test purposes.

public function setProtectedProperty($object, string $property, $value)

Sets a protected or private property.

Parameters

  • object $object

    Required. The instance containing the property to set.

  • string $property

    Required. The property name.

  • mixed $value

    Required. The value to set.

Throws

Returns

  • void

统计信息

  • 总下载量: 102
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-05-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固