Skip to content

Commit

Permalink
Merge 2106d71 into 4770e96
Browse files Browse the repository at this point in the history
  • Loading branch information
evgeek authored Aug 7, 2023
2 parents 4770e96 + 2106d71 commit 49b0f1f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
19 changes: 12 additions & 7 deletions src/Integration/Laravel/Contracts/SyncableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,42 @@
interface SyncableModel
{
/**
* @var string
* @return string
*/
public function getKeyName();

/**
* @var string
* @return string
*/
public function getKey();

/**
* @var static|null
* @return static|null
*/
public function fresh();

/**
* @var array
* @return array
*/
public function getTableSyncableAttributes();

/**
* @var string
* @return array
*/
public function getTableSyncableDeletedAttributes();

/**
* @return string
*/
public function classForSync();

/**
* @var bool
* @return bool
*/
public function exists();

/**
* @var string
* @return string
*/
public function routingKey();
}
8 changes: 4 additions & 4 deletions src/Integration/Laravel/Syncer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private function syncTable(SyncableModel $model, string $event): void

private function getSyncableAttributes(SyncableModel $model): array
{
if (!$model->exists()) {
return $this->pkAttributes($model);
}
$syncableAttributes = $model->exists() ?
$model->getTableSyncableAttributes() :
$model->getTableSyncableDeletedAttributes();

return array_merge($this->pkAttributes($model), $model->getTableSyncableAttributes());
return array_merge($this->pkAttributes($model), $syncableAttributes);
}

private function needsPublishAttributes(SyncableModel $model, array $attributes): bool
Expand Down
5 changes: 5 additions & 0 deletions src/Integration/Laravel/TableSyncable.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public function getTableSyncableAttributes(): array
return $this->getAttributes();
}

public function getTableSyncableDeletedAttributes(): array
{
return [];
}

public function classForSync(): string
{
return static::class;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protected function setUp(): void
{
parent::setUp();

$this->spyPublisher = $this->makeSpyPublsiher();
$this->spyPublisher = $this->makeSpyPublisher();

$this->app->bind(Publisher::class, function () {
return $this->spyPublisher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected function setUp(): void
{
parent::setUp();

$this->spyPublisher = $this->makeSpyPublsiher();
$this->spyPublisher = $this->makeSpyPublisher();

$this->app->bind(Publisher::class, function () {
return $this->spyPublisher;
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/Laravel/Traits/SpyPublisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

trait SpyPublisher
{
protected function makeSpyPublsiher(): Publisher
protected function makeSpyPublisher(): Publisher
{
return new class() implements Publisher {
public $messages;
Expand Down

0 comments on commit 49b0f1f

Please sign in to comment.