d

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore.

15 St Margarets, NY 10033
(+381) 11 123 4567
ouroffice@aware.com

 

KMF

Quick Tip: Unit Testing JSON Columns in Laravel

You may know that you can query against JSON columns using the column->key syntax in Laravel, but I recently learned you can use the same syntax in your tests when asserting that the database has certain data!

Query Example

FormElement::where('rules->required', null)->get();

Testing Example

/** @test */
public method a_form_element_can_be_stored
{
    // Do some stuff...
    
    $this->assertDatabaseHas('form_elements', [
        'rules->required' => null,
    ]);
}

Check out all our posts on testing with Laravel.

Credit: Source link

Previous Next
Close
Test Caption
Test Description goes like this