Skip to content

Instantly share code, notes, and snippets.

@ScullWM
Created July 10, 2017 08:30
Show Gist options
  • Save ScullWM/7e5302be6e282afe5611f7429266525c to your computer and use it in GitHub Desktop.
Save ScullWM/7e5302be6e282afe5611f7429266525c to your computer and use it in GitHub Desktop.
Mock Asynch bus
<?php
namespace Xeonys\Tests\Features\Mock;
use Rezzza\CommandBus\Domain\CommandBusInterface;
use Rezzza\CommandBus\Domain\CommandInterface;
class CommandBusMock implements CommandBusInterface
{
const FILENAME = 'async_queue';
private $cmd = array();
public function getHandleType()
{
return;
}
public function handle(CommandInterface $command, $priority = null)
{
$this->cmd[] = $this->dumpCmd($command);
file_put_contents(__DIR__.'/../../../../web/'.self::FILENAME . '.json', json_encode(['items' => $this->cmd]));
}
private function dumpCmd(CommandInterface $command)
{
$className = get_class($command);
$user = $command->getUser();
$connection = $command->getConnection();
return [
'className' => $className,
'user' => $user,
'connection' => $connection,
'channel' => $command->getChannel()->getName(),
'cmd' => $command,
];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment