dmaicher / doctrine-test-bundle

Symfony bundle to isolate your app's doctrine database tests and improve the test performance
MIT License
1.08k stars 61 forks source link

Test database instructions #123

Closed igneus closed 4 years ago

igneus commented 4 years ago

Hi, I've been trying to make the bundle's test suite work and having some difficulties.

$ composer install went OK

$ vendor/bin/phpunit complained about a missing file parameters.yml, through trial and error I found that it should be placed in the Tests/Functional directory and that there's provided a template parameters.yml.dist. I created a MySQL database, set connection details in parameters.ymland ran the tests again. Now they fail like

There were 7 errors:

1) Tests\Functional\FunctionalTest::testChangeDbState
Doctrine\DBAL\Exception\TableNotFoundException: An exception occurred while executing 'SELECT COUNT(*) FROM test':

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'doctrine_test_bundle.test' doesn't exist

/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:42
/home/igneus/github_hacking/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php:99
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:169
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php:149
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:914
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:588
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:47

Caused by
Doctrine\DBAL\Driver\PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'doctrine_test_bundle.test' doesn't exist

/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:83
/home/igneus/github_hacking/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticConnection.php:41
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:911
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:588
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:47

Caused by
PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'doctrine_test_bundle.test' doesn't exist

/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:78
/home/igneus/github_hacking/doctrine-test-bundle/src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticConnection.php:41
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:911
/home/igneus/github_hacking/doctrine-test-bundle/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:588
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:47

[etc. etc.]

Inspection of tests/Functional/FunctionalTest.php suggests that the test database should probably have just one table named test with one column named test, so I created such a table (with a single column of type TEXT), but now the tests fail like

There were 6 failures:

1) Tests\Functional\FunctionalTest::testPreviousChangesAreRolledBack
Failed asserting that '1' matches expected 0.

/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:54

2) Tests\Functional\FunctionalTest::testChangeDbStateWithinTransaction
Failed asserting that '1' matches expected 0.

/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:59

3) Tests\Functional\FunctionalTest::testPreviousChangesAreRolledBackAfterTransaction
Failed asserting that '1' matches expected 0.

/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:75

4) Tests\Functional\FunctionalTest::testChangeDbStateWithSavePoint
Failed asserting that '1' matches expected 0.

/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:80

5) Tests\Functional\FunctionalTest::testPreviousChangesAreRolledBackAfterUsingSavePoint
Failed asserting that '1' matches expected 0.

/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:91

6) Tests\Functional\FunctionalTest::testRollBackChangesWithReOpenedConnection
Failed asserting that '1' matches expected 0.

/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:35
/home/igneus/github_hacking/doctrine-test-bundle/tests/Functional/FunctionalTest.php:99

FAILURES!
Tests: 19, Assertions: 49, Failures: 6.

Any idea what the problem is?

dmaicher commented 4 years ago

Can you try running make test?

See https://github.com/dmaicher/doctrine-test-bundle/blob/master/makefile#L8

Edit: Probably you did not use the correct phpunit config?

This one for phpunit 8+: https://github.com/dmaicher/doctrine-test-bundle/blob/master/tests/phpunit.xml

igneus commented 4 years ago

Thank you very much, I confirm that make test or vendor/bin/phpunit --config tests/phpunit.xml both work like a charm.