PHP code example of qratorlabs / smocky

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

    

qratorlabs / smocky example snippets


public function testSomeTest(): void {
    $methodMock = new MockedMethod($this, SomeClass::class, 'someMethod', once());
    $methodMock->getMocker()->willReturn(10);

    SomeClass::someMethod(); // will return `10`
    
    SomeClass::someMethod(); // will cause error (expectation - one call)
}

class Base
{
    public static function methodName()
    {
        return 'something';
    }
}

class Child extends Base
{

}

// simulating PHPUnit test case
(new class('test') extends \PHPUnit\Framework\TestCase {

    public function test(): void
    {
        // child should instanced (or loaded any other way)
        $child = new Child();
        // mocking method of base class
        $method = new MockedClassMethod(Base::class, 'methodName');
        // at least one call should be made
        Base::methodName();
    }
})->run();