mirror of
https://github.com/anikeen-com/id.git
synced 2026-11-02 05:39:35 +00:00
Declare the billable's API caches, so Eloquent models can still be saved
The caches were undeclared properties: on an Eloquent model they went through Model::__set into the attributes, and save() failed with "no such column: ordersCache". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fd96e559af
commit
be59602b30
2 files changed
+46
No files matched your search
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Anikeen\Id\Tests;
|
||||
|
||||
use Anikeen\Id\Billable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BillableModelTest extends TestCase
|
||||
{
|
||||
public function test_cached_api_results_are_not_model_attributes(): void
|
||||
{
|
||||
$user = new class extends Model {
|
||||
use Billable;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
public function cacheAll(): void
|
||||
{
|
||||
foreach (['addresses', 'countries', 'defaultPaymentMethod', 'invoices', 'orders', 'paymentMethods', 'subscriptions', 'transactions', 'userData'] as $name) {
|
||||
$this->{$name.'Cache'} = 'cached';
|
||||
}
|
||||
}
|
||||
};
|
||||
$user->email = 'ada@example.com';
|
||||
|
||||
$user->cacheAll();
|
||||
|
||||
// save() would otherwise write them as columns ("no such column: ordersCache")
|
||||
$this->assertSame(['email' => 'ada@example.com'], $user->getAttributes());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user