1

I'm using liip-functional-test bundle for functional testing my application. I configured a test database in the config_test.php file:

doctrine:
    dbal:
        default_connection: default
        connections:
            default:
                driver:   %database_driver_sqlite%
                path:     %database_path%

When i run my tests i get the error : Failed asserting that false is true on the last line

public function test()
{
        $this->loadFixtures(array(
        'UserBundle\DataFixtures\ORM\LoadUserData'
    ));
    $client = static::makeClient(true,
        array(
            'HTTP_HOST' => 'mylocalhost'
        ));  
  $crawler = $client->request('GET', '/login');
 $form = $crawler->selectButton('Login')->form(array(
        '_username' => 'username',
        '_password' => 'password',
    ),'POST');
    echo ' TEST RESULT   '.$client->getResponse()->getStatusCode().'   ';

    $client->submit($form);
    $this->assertTrue($client->getResponse()->isRedirect());
    $client->followRedirect();
    echo ' TEST RESULT   '.$client->getResponse()->getStatusCode().'   ';

    $crawler = $client->request('GET', '/another page');
   $this->assertTrue($crawler->filter('html:contains("some_text_on_page")')->count() > 0);

If i comment the test database configuration from config_test file, my tests run ok. All i want is something like: write fixtures in the test database and run asserts and other tests on the real database

Osmiumbin
  • 93
  • 1
  • 4
  • Have you initialized the test database with console command `doctrine:database:create --env=test`? That needs to be followed with `doctrine:schema:create --env=test`. – geoB Dec 17 '15 at 13:21
  • Yes, the database is created, schema is created, the fixture is loaded – Osmiumbin Dec 17 '15 at 13:35
  • Some diagnostic tools: clear the test cache, check test.log, use `$client->getResponse()->getContent()` to see what's on the page, use something like Firefox's add on SQLite Manager to confirm the data. – geoB Dec 17 '15 at 14:39
  • Hmm.. it doesn't passes the login stage. I believe that it checks for the credentials from my empty test database instead of my real database. – Osmiumbin Dec 17 '15 at 14:59
  • "...checks for the credentials from my empty test database..." is supposed to happen. The solution is to build a fixture that loads the test database with credentials for the user you want to test. – geoB Dec 17 '15 at 16:20
  • I've created the fixture that populates my user table but i've got the same error – Osmiumbin Dec 18 '15 at 14:01
  • 1
    You've stuffed a lot into a single function. Try smaller steps: load fixtures in `public function setup()`, test just the login in `testLogin()`, test getting a page in `testAnother()`. Plus - is '/another page' missing an underscore and the URI is really '/another_page`? – geoB Dec 18 '15 at 14:16

0 Answers0