mikolajprzybysz/php-native-wrapper 问题修复 & 功能扩展

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

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

mikolajprzybysz/php-native-wrapper

最新稳定版本:v1.0.0

Composer 安装命令:

composer require mikolajprzybysz/php-native-wrapper

包简介

Object that wrappers every php native method.

README 文档

README

This project provides class that can be used to proxy calls to regular functions, therefore making them mockable like every other method call.

Install (include in composer)

"require": {
    "mikolajprzybysz/php-native-wrapper": "^1.0.0"
}

How to use:

1.Add Native class as dependency to the class using native calls

Via constructor

class SampleClass {
    /** @var Native */
    protected $native;
    public function __construct(Native $native){
        $this->native = $native;
    }
}

Via setter

class SampleClass {
    /** @var Native */
    protected $native;
    public function setNative(Native $native){
        $this->native = $native;
    }
}

2.Whenever you need to run native function, call it via $native instance:

class SampleClass {
    /** @var Native */
    protected $native;
    public function sampleMethod(){
        return $native->time();
    }
}

3.Mock it as any other class

class SampleClassTest extends \PHPUnit_Framework_TestCase {
    public function testSampleMethod(){
        $sampleTime = 123;
        $nativeMock = $this->getMock(Native::class);
        $nativeMock->expects($this->once())->method('time')->will($this->returnValue($sampleTime));
        $testObject = new SampleClass($nativeMock);
        $result = $testObject->sampleMethod();
        $this->assertEquals($sampleTime, $result);
    }
}

Unit test

./vendor/bin/phpunit test/MockTest.php --bootstrap vendor/autoload.php

Acceptance test

./vendor/bin/phpunit test/MockTest.php --bootstrap vendor/autoload.php

What it does not support

  • extract
  • sort and any method using reference in it's arguments

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-28