Last active
January 2, 2019 15:04
-
-
Save Jmrich/752adaea13645ba496fa5b8110962261 to your computer and use it in GitHub Desktop.
Assert database has json values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// user class | |
class User extends Authenticatable | |
{ | |
use Notifiable; | |
protected $fillable = [ | |
'name', 'email', 'password', | |
]; | |
protected $hidden = [ | |
'password', 'remember_token', | |
]; | |
protected $casts = [ | |
'settings' => 'array' | |
]; | |
} | |
// migration | |
public function up() | |
{ | |
Schema::create('users', function (Blueprint $table) { | |
$table->increments('id'); | |
$table->string('name'); | |
$table->string('email')->unique(); | |
$table->string('password'); | |
$table->json('settings')->nullable(); | |
$table->rememberToken(); | |
$table->timestamps(); | |
}); | |
} | |
// test | |
public function testCanVerifyJsonColumn() | |
{ | |
$expectedData = [ | |
'profile_picture' => 'profile picture', | |
]; | |
$user = factory(User::class)->create([ | |
'settings' => $expectedData | |
]); | |
$this->assertDatabaseHas('users', [ | |
'settings' => json_encode($expectedData), | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For Postgres
json
fails butjsonb
is okay.