This package is abandoned and no longer maintained. The author suggests using the netpromotion/symfony-up package instead.

Nette Bootstrap and Test-Case for PHPUnit

v1.2.0 2016-11-12 11:06 UTC

This package is not auto-updated.

Last update: 2019-02-20 19:04:14 UTC



Base bootstrap class is self-explanatory, just use it naturally.



Special configuration for unit testing

If you need special configuration for unit testing (f.e. different database connection) you can simply modify Bootstrap::getConfigFiles method.


class Bootstrap extends \PetrKnap\Nette\Bootstrap\Bootstrap
    protected function getConfigFiles()
        return array(
            __DIR__ . "/cfg/config.neon",
            self::getOption(self::OPTION_IS_TEST_RUN) ? __DIR__ . "/cfg/test.neon" : __DIR__ . "/cfg/local.neon"

You can modify any other method the same way if you need different log dir, etc.

Test Case

There is prepared NetteTestCase, base class for your unit tests. This class requires defined constant NETTE_BOOTSTRAP_CLASS, you can defined it in your phpunit.xml:

      <const name="NETTE_BOOTSTRAP_CLASS" value="Bootstrap"/>

or in your own test case:


class NetteTestCase extends \PetrKnap\Nette\Bootstrap\PhpUnit\NetteTestCase
    const NETTE_BOOTSTRAP_CLASS = "Bootstrap";

Container access

For access to application container in test use method NetteTestCase::getContainer.

Presenter testing

Test case simulates Application\Request instead of Http\Request.

For presenter testing use method NetteTestCase::runPresenter.


class NetteTestCase extends \PetrKnap\Nette\Bootstrap\PhpUnit\NetteTestCase
    public function testHelloWorld()
        /** @var \Nette\Application\Responses\TextResponse $response */
        $response = $this->runPresenter("World", "hello"); // calls WorldPresenter::actionHello
        $html = (string) $response->getSource(); // renders output
        $this->assertContains("Hello, world!", $html);

How to install

Run composer require petrknap/nette-bootstrap or merge this JSON code with your project composer.json file manually and run composer install. Instead of dev-master you can use one of released versions.

    "require": {
        "petrknap/nette-bootstrap": "dev-master"

Or manually clone this repository via git clone or download this repository as ZIP and extract files into your project.