mrtnzlml-archive / testbench

:green_apple: Simple integration testing tool for Nette applications
http://zlml.cz/jednoduche-testovani-pro-uplne-kazdeho
41 stars 13 forks source link

U velmi jednoduchých testů, kde není potřeba DIC se nezavolá druhý parametr Testbench\Bootstrap::setup #30

Closed mrtnzlml closed 7 years ago

mrtnzlml commented 8 years ago

Nezavolá se z toho důvodu, že DIC není vůbec potřeba (tím pádem nefunguje třeba robot loader). Failing test:

<?php

namespace Tests;

use App;
use Nette;
use Tester;

require __DIR__ . '/bootstrap.php';

/**
 * @testCase
 */
class ComponentTest extends Tester\TestCase
{

    use \Testbench\TComponent;

    public function testRender()
    {
        $control = new App\Components\DrinkingStreamControl();
        $this->checkRenderOutput($control, 'drink');
    }

}

(new ComponentTest)->run();

Kde DrinkingStreamControl je:

<?php

namespace App\Components;

use Nette;

class DrinkingStreamControl extends Nette\Application\UI\Control
{

    public function __construct()
    {
        parent::__construct(); // vždy je potřeba volat rodičovský konstruktor
    }

    public function render()
    {
        $this->template->setFile( __DIR__ . '/DrinkingStream.latte' );
        $this->template->render();
    }

}

A boostrap.php:

<?php

require __DIR__ . '/../vendor/autoload.php';

Testbench\Bootstrap::setup(__DIR__ . '/../temp', function (\Nette\Configurator $configurator) {
    $configurator->createRobotLoader()->addDirectory([
        __DIR__ . '/../app',
        __DIR__ . '/../components/DrinkingStream',
    ])->register();

    $configurator->addParameters([
        'appDir' => __DIR__ . '/../app',
    ]);

    $configurator->addConfig(__DIR__ . '/../app/config/config.neon');
    //$configurator->addConfig(__DIR__ . '/tests.neon');
});

Dočasné řešení je trošku potunit bootstrap:

<?php

require __DIR__ . '/../vendor/autoload.php';

$tempDir = __DIR__ . '/../temp';

(new \Nette\Loaders\RobotLoader())
    ->setCacheStorage(new \Nette\Caching\Storages\FileStorage($tempDir))
    ->addDirectory([
        __DIR__ . '/../app',
    ])->register();

Testbench\Bootstrap::setup($tempDir, function (\Nette\Configurator $configurator) {
    $configurator->addParameters([
        'appDir' => __DIR__ . '/../app',
    ]);

    $configurator->addConfig(__DIR__ . '/../app/config/config.neon');
    $configurator->addConfig(__DIR__ . '/../app/config/config.local.neon');
});

https://forum.nette.org/cs/25627-jak-otestovat-obsah-prvku-control#p177380