PHP code example of meritum / testing

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

    

meritum / testing example snippets


use Georgeff\Kernel\Environment;
use Meritum\Testing\TestingKernel;

$kernel = new TestingKernel(Environment::Testing);

$kernel->manages($httpKernel, 'http');
$kernel->manages($cliKernel, 'cli');

$kernel->boot();

$httpKernel = $kernel->get('http');

$queue = new MemoryQueue();

$kernel->instance(QueueInterface::class, $queue);

$kernel->factory(ClockInterface::class, fn() => new FrozenClock('2026-01-01'));

$kernel->instance(QueueInterface::class, $queue, 'http');

$repository = $kernel->mock(RepositoryInterface::class);
$repository->shouldReceive('find')->once()->andReturn($model);

$kernel->boot();

$kernel->setEnv('DB_DATABASE', 'file::memory:?cache=shared');

$kernel->shutdown();

use Meritum\Testing\TestCase;

final class ExampleTest extends TestCase
{
    protected function modules(): array
    {
        return [new DatabaseModule()];
    }

    protected function environment(): array
    {
        return ['DB_DATABASE' => 'file::memory:?cache=shared'];
    }

    public function test_something(): void
    {
        $this->kernel->manages($httpKernel, 'http');
        $this->kernel->mock(QueueInterface::class);

        $this->kernel->boot();

        // ...
    }
}