定制 markbaker/spymaster 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

markbaker/spymaster

Composer 安装命令:

composer require --dev markbaker/spymaster

包简介

SpyMaster is a small library, for use in testing, that allows access to verify the values of protected and private properties in a class that is being tested, without needing to modify the class using Reflection.

README 文档

README

SpyMaster is a small library, for use in testing, that allows access to verify the values of protected and private properties in a class that is being tested, or execution of protected or private methods, without needing to modify the class using Reflection.

Build Status License

Requirements

  • PHP version 7.0.0 or higher

Installation

Using composer, either

composer require markbaker/spymaster

or add the library to your existing composer.json file, and let composer's own autoloader work its magic.

Or you can download the files from github, and include the bootstrap.php file to enable the SpyMaster autoloader

Usage

There are a few examples of use in the /examples folder.

// Instantiate your object
$myObject = new myObject();

// Infiltrate a read-only Spy that can view the properties of $myObject 
$spy = (new SpyMaster\SpyMaster($myObject))
    ->infiltrate();

// Access the $value property of $myObject
// Any property of $myObject can be accessed, whether it is public, protected or private
echo $spy->value;
// Instantiate your object
$myObject = new myObject();

// Infiltrate a read-write spy that can both read and modify the properties of $myObject 
$spy = (new SpyMaster\SpyMaster($myObject))
    ->infiltrate(SpyMaster\SpyMaster::SPY_READ_WRITE);

// Access the $value property of $myObject
// Any property of $myObject can be accessed, whether it is public, protected or private
echo $spy->value;

// A Read-Write Spy also allows you to set new values for those properties
$spy->value += 1000;
echo $spy->value;

Spies cannot unset properties, nor can they access properties that are created dynamically after the Spy is infiltrated.

To execute private or protected methods inside an object, you can use a Manipulator.

// Instantiate your object
$myObject = new myObject();

// Create a Manipulator
$Manipulator = new Manipulator();

// Call the Manipulator's execute() method, passing in the object and name of the method to execute, together with any arguments
$result = $Manipulator->execute($myObject, 'add', 3, 5);
// This example would execute the add() method of the myObject instance with arguments 3 and 5

License

SpyMaster is published under the MIT license

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固