What does "ExampleTest.php" look like? My best guest is that in your testTwo() method, you have a case issue: "config" instead of "Config".
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.
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.
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
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.
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
I am not sure about my solution :)
Put this in TestCase.php
public function setUp()
{
parent::setUp();
$this->createApplication();
}
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();
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.
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();
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community