PHP code example of kgabryel / test-tools

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

    

kgabryel / test-tools example snippets

 
    class MyTest extends BaseTestCase
    {
        public function testExample(): void
        {
            $mock = $this->getMock(
                DummyClass::class,
                new AllowedMethodsList(),
                new ReturnsValueMethod('return1', null, 42),
                new VoidMethod('withException', null),
            );
        
            $this->assertSame(42, $mock->return1());
            $mock->withException();
        }
    }

    #[Handler(MyCustomHandler::class)]
    class MyCustomMethod extends BaseMethod
    {
        // konstruktor, parametry, itp.
    }

    class MyCustomHandler extends BaseHandler
    {
        protected function applyBehavior(InvocationStubber $mock): void
        {
            // dodatkowa konfiguracja
        }
    }

    class MyTest extends BaseTestCase
    {
        public function testExample(): void
        {
            $mock = $this->getMock(
                DummyClass::class,
                new AllowedMethodsList(),
                new MyCustomMethod('return1', null, 42),
            );
        }
    }
bash
# Nazwa kontenera PHP w Dockerze
PHP_CONTAINER="php"

# Ścieżka do katalogu projektu wewnątrz kontenera
PROJECT_DIR="/var/www/html/test-tools"
TOOLS_DIR="${PROJECT_DIR}/tools"