PHP code example of chadicus / test-helpers

1. Go to this page and download the library: Download chadicus/test-helpers 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/ */

    

chadicus / test-helpers example snippets


class MyClass
{
    public function doSomething()
    {
        $curl = curl_init();
        if ($curl === false) {
            throw new \Exception('curl_init() failed');
        }

        //do something with $curl ...
    }
}

class MyClass
{
    public function doSomething()
    {
        $curl = curl_init();
        if ($curl === false) {
            //@codeCoverageIgnoreStart
            throw new \Exception('curl_init() failed');
            //@codeCoverageIgnoreEnd
        }

        //do something with $curl ...
    }
}

class MyClassTest extends \PHPUnit_Framework_TestCase
{
    protected function setUp()
    {
        // prepare the curl functions for mocking
        \Chadicus\FunctionRegistry::reset(__NAMESPACE__, array('curl'));
    }

    /**
     * @expectedExceptionMessage curl_init() failed
     */
    public function testCurlInitFails()
    {
        \Chadicus\FunctionRegistry::set(
            __NAMESPACE__,
            'curl_init',
            function () {
                return false;
            }
        );

        $myClass = new MyClass();

        // this will call our custom curl_init function
        $myClass->doSomething();
    }
}