-
-
Notifications
You must be signed in to change notification settings - Fork 167
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from spatie/add-weight-to-handlers
Support weight property to event handlers
- Loading branch information
Showing
10 changed files
with
175 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Spatie\EventSourcing\Tests\TestClasses; | ||
|
||
class ProjectorWithWeightTestHelper | ||
{ | ||
public array $calledBy = []; | ||
|
||
public function calledBy(string $className): void | ||
{ | ||
$this->calledBy[] = $className; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Spatie\EventSourcing\Tests\TestClasses\Projectors; | ||
|
||
use Spatie\EventSourcing\EventHandlers\Projectors\Projector; | ||
use Spatie\EventSourcing\Tests\TestClasses\Events\MoneyAddedEvent; | ||
use Spatie\EventSourcing\Tests\TestClasses\ProjectorWithWeightTestHelper; | ||
|
||
class ProjectorWithHighWeight extends Projector | ||
{ | ||
public int $weight = 5; | ||
|
||
public function __construct( | ||
private ProjectorWithWeightTestHelper $projectorWithWeightTestHelper, | ||
) { | ||
} | ||
|
||
public function onMoneyAdded(MoneyAddedEvent $event): void | ||
{ | ||
$this->projectorWithWeightTestHelper->calledBy(static::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Spatie\EventSourcing\Tests\TestClasses\Projectors; | ||
|
||
use Spatie\EventSourcing\EventHandlers\Projectors\Projector; | ||
use Spatie\EventSourcing\Tests\TestClasses\Events\MoneyAddedEvent; | ||
use Spatie\EventSourcing\Tests\TestClasses\ProjectorWithWeightTestHelper; | ||
|
||
class ProjectorWithLowWeight extends Projector | ||
{ | ||
public int $weight = 1; | ||
|
||
public function __construct( | ||
private ProjectorWithWeightTestHelper $projectorWithWeightTestHelper, | ||
) { | ||
} | ||
|
||
public function onMoneyAdded(MoneyAddedEvent $event): void | ||
{ | ||
$this->projectorWithWeightTestHelper->calledBy(static::class); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
tests/TestClasses/Projectors/ProjectorWithNegativeWeight.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Spatie\EventSourcing\Tests\TestClasses\Projectors; | ||
|
||
use Spatie\EventSourcing\EventHandlers\Projectors\Projector; | ||
use Spatie\EventSourcing\Tests\TestClasses\Events\MoneyAddedEvent; | ||
use Spatie\EventSourcing\Tests\TestClasses\ProjectorWithWeightTestHelper; | ||
|
||
class ProjectorWithNegativeWeight extends Projector | ||
{ | ||
public int $weight = -5; | ||
|
||
public function __construct( | ||
private ProjectorWithWeightTestHelper $projectorWithWeightTestHelper, | ||
) { | ||
} | ||
|
||
public function onMoneyAdded(MoneyAddedEvent $event): void | ||
{ | ||
$this->projectorWithWeightTestHelper->calledBy(static::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Spatie\EventSourcing\Tests\TestClasses\Projectors; | ||
|
||
use Spatie\EventSourcing\EventHandlers\Projectors\Projector; | ||
use Spatie\EventSourcing\Tests\TestClasses\Events\MoneyAddedEvent; | ||
use Spatie\EventSourcing\Tests\TestClasses\ProjectorWithWeightTestHelper; | ||
|
||
class ProjectorWithoutWeight extends Projector | ||
{ | ||
public function __construct( | ||
private ProjectorWithWeightTestHelper $projectorWithWeightTestHelper, | ||
) { | ||
} | ||
|
||
public function onMoneyAdded(MoneyAddedEvent $event): void | ||
{ | ||
$this->projectorWithWeightTestHelper->calledBy(static::class); | ||
} | ||
} |