Tested against PHP 7.4. Please read this wiki.
Heavily inspired by these GitHub projects:
- Kdyby/TesterExtras, Librette tests, Nette tests and damejidlo/modular-testcase
And article(s):
- Bootstrap your integration testing database (Jiří Pudil)
- Testování presenterů v Nette (Martin Zlámal)
Write integration tests as simple as possible. This project helps you to write tests very quickly. DRY! The main goal of this project is to make testing very simple for everyone and help with the difficult start.
You can find few examples in this readme or take a look to the tests folder in this project.
$ composer require --dev nexendrie/testbenchAt first, you need classic bootstrap file (just example, DIY):
<?php
require __DIR__ . '/../vendor/autoload.php';
Testbench\Bootstrap::setup(__DIR__ . '/_temp', function (\Nette\Configurator $configurator) {
$configurator->createRobotLoader()->addDirectory([
__DIR__ . '/../app',
])->register();
$configurator->addParameters([
'appDir' => __DIR__ . '/../app',
]);
$configurator->addConfig(__DIR__ . '/../app/config/config.neon');
$configurator->addConfig(__DIR__ . '/tests.neon');
});It's important, that we are not creating dependency injection container here. You can use autoload from composer if you don't want to use robot loader.
And you are ready to go:
<?php
require __DIR__ . '/../bootstrap.php';
/**
* @testCase
*/
class HomepagePresenterTest extends \Tester\TestCase
{
use \Testbench\TPresenter;
public function testRenderDefault()
{
$this->checkAction('Homepage:default');
}
public function testRenderDefaultModule()
{
$this->checkAction('Module:Homepage:default');
}
}
(new HomepagePresenterTest())->run();You can easily write cover with tests UI\Controls, restricted areas, forms, signals, redirects, ...
Please read this article.
Look at the tests in this project. You'll see how to use it properly. There are examples in tests folder or in the wiki. Learn how to use these traits: