Symfony 3 Establish a test database for integration testing

In Symofny it is called automatically when you run tests app/config/parameters_test.yml loaded.
There, another database should then be specified, for simplicity sake with the same database user:

database_host: same_as_dev
database_port: same_as_dev
database_name: test_db
database_user: same_as_dev
database_password: same_as_dev

Then following commands must be executed on the console:
Clear cache:
am PHP / console cache:clear –env = test

Create database
am PHP / console doctrine:database:create –env = test

Create tables
HP am / console doctrine:schema:update –env = test –force

Then can fixtures are loaded and integration tests are written.

 

Run PHPUnit Unit and Integrations test with different configurations in PHPStorm

If you want to develop unit and integration tests with PHPStorm you can easily bootstrap your application and run your tests. But if you want to develop real unit tests in your local development enviroment without having a database connection or a cache, you need to make sure, that your application is configured differently, when unit tests are running. In this article you will learn how to do that and how to make PHPStorm will automatically recognize which tests/tests suites you want to execute.

Requirement:

Your integration and unit tests are seperated in 2 directories, like:

/tests/unitTests
/tests/integrationsTests

Overview more…

Variables in the @Dataprovider use PHPUnit @Depends

Unfortunately, it is currently not possible for PHPUnit testing both to highlight another test as a prerequisite for a test, to run the tests in case of an error does not occur, and at the same time a data provider for the test to use a previous test accessing the result. This is because, that data provider be initilisiert before iterating through the tests of PHPunit.

The problem

class StackTest extends PHPUnit_Framework_TestCase {
    protected static $foo;

    public function provider() { 
        print_r( self::$foo); //does not work
    }

    /**
     * @dataProvider provider
     */
    public function testOne() {
        self::$foo = array();
    }

    /**
     * @depends testOne
     * @dataProvider provider
     */
    public function testTwo( $data ) { 
    }

more…