forked from event-engine/php-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
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 event-engine#17 from bitExpert/fix/check_name_uniq…
…ueness Ensure command, query and event names are unique
- Loading branch information
Showing
2 changed files
with
143 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?php | ||
/** | ||
* This file is part of event-engine/php-engine. | ||
* (c) 2018-2019 prooph software GmbH <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace EventEngineTest; | ||
|
||
use EventEngine\DocumentStore\DocumentStore; | ||
use EventEngine\DocumentStore\InMemoryDocumentStore; | ||
use EventEngine\EventEngine; | ||
use EventEngine\EventStore\EventStore; | ||
use EventEngine\JsonSchema\JsonSchema; | ||
use EventEngine\JsonSchema\JustinRainbowJsonSchema; | ||
use EventEngine\Logger\DevNull; | ||
use EventEngine\Logger\SimpleMessageEngine; | ||
use EventEngine\Messaging\Message; | ||
use EventEngine\Persistence\InMemoryConnection; | ||
use EventEngine\Prooph\V7\EventStore\InMemoryEventStore; | ||
use EventEngine\Prooph\V7\EventStore\ProophEventStore; | ||
use EventEngine\Runtime\PrototypingFlavour; | ||
use EventEngine\Schema\Schema; | ||
use Psr\Container\ContainerInterface; | ||
use Ramsey\Uuid\Uuid; | ||
|
||
class EventEngineUniqueNameTest extends BasicTestCase | ||
{ | ||
const CMD_REGISTER_USER = 'RegisterUser'; | ||
const EV_USER_REGISTERED = 'UserHasRegistered'; | ||
const QY_LIST_USERS = 'ListUsers'; | ||
/** | ||
* @var EventEngine | ||
*/ | ||
private $eventEngine; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->eventEngine = new EventEngine(new JustinRainbowJsonSchema()); | ||
|
||
$this->eventEngine->registerCommand(self::CMD_REGISTER_USER, JsonSchema::object([])); | ||
$this->eventEngine->registerEvent(self::EV_USER_REGISTERED, JsonSchema::object([])); | ||
$this->eventEngine->registerQuery(self::QY_LIST_USERS, JsonSchema::object([])); | ||
} | ||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_register_command_as_event() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/Command with name/'); | ||
|
||
$this->eventEngine->registerEvent(self::CMD_REGISTER_USER, JsonSchema::object([])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_register_command_as_query() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/Command with name/'); | ||
|
||
$this->eventEngine->registerQuery(self::CMD_REGISTER_USER, JsonSchema::object([])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_register_event_as_command() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/Event with name/'); | ||
|
||
$this->eventEngine->registerCommand(self::EV_USER_REGISTERED, JsonSchema::object([])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_register_event_as_query() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/Event with name/'); | ||
|
||
$this->eventEngine->registerQuery(self::EV_USER_REGISTERED, JsonSchema::object([])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_register_query_as_command() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/Query with name/'); | ||
|
||
$this->eventEngine->registerCommand(self::QY_LIST_USERS, JsonSchema::object([])); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function it_does_not_allow_to_register_query_as_event() | ||
{ | ||
$this->expectException(\RuntimeException::class); | ||
$this->expectExceptionMessageRegExp('/Query with name/'); | ||
|
||
$this->eventEngine->registerEvent(self::QY_LIST_USERS, JsonSchema::object([])); | ||
} | ||
} |