PHP code example of pccomponentes / ddd-testing

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

    

pccomponentes / ddd-testing example snippets


use PcComponentes\Ddd\Testing\Util\PhpUnit\IterableMockTrait;
use PHPUnit\Framework\TestCase;

final class Testing extends TestCase
{
    use IterableMockTrait;

    public function testMethod()
    {
        $mockedItem1 = $this->createMock(\stdClass::class);
        // Assertions in mock
        $mockedItem2 = $this->createMock(\stdClass::class);
        // Assertions in mock

        $mockedIterator = $this->addIterableValuesToMock(
            $this->createMock(\Iterator::class), // Your iterable mock
            [
                $mockedItem1,
                $mockedItem2,
            ],
        );
        // ...
    }
}

use PcComponentes\Ddd\Testing\Util\PhpUnit\SerializableMockTrait;
use PHPUnit\Framework\TestCase;

final class Testing extends TestCase
{
    use SerializableMockTrait;

    public function testMethod()
    {
        $valueToReturnOnSerialize = 'some compatible with serialization method declared';

        $serializableMock = $this->addJsonSerializationToMock( 
            $this->createMock(\JsonSerializable::class), // Your mock which implements jsonSerialize method 
            $this->once(), // Or other InvocationOrder
            $valueToReturnOnSerialize,
        );
        // ...
    }
}