When I run the phpunit command vendor/bin/phpunit I get this error. I did not understand where I make a mistake. can anyone solve this problem? This is terminal error output
$ vendor/bin/phpunit
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
.E. 3 / 3 (100%)
Time: 301 ms, Memory: 24.00 MB
There was 1 error:
1) Tests\Unit\DatabaseTest::testDatabase
Error: Call to undefined method Tests\Unit\DatabaseTest::assertDatabaseHas()
C:\xampp\htdocs\supportcrm\tests\Unit\DatabaseTest.php:18
ERRORS!
Tests: 3, Assertions: 2, Errors: 1.
lara
and this is my test file code.
<?php
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class DatabaseTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function testDatabase()
{
// Make call to application...
$this->assertDatabaseHas('users', [
'email' => 'admin@aynsoft.com',
]);
}
}
The assertDatabaseHas is part of the trait InteractsWithDatabase ( see: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Testing/Concerns/InteractsWithDatabase.php#L22-L29 )
That is added to the use Illuminate\Foundation\Testing\TestCase ( see: https://github.com/laravel/framework/blob/6.x/src/Illuminate/Foundation/Testing/TestCase.php#L22 )
If you let your DatabaseTest extend Illuminate\Foundation\Testing\TestCase instead of PHPUnit\Framework\TestCase you got this assertions.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community