Level 102
That is still correct in the newest phpunit. Error?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
With latest Laravel, it seems the $this part of the
$this->assertEquals('December 1, 2016', $date); is not correct.
How it should be with latest Laravel?
<?php
namespace Tests\Unit;
use App\Models\Concert;
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
class ConcertTest extends TestCase
{
/**
* A basic test example.
*
* @return void
*/
public function test_that_true_is_true()
{
/** @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);
}
}
}
Hi @tenzan
I think your code structure is wrong, your test can_get_formatted_date is inside test_that_true_is_true
Needs to be?
<?php
namespace Tests\Unit;
use App\Models\Concert;
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
class ConcertTest extends TestCase{
/**
* A basic test example.
*
* @return void
*/
public function test_that_true_is_true() {
}
/** @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);
}
}
Please or to participate in this conversation.