Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Sep 28, 2024
1 parent 64ea994 commit 10017ff
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,35 @@
expect($model->is($found))->toBeTrue();
});

it('can delete attribute by setting it to null', function () {
$model = ModelStub::create([
'name' => 'John Doe',
]);

$model->update(['name' => null]);

$model->refresh();

expect($model->name)->toBeNull();
});

it('can delete multiple attributes by setting them to null', function () {
$model = ModelStub::create([
'name' => 'John Doe',
'company' => 'Acme',
]);

$model->update([
'name' => null,
'company' => null,
]);

$model->refresh();

expect($model->name)->toBeNull();
expect($model->company)->toBeNull();
});

it('throws exception when update or creating with previous null searchable attribute in values to existing', function () {
ModelStubWithSearchable::updateOrCreate([
'id' => 'foo',
Expand All @@ -201,7 +230,6 @@
ModelStub::create(['id' => $id]);
})->with([
'',
null,
])->throws(InvalidKeyException::class, 'A key is required to create a model.');

it('throws exception when creating a model that already exists', function () {
Expand Down

0 comments on commit 10017ff

Please sign in to comment.