Skip to content
Advertisement

Falling testing Laravel assertModelExists

Making a test for database with Laravel (8.44.0) assetion assertModelExists(), fails on an error.

Error : Call to undefined method TestsFeatureCommuneTest::assertModelExists()

The test class looks like this

<?php

namespace TestsFeature;

use AppModelsCommune;
use IlluminateFoundationTestingConcernsInteractsWithDatabase;
use IlluminateFoundationTestingRefreshDatabase;
use IlluminateFoundationTestingWithFaker;
use TestsTestCase;

class CommuneTest extends TestCase
{
    use RefreshDatabase, InteractsWithDatabase;

    /**
     * Test can save a commune model on DB
     *
     * @return void
     * @test
     */
    public function canStoreDb()
    {
        $commune = Commune::factory()->create();
        $this->assertModelExists($commune);
    }
}

What do you think is missing?

Advertisement

Answer

The assertModelExists method was added September 2021:

https://github.com/laravel/framework/pull/38766

Version 8.44.0 was released May 2021:

https://github.com/laravel/framework/releases/tag/v8.44.0

So just update Laravel to the latest 8.x release and you should be good to go.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement