2017 © Pedro Peláez
 

library php-native-wrapper

Object that wrappers every php native method.

image

mikolajprzybysz/php-native-wrapper

Object that wrappers every php native method.

  • Friday, October 30, 2015
  • by mikolajprzybysz
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Abstract (about)

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

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, (*2)

Via constructor, (*3)

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

Via setter, (*4)

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:, (*5)

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

3.Mock it as any other class, (*6)

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

The Versions

30/10 2015

dev-master

9999999-dev https://github.com/mikolajprzybysz/php-native-wrapper

Object that wrappers every php native method.

  Sources   Download

MIT

The Development Requires

by Mikołaj Przybysz

30/10 2015

v1.0.0

1.0.0.0 https://github.com/mikolajprzybysz/php-native-wrapper

Object that wrappers every php native method.

  Sources   Download

MIT

The Development Requires

by Mikołaj Przybysz