2017 © Pedro Peláez
 

library nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

image

petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  • Thursday, June 29, 2017
  • by petrknap
  • Repository
  • 1 Watchers
  • 0 Stars
  • 69 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 3 % Grown

The README.md

Nette Bootstrap and Test-Case for PHPUnit

Container

Base bootstrap class is self-explanatory, just use it naturally., (*1)

Bootstrap::getContainer()->getByType("Nette\\Application\\Application")->run();

Testing

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., (*2)

<?php

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., (*3)

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:, (*4)

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

or in your own test case:, (*5)

<?php

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., (*6)

Presenter testing

Test case simulates Application\Request instead of Http\Request., (*7)

For presenter testing use method NetteTestCase::runPresenter., (*8)

<?php

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., (*9)

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

Or manually clone this repository via git clone https://github.com/petrknap/nette-bootstrap.git or download this repository as ZIP and extract files into your project., (*10)

The Versions

29/06 2017
12/11 2016

dev-develop

dev-develop https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2016
12/11 2016

v1.2.0-rc3

1.2.0.0-RC3 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2016

v1.2.0-rc2

1.2.0.0-RC2 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

12/11 2016

v1.2.0-rc1

1.2.0.0-RC1 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

07/11 2016
06/11 2016

v1.0.4

1.0.4.0 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

06/11 2016

v1.0.3

1.0.3.0 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

03/11 2016

v1.0.2

1.0.2.0 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

31/10 2016

v1.0.1

1.0.1.0 https://github.com/petrknap/nette-bootstrap

Nette Bootstrap and Test-Case for PHPUnit

  Sources   Download

MIT

The Requires

 

The Development Requires

31/10 2016