diff --git a/src/Contracts/Syncable.php b/src/Contracts/Syncable.php index 4198b0ca..29a681f8 100644 --- a/src/Contracts/Syncable.php +++ b/src/Contracts/Syncable.php @@ -16,5 +16,5 @@ interface Syncable public function triggerSyncEvent(): void; - public function getResourceCreationAttributes(): array|null; // todo come up with a better name + public function getCreationAttributes(): array|null; // todo come up with a better name } diff --git a/src/Database/Concerns/ResourceSyncing.php b/src/Database/Concerns/ResourceSyncing.php index 5fb22d1b..d4bbbf60 100644 --- a/src/Database/Concerns/ResourceSyncing.php +++ b/src/Database/Concerns/ResourceSyncing.php @@ -33,7 +33,7 @@ trait ResourceSyncing event(new SyncedResourceSaved($this, tenant())); } - public function getResourceCreationAttributes(): array|null + public function getCreationAttributes(): array|null { return null; } diff --git a/src/Listeners/UpdateSyncedResource.php b/src/Listeners/UpdateSyncedResource.php index 0d38030d..5b7d40f8 100644 --- a/src/Listeners/UpdateSyncedResource.php +++ b/src/Listeners/UpdateSyncedResource.php @@ -123,18 +123,18 @@ class UpdateSyncedResource extends QueueableListener protected function getAttributesForCreation(Syncable $model): array { - if (! $model->getResourceCreationAttributes()) { + if (! $model->getCreationAttributes()) { // Creation attributes are not specified so create the model as 1:1 copy return $model->getAttributes(); } - if (Arr::isAssoc($model->getResourceCreationAttributes())) { + if (Arr::isAssoc($model->getCreationAttributes())) { // Developer provided the default values // We will merge the default values with sync attributes - return array_merge($model->getResourceCreationAttributes(), $model->only($model->getSyncedAttributeNames())); + return array_merge($model->getCreationAttributes(), $model->only($model->getSyncedAttributeNames())); } // Developer provided the attribute names, so we'd use them to pick model attributes - return $model->only($model->getResourceCreationAttributes()); + return $model->only($model->getCreationAttributes()); } } diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index ad28c4f9..7115ca6d 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -148,7 +148,7 @@ test('creating the resource in tenant database creates it in central database as tenancy()->end(); // Assert central user and Resource user has exact same attributes and values - expect($resourceUser->getResourceCreationAttributes())->toBeNull(); + expect($resourceUser->getCreationAttributes())->toBeNull(); expect(CentralUser::first()->toArray())->toEqual(ResourceUser::first()->toArray()); }); @@ -232,7 +232,7 @@ test('creating the resource in central database creates it in tenant database as $centralUser->tenants()->attach('t1'); $centralUser = CentralUser::first(); - expect($centralUser->getResourceCreationAttributes())->toBeNull(); + expect($centralUser->getCreationAttributes())->toBeNull(); $tenant->run(function () use ($centralUser) { expect(ResourceUser::all())->toHaveCount(1); expect(ResourceUser::first()->toArray())->toEqual($centralUser->toArray()); @@ -820,7 +820,7 @@ class ResourceUser extends Model implements Syncable // override method in ResourceUser class to return attribute default values class ResourceUserWithDefaultValues extends ResourceUser { - public function getResourceCreationAttributes(): array + public function getCreationAttributes(): array { // Attributes default values when creating resources from tenant to central DB return @@ -832,7 +832,7 @@ class ResourceUserWithDefaultValues extends ResourceUser { // override method in ResourceUser class to return attribute names class ResourceUserWithAttributeNames extends ResourceUser { - public function getResourceCreationAttributes(): array + public function getCreationAttributes(): array { // Attributes used when creating resources from tenant to central DB // Notice here we are not adding "code" filed because it doesn't @@ -851,7 +851,7 @@ class ResourceUserWithAttributeNames extends ResourceUser { // override method in CentralUser class to return attribute default values class CentralUserWithDefaultValues extends CentralUser { - public function getResourceCreationAttributes(): array + public function getCreationAttributes(): array { // Attributes default values when creating resources from central to tenant model return @@ -863,7 +863,7 @@ class CentralUserWithDefaultValues extends CentralUser { // override method in CentralUser class to return attribute names class CentralUserWithAttributeNames extends CentralUser { - public function getResourceCreationAttributes(): array + public function getCreationAttributes(): array { // Attributes used when creating resources from central to tenant DB return