-
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.
- Loading branch information
Showing
12 changed files
with
179 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* cqrs-tactician (https://github.com/phpgears/cqrs-tactician). | ||
* CQRS implementation with League Tactician. | ||
* | ||
* @license MIT | ||
* @link https://github.com/phpgears/cqrs-tactician | ||
* @author Julián Gutiérrez <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gears\CQRS\Tactician; | ||
|
||
use Gears\CQRS\Command; | ||
use Gears\CQRS\Exception\InvalidCommandException; | ||
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor; | ||
|
||
final class CommandExtractor implements CommandNameExtractor | ||
{ | ||
/** | ||
* Extract the name from a command. | ||
* | ||
* @param mixed $command | ||
* | ||
* @throws InvalidCommandException | ||
* | ||
* @return string | ||
*/ | ||
public function extract($command) | ||
{ | ||
if (!$command instanceof Command) { | ||
throw new InvalidCommandException(\sprintf( | ||
'Command must implement "%s" interface, "%s" given', | ||
Command::class, | ||
\is_object($command) ? \get_class($command) : \gettype($command) | ||
)); | ||
} | ||
|
||
return $command->getCommandType(); | ||
} | ||
} |
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,43 @@ | ||
<?php | ||
|
||
/* | ||
* cqrs-tactician (https://github.com/phpgears/cqrs-tactician). | ||
* CQRS implementation with League Tactician. | ||
* | ||
* @license MIT | ||
* @link https://github.com/phpgears/cqrs-tactician | ||
* @author Julián Gutiérrez <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gears\CQRS\Tactician; | ||
|
||
use Gears\CQRS\Exception\InvalidQueryException; | ||
use Gears\CQRS\Query; | ||
use League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor; | ||
|
||
final class QueryExtractor implements CommandNameExtractor | ||
{ | ||
/** | ||
* Extract the name from a query. | ||
* | ||
* @param mixed $query | ||
* | ||
* @throws InvalidQueryException | ||
* | ||
* @return string | ||
*/ | ||
public function extract($query) | ||
{ | ||
if (!$query instanceof Query) { | ||
throw new InvalidQueryException(\sprintf( | ||
'Query must implement "%s" interface, "%s" given', | ||
Query::class, | ||
\is_object($query) ? \get_class($query) : \gettype($query) | ||
)); | ||
} | ||
|
||
return $query->getQueryType(); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
/* | ||
* cqrs-tactician (https://github.com/phpgears/cqrs-tactician). | ||
* CQRS implementation with League Tactician. | ||
* | ||
* @license MIT | ||
* @link https://github.com/phpgears/cqrs-tactician | ||
* @author Julián Gutiérrez <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gears\CQRS\Tactician\Tests; | ||
|
||
use Gears\CQRS\Exception\InvalidCommandException; | ||
use Gears\CQRS\Tactician\CommandExtractor; | ||
use Gears\CQRS\Tactician\Tests\Stub\CommandStub; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Command extractor test. | ||
*/ | ||
class CommandExtractorTest extends TestCase | ||
{ | ||
public function testInvalidCommand(): void | ||
{ | ||
$this->expectException(InvalidCommandException::class); | ||
$this->expectExceptionMessage('Command must implement "Gears\CQRS\Command" interface, "stdClass" given'); | ||
|
||
(new CommandExtractor())->extract(new \stdClass()); | ||
} | ||
|
||
public function testExtract(): void | ||
{ | ||
$type = (new CommandExtractor())->extract(CommandStub::instance()); | ||
|
||
static::assertSame(CommandStub::class, $type); | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
|
||
/* | ||
* cqrs-tactician (https://github.com/phpgears/cqrs-tactician). | ||
* CQRS implementation with League Tactician. | ||
* | ||
* @license MIT | ||
* @link https://github.com/phpgears/cqrs-tactician | ||
* @author Julián Gutiérrez <[email protected]> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gears\CQRS\Tactician\Tests; | ||
|
||
use Gears\CQRS\Exception\InvalidQueryException; | ||
use Gears\CQRS\Tactician\QueryExtractor; | ||
use Gears\CQRS\Tactician\Tests\Stub\QueryStub; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Query extractor test. | ||
*/ | ||
class QueryExtractorTest extends TestCase | ||
{ | ||
public function testInvalidQuery(): void | ||
{ | ||
$this->expectException(InvalidQueryException::class); | ||
$this->expectExceptionMessage('Query must implement "Gears\CQRS\Query" interface, "stdClass" given'); | ||
|
||
(new QueryExtractor())->extract(new \stdClass()); | ||
} | ||
|
||
public function testExtract(): void | ||
{ | ||
$type = (new QueryExtractor())->extract(QueryStub::instance()); | ||
|
||
static::assertSame(QueryStub::class, $type); | ||
} | ||
} |
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