PHP code example of arron / testit

1. Go to this page and download the library: Download arron/testit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arron / testit example snippets


$mock = $this->getMockedClass($className, $mockName);

protected function mockGlobalFunction($name, $namespace = NULL)

//just call it before using global function
$this->mockGlobalFunction('time', 'YourNamespace');
//and then expect the call
$this->expectDependencyCall('global', 'time', array(), 123456789);

$timestamp = time();//can be mocked

$timestamp = \time();//can NOT be mocked

//declaration of expectation method
public function expectDependencyCall($dependencyName, $methodName, $methodArguments = array(), $returnValue = NULL)

//practical use
$this->expectDependencyCall("articleModel", "get", array(10, 5), array());
//expects that on the "articleModel" dependency "get" method will be called with arguments (offset, limit) 10, 5 and it will return empty array

//valid call in tested class would be for example
$this->articleModel->get(10,5); //where $this->articleModel is a property where mock named "articleModel" is stored

protected function setPropertyInTestSubject($name, $value)

//example
$this->setPropertyInTestSubject('state', 'notReady'); //will set property 'state' to value 'notReady' in test object

protected function getPropertyFromTestSubject($name)

//example
$this->getPropertyFromTestSubject('state'); //return value of the 'state' property in test object

protected function callTestSubjectMethod($name, array $arguments = array())

//example
$this->callTestSubjectMethod('setState', array('ready')); //will call 'setState' method with one argument 'ready',  even it is protected/private