PHP code example of atanvarno / test-util

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

    

atanvarno / test-util example snippets


class YourTest extends \PHPUnit\Framework\TestCase
{
    // Include the traits
    use Atanvarno\PHPUnit\{CallProtectedMethodTrait, SetProtectedPropertyTrait};
    
    // Write your tests
    public function testYourMethod()
    {
        $testObject = new SomeClass();
        
        // Set an inaccessible property
        $this->setProtectedProperty($testObject, 'propertyName', 'value');
        
        // Call an inaccessible method
        $result = $this->callProtectedMethod(
            $testObject,
            'methodName',
            ['argument 1', 'argument 2', '...']
        );
        
        // Do your assertations
        // ...
    }
}

public function callProtectedMethod($object, string $method, array $arguments = [])

public function setProtectedProperty($object, string $property, $value)