What does your phpunit.xml file look like; especially the DB_ environment variables?
Aug 19, 2022
13
Level 3
Call to a member function connection() on null
Hi,
Full error message
FAIL Tests\Unit\ConcertTest
⨯ can get formatted date
FAIL Tests\Feature\ViewConcertListingTest
⨯ user can view a concert listing
---
• Tests\Unit\ConcertTest > can get formatted date
Error
Call to a member function connection() on null
at vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php:1705
1701▕ * @return \Illuminate\Database\Connection
1702▕ */
1703▕ public static function resolveConnection($connection = null)
1704▕ {
➜ 1705▕ return static::$resolver->connection($connection);
1706▕ }
1707▕
1708▕ /**
1709▕ * Get the connection resolver instance.
+7 vendor frames
8 tests/Unit/ConcertTest.php:16
Illuminate\Database\Eloquent\Model::__callStatic()
• Tests\Feature\ViewConcertListingTest > user can view a concert listing
Failed asserting that '<h1>Sample Title</h1>\n
<h2>Sample Subtitle</h2>\n
<p></p>\n
<p>Doors at 8:00pm</p>\n
<p>32.50</p>\n
<p>Sample Venue</p>\n
<p>123 Sample Address</p>\n
<p>Some City, ON 12345</p>\n
<p>For tickets, call (555) 555-5555.</p>\n
' contains "December 13, 2016".
at tests/Feature/ViewConcertListingTest.php:44
40▕ // Assert
41▕ // see the concert details
42▕ $view->assertSee('Sample Title');
43▕ $view->assertSee('Sample Subtitle');
➜ 44▕ $view->assertSee('December 13, 2016');
45▕ $view->assertSee('8:00pm');
46▕ $view->assertSee('32.50');
47▕ $view->assertSee('Sample Venue',);
48▕ $view->assertSee('123 Sample Address');
Tests: 2 failed
Time: 1.51s
Line 16 is 'date' => Carbon::parse('2016-12-01 8:00pm') of the following ConcertTest.php
<?php
namespace Tests\Unit;
use App\Models\Concert;
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
class ConcertTest extends TestCase
{
/** @test */
function can_get_formatted_date()
{
// Create concert with a known date
$concert = Concert::create([
'date' => Carbon::parse('2016-12-01 8:00pm')
]);
// Retrieve the formatted date
$date = $concert->formatted_date;
// Verify the date formatted as expected
$this->assertEquals('December 1, 2016', $date);
}
}
Level 48
What if you replace use PHPUnit\Framework\TestCase; with use Tests\TestCase; ?
1 like
Please or to participate in this conversation.