2017 © Pedro Peláez
 

library testbench

Simple integration testing tool for Nette Framework applications

image

mrtnzlml/testbench

Simple integration testing tool for Nette Framework applications

  • Saturday, October 14, 2017
  • by mrtnzlml
  • Repository
  • 11 Watchers
  • 42 Stars
  • 36,702 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 12 Forks
  • 4 Open issues
  • 27 Versions
  • 2 % Grown

The README.md

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

Build Status, (*2)

Tested against PHP 5.6 and 7.0. Please read this wiki., (*3)

Heavily inspired by these GitHub projects: - Kdyby/TesterExtras, Librette tests, Nette tests and damejidlo/modular-testcase, (*4)

And article(s): - Bootstrap your integration testing database (Jiří Pudil) - Testování presenterů v Nette (me), (*5)

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

You can find few examples in this readme or take a look to the tests folder in this project., (*7)

Installation

$ composer require mrtnzlml/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:, (*8)

  • Doctrine 2
  • Nette\Database

For another databases please send PR or open issue., (*9)

Minimal code

At first you need classic bootstrap file (just example, DIY):, (*10)

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

testbench:
    sqls: #what should be loaded after empty database creation
        - %appDir%/../sqls/1.sql
        - %appDir%/../sqls/2.sql

And you are ready to go:, (*12)

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

Please read this article., (*14)

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

The Versions

13/03 2016

v2.0.4

2.0.4.0

Simple integration testing tool for Nette Framework applications

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

07/03 2016

v2.0.3

2.0.3.0

Simple integration testing tool for Nette Framework applications

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

03/03 2016

v2.0.2

2.0.2.0

Simple integration testing tool for Nette Framework applications

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

19/02 2016

v2.0.1

2.0.1.0

Simple integration testing tool for Nette Framework applications

  Sources   Download

GPL-3.0 BSD-3-Clause GPL-2.0

The Requires

 

The Development Requires

27/03 2015