Search code examples
laravelpostgresqljsonblaravel-5.6laravel-testing

Laravel 5.6. How to test JSON/JSONb columns


$this->assertDatabaseHas() not working with JSON/JSONb columns.

So how can I tests these types of columns in Laravel?

Currently, I have a store action. How can I perform an assertion, that a specific column with pre-defined values was saved.

Something like

['options->language', 'en']

is NOT an option, cause I have an extensive JSON with meta stuff.

How can I check the JSON in DB at once?


Solution

  • UPD

    Now can be done like that.


    I have solved it with this one-liner (adjust it to your models/fields)

    $this->assertEquals($store->settings, Store::find($store->id)->settings);