-
Notifications
You must be signed in to change notification settings - Fork 5
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 #536 from patchlevel/improve-deployment
worker should not discover new subscriptions in running process
- Loading branch information
Showing
6 changed files
with
472 additions
and
1 deletion.
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
66 changes: 66 additions & 0 deletions
66
tests/Integration/Subscription/Subscriber/ProfileNewProjection.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,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Integration\Subscription\Subscriber; | ||
|
||
use Doctrine\DBAL\Connection; | ||
use Doctrine\DBAL\Schema\Table; | ||
use Patchlevel\EventSourcing\Attribute\Projector; | ||
use Patchlevel\EventSourcing\Attribute\Setup; | ||
use Patchlevel\EventSourcing\Attribute\Subscribe; | ||
use Patchlevel\EventSourcing\Attribute\Teardown; | ||
use Patchlevel\EventSourcing\EventBus\Message; | ||
use Patchlevel\EventSourcing\Subscription\Subscriber\SubscriberUtil; | ||
use Patchlevel\EventSourcing\Tests\Integration\Subscription\Events\ProfileCreated; | ||
|
||
use function assert; | ||
|
||
#[Projector('profile_2')] | ||
final class ProfileNewProjection | ||
{ | ||
use SubscriberUtil; | ||
|
||
public function __construct( | ||
private Connection $connection, | ||
) { | ||
} | ||
|
||
#[Setup] | ||
public function create(): void | ||
{ | ||
$table = new Table($this->tableName()); | ||
$table->addColumn('id', 'string')->setLength(36); | ||
$table->addColumn('firstname', 'string')->setLength(255); | ||
$table->setPrimaryKey(['id']); | ||
|
||
$this->connection->createSchemaManager()->createTable($table); | ||
} | ||
|
||
#[Teardown] | ||
public function drop(): void | ||
{ | ||
$this->connection->createSchemaManager()->dropTable($this->tableName()); | ||
} | ||
|
||
#[Subscribe(ProfileCreated::class)] | ||
public function handleProfileCreated(Message $message): void | ||
{ | ||
$profileCreated = $message->event(); | ||
|
||
assert($profileCreated instanceof ProfileCreated); | ||
|
||
$this->connection->executeStatement( | ||
'INSERT INTO ' . $this->tableName() . ' (id, firstname) VALUES(:id, :firstname);', | ||
[ | ||
'id' => $profileCreated->profileId->toString(), | ||
'firstname' => $profileCreated->name, | ||
], | ||
); | ||
} | ||
|
||
private function tableName(): string | ||
{ | ||
return 'projection_' . $this->subscriberId(); | ||
} | ||
} |
Oops, something went wrong.