mercredi 7 août 2019

Failed to assert data into db during PHPUnit test

I'm currently following this tutorial from laravel-news.

One of the tests with PHPUnit failed to run and the test failed to assert into sqlite memory db for testing.

I've confirmed sqlite3 is up and running in my box(i'm using homestead) however when i did .databases there's only main inside

here's the env setup in my phpunit.xml

<php>
    <server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
    <server name="MAIL_DRIVER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <env name="DB_CONNECTION" value="sqlite"/>
    <env name="DB_DATABASE" value=":memory:"/>
</php>

here's the actual function with the namespace and imports

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Validation\ValidationException;

class SubmitLinksTest extends TestCase
{
    use RefreshDatabase;

    /** @test */
    public function can_submit_link(){
        $response = $this->post('/submit', [
           'title' => 'Example Title',
           'url' => 'http://example.com',
            'description' => 'Example Description',
        ]);

        $this->assertDatabaseHas('links', [
            'title' => 'Example Title'
        ]);

        $response->assertStatus(302)->assertHeader('Location', url('/'));

        $this->get('/')->assertSee('Example Title');
    }

here's the error output from PHPUnit:

1) Tests\Feature\SubmitLinksTest::can_submit_link
Failed asserting that a row in the table [links] matches the attributes {
    "title": "Example Title"
}.

The table is empty.


/home/vagrant/code/links/vendor/laravel/
framework/src/Illuminate/Foundation/Testing/
Concerns/InteractsWithDatabase.php:24/
home/vagrant/code/links/tests/Feature/SubmitLinksTest.php:23

Aucun commentaire:

Enregistrer un commentaire