PHP code example of snailweb / php-tests-helpers

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

    

snailweb / php-tests-helpers example snippets


class MyClassTest
{
    use Snailweb\Helpers\Tests\AccessProtectedTrait;

    public function testMyMethod()
    {
        // Invoke method
        $returnValue = $this->invokeMethod($object, 'methodName', ['arg1', 'arg2']);

        // Get attribute
        $attributeValue = $this->getAttribute($object, 'attributeName');

        // Set attribute
        $this->setAttribute($object, 'attributeName', $attributeValue);
    }
}

class MyClassTest extends TestCase
{
    use Snailweb\Helpers\Tests\TestIteratorTrait;
    
    public function setUp(): void
    {
        $this->setUpIterator(MyClass::class, 'key', 'array');
    }

    // Do your methods tests
    // ...
}

class MyClassTest extends TestCase
{
    use Snailweb\Helpers\Tests\TestIteratorTrait{
        testConstruct as testIteratorConstruct;
    }
    
    public function setUp(): void
    {
        $this->setUpIterator(MyClass::class, 'key', 'array');
    }

    public function testConstruct()
    {
        $this->testIteratorConstruct();

        // Do your constructor tests
        // ...
    }

    // Do your methods tests
    // ...
}

class MyClassTest extends TestCase
{
    use Snailweb\Helpers\Tests\TestSplSubjectTrait;
    
    public function setUp(): void
    {
        $this->setUpSplSubject(MyClass::class, 'observers');
    }

    // Do your methods tests
    // ...
}