2016-12-04 18:19:45 +05:30
|
|
|
<?php
|
2016-12-04 22:26:49 +05:30
|
|
|
namespace tests\codeception\common\_support\amqp;
|
2016-12-04 18:19:45 +05:30
|
|
|
|
|
|
|
use common\components\RabbitMQ\Component;
|
|
|
|
use PhpAmqpLib\Connection\AbstractConnection;
|
|
|
|
|
2016-12-04 22:26:49 +05:30
|
|
|
class TestComponent extends Component {
|
|
|
|
|
|
|
|
private $sentMessages = [];
|
|
|
|
|
|
|
|
public function init() {
|
|
|
|
\yii\base\Component::init();
|
|
|
|
}
|
2016-12-04 18:19:45 +05:30
|
|
|
|
|
|
|
public function getConnection() {
|
|
|
|
/** @noinspection MagicMethodsValidityInspection */
|
|
|
|
/** @noinspection PhpMissingParentConstructorInspection */
|
|
|
|
return new class extends AbstractConnection {
|
|
|
|
public function __construct(
|
|
|
|
$user,
|
|
|
|
$password,
|
|
|
|
$vhost,
|
|
|
|
$insist,
|
|
|
|
$login_method,
|
|
|
|
$login_response,
|
|
|
|
$locale,
|
|
|
|
\PhpAmqpLib\Wire\IO\AbstractIO $io,
|
|
|
|
$heartbeat
|
|
|
|
) {
|
|
|
|
// ничего не делаем
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
public function sendToExchange($exchangeName, $routingKey, $message, $exchangeArgs = [], $publishArgs = []) {
|
2016-12-04 22:26:49 +05:30
|
|
|
$this->sentMessages[$exchangeName][] = $this->prepareMessage($message);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string|null $exchangeName
|
|
|
|
* @return \PhpAmqpLib\Message\AMQPMessage[]
|
|
|
|
*/
|
|
|
|
public function getSentMessages(string $exchangeName = null) : array {
|
|
|
|
if ($exchangeName !== null) {
|
|
|
|
return $this->sentMessages[$exchangeName] ?? [];
|
2017-05-29 16:50:28 +05:30
|
|
|
}
|
2016-12-04 22:26:49 +05:30
|
|
|
|
2017-05-29 16:50:28 +05:30
|
|
|
$messages = [];
|
|
|
|
foreach($this->sentMessages as $exchangeGroup) {
|
|
|
|
foreach ($exchangeGroup as $message) {
|
|
|
|
$messages[] = $message;
|
|
|
|
}
|
2016-12-04 22:26:49 +05:30
|
|
|
}
|
2017-05-29 16:50:28 +05:30
|
|
|
|
|
|
|
return $messages;
|
2016-12-04 18:19:45 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
}
|