Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Sep 23, 2024
1 parent 8d6387c commit a1deeb5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function setAttribute(string $key, mixed $value): self
$value = $value ? '1' : '0';
}

$this->attributes[$key] = $value;
$this->attributes[$key] = (string) $value;

return $this;
}
Expand Down
37 changes: 37 additions & 0 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,40 @@
expect(ModelStub::query())->toBeInstanceOf(Query::class);
expect((new ModelStub)->newQuery())->toBeInstanceOf(Query::class);
});

it('can be refreshed', function () {
$model = ModelStub::create();

$model->name = 'John Doe';

$model->save();

$model->refresh();

expect($model->name)->toBe('John Doe');
});

it('can be refreshed with custom key', function () {
$model = ModelStubWithCustomKey::create(['custom' => 'foo']);

$model->custom = 'bar';

$model->save();

$model->refresh();

expect($model->custom)->toBe('bar');
});

it('can be re-retrieved with fresh', function () {
$model = ModelStub::create();

$model->name = 'John Doe';

$model->save();

$fresh = $model->fresh();

expect($fresh->is($model))->toBeTrue();
expect($fresh->name)->toBe('John Doe');
});

0 comments on commit a1deeb5

Please sign in to comment.