PHP code example of gealex / doublit

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

    

gealex / doublit example snippets


    // Get a double instance of type "dummy" for class "MyClass"
    $my_double = Doublit::dummy(MyClass::class)->getInstance();
    

    // Get a double instance of type "mock" for class "MyClass"
    $my_double = Doublit::mock(MyClass::class)->getInstance();
    

    // Test that the method "myMethod" is called a least one time
    $double::_method('myMethod')->count('>=1');
    

    // Test that the arguments passed to method "myMethod" are "value1" and "value2"
    $double::_method('myMethod')->args(['value1', 'value2']);
    

    // Make method "myMethod" return "hello"
    $my_double::_method('myMethod')->stub('hello');
    

    // Get double instance with config
    $my_double = Doublit::dummy(MyClass::class, [
        'allow_final_doubles' => true,
        'allow_non_existent_classes' => true
    ])->getInstance();