Support the ongoing development of Laravel.io →
Database Testing
Last updated 2 years ago.
0

What does "ExampleTest.php" look like? My best guest is that in your testTwo() method, you have a case issue: "config" instead of "Config".

Last updated 9 years ago.
0

Pretty much the basic template.. besides setUp() and tearDown(), these methods are available:

public function testBasicExample()
{
    $response = $this->call('GET', '/');

    $this->assertResponseOk();
}

public function testTwo()
{
    $this->assertTrue(true);
}

testBasicExample() fetches the correct route (containing database calls and stuff). This is the test succeeding without having tearDown() implemented. testTwo() never succeeds.

0

If you want to check it out by yourself, I've created a project on GitHub. Just check it out, run composer update and run phpunit. You will see the test failing.

Remove the second test at tests/ExampleTest.php, run phpunit again and it will succeed. Hope you can help me fixing it.. Guess I'm missing something.

0

I had the exact same problem.

Oddly enough I solved it by removed the call to flush() by overriding tearDown()

Put this in TestCase.php

public function tearDown() {
    // Don't perform any tear down operations right now
}

Any additional insights on this would be helpful

Last updated 9 years ago.
0

Thanks for the reply! Sadly, that doesn't solve the problem completely. You're right, it then runs the tests, but it won't reset the application. So if you're trying to for example use

$this->call('GET', '/');

twice (in two different tests or classes), to fetch two different routes, it will fail. Hope there's another solution than that. Would be kind of bad if I'm only able to use that call once.

Last updated 9 years ago.
0

I have kind of the same error. Using Artisan::call('migrate'); in my Lumen tests gives me. Fatal error: Call to a member function call() on a non-object in /vendor/illuminate/support/Facades/Facade.php on line 210

0

I am not sure about my solution :)

Put this in TestCase.php

public function setUp()
{
    parent::setUp();
    $this->createApplication();
}
0

If you have a db call like this in any of your seeders:

DB::table('users')->delete();

Then the issue is that DB is not being resolved correctly, that is, is not being resolved from the main app container, but rather from a generic one (I think).

Anyway, as a temporary fix you could write those sentences like this:

$this->container['db']->table('user')->truncate();

In a more general form, change this:

DB::

for this:

$this->container['db']->

As a side note, it doesn't matter if you have facades turned on or off on bootstrap/app.php.

$app->withFacades();
Last updated 9 years ago.
0

MiniCodeMonkey said:

I had the exact same problem.

Oddly enough I solved it by removed the call to flush() by overriding tearDown()

Put this in TestCase.php

public function tearDown() {
   // Don't perform any tear down operations right now
}

Any additional insights on this would be helpful

This work for me.

Last updated 9 years ago.
0

Hi,

Hope this helps someone. The error was solved for me if you change the ordering of your method calls in function tearDown()

public function tearDown(){
    //perform your cleanup operations here
    ...

    //call parent::tearDown() lastly, this removed the error.
    parent::tearDown();
}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

KarimG karimg Joined 22 Apr 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.