antstudiocz / testbench
Simple integration testing tool for Nette Framework applications
Requires
- php: ^7.4 || ^8.0
- antstudiocz/kdyby-fake-session: ^3.1.1
- nette/application: ^2.4 || ^v3.0
- nette/bootstrap: ^2.4 || ^v3.0
- nette/di: ^2.4 || ^v3.0
- nette/safe-stream: ^2.3
- nette/security: ^2.4 || ^v3.0
- nette/tester: ^2.0
- nette/utils: ^2.4 || ^v3.0
Requires (Dev)
- contributte/console: ^0.10.x-dev
- dek-cz/doctrine: ^3.4.0
- dek-cz/doctrine-cache: ^3.1.2
- doctrine/common: ^3.0
- kdyby/doctrine-dbal-batchimport: dev-master
- kdyby/events: ^5.0.1
- latte/latte: ^2.4
- nette/database: ^2.4 || ^v3.0
- nette/forms: ^2.4 || ^v3.0
- nette/robot-loader: ^2.4 || ^v3.0
- nettrine/migrations: ^0.8
- nextras/migrations: dev-master
- tracy/tracy: ^2.4
Suggests
- kdyby/doctrine: Allows enhanced database tests using Doctrine
- kdyby/doctrine-dbal-batchimport: Allows SQL scripts import for Doctrine (required with kdyby/doctrine)
- nette/database: Allows enhanced database tests using Nette\Database
- nettrine/migrations: Migrate database to the fresh state
- nextras/migrations: Migrate database to the fresh state
- dev-master
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4
- v2.3.1
- v2.3
- v2.2.1
- v2.2
- v2.1.6
- v2.1.5
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0
- v2.0-rc.2
- v2.0-rc.1
- 1.2.1
- 1.2
- 1.1.1
- 1.1
- 1.0
- dev-php82
- dev-fix-tpresenter
- dev-add-silent-transactional-test-mode
- dev-fix-migrations
- dev-php8
- dev-tcomponent-fix
- dev-expand-tcomponent
- dev-remove-abandoned-packages
- dev-transactional-db-tests
This package is not auto-updated.
Last update: 2024-12-11 19:51:56 UTC
README
At this moment I don't have time, energy and money to maintain this project. But it's a shame so if you depend on this project and you want to become a sponsor or develop it further please don't hesitate to contact me. Otherwise, I am not able to guarantee bright future of this repo... :)
Tested against PHP 5.6 and 7.0. 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 (me)
Simple test bench for Nette Framework projects
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.
Installation
$ composer require antstudiocz/testbench
Testbench itself doesn't need database. But if you want to use Testbench\TDoctrine
or Testbench\TNetteDatabase
trait you have to setup database for the first connection. You should use standard database configuration - nothing special. You can see example in tests/tests.local.neon.dist
file. Empty database is good enough for Testbench. Supported databases are:
- Doctrine 2
- Nette\Database
For another databases please send PR or open issue.
Minimal code
At 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.
You should also create config file e.g. tests.neon
. This file is needed only for database tests at this moment. In this file you should configure your project before tests:
testbench: sqls: #what should be loaded after empty database creation - %appDir%/../sqls/1.sql - %appDir%/../sqls/2.sql
And you are ready to go:
<?php //HomepagePresenterTest.phpt 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.
Give it a shot!
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: