Skip to content

Commit

Permalink
Working on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Jul 7, 2016
1 parent 3cba8aa commit ca5b132
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<php>
<!-- "Real" test RabbitMQ -->
<var name="rabbitmq_host" value="localhost" />
<var name="rabbitmq_port" value="5672" />
<var name="rabbitmq_user" value="guest" />
<var name="rabbitmq_password" value="guest" />
</php>
Expand Down
10 changes: 6 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Client {

/**
* RabbitMq channel
* @var AMQPChannel
* @var \AMQPChannel
*/
private $channel = null;

Expand All @@ -68,7 +68,7 @@ class Client {

public function __construct($host, $port, $user, $password) {
$this->host = $host;
$this->port = $port;
$this->port = ($port !== null) ? $port : 5672;
$this->user = $user;
$this->password = $password;
}
Expand Down Expand Up @@ -137,8 +137,10 @@ public function setRabbitMqObjects(array $rabbitMqObjects) {

/**
* Connection to the RabbitMq service with AMQPStreamConnection
*
* @return AMQPChannel
*/
private function getConnection() {
public function getChannel() {
if(!$this->connection) {
$this->connection = new AMQPStreamConnection($this->host, $this->port, $this->user, $this->password);

Expand All @@ -152,7 +154,7 @@ private function getConnection() {
$rabbitMqObject->init($this->channel);
}
}
return $this->connection;
return $this->channel;
}

}
23 changes: 15 additions & 8 deletions src/Objects/Exchange.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php
namespace Mouf\AmqpClient\Objects;

use Mouf\AmqpClient\Client;
use Mouf\AmqpClient\RabbitMqObjectInterface;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Message\AMQPMessage;

class Exchange implements RabbitMqObjectInterface{

/**
*
* @var Binding
* @var Client
*/
private $to;
private $client;

/**
* Name
* @var string
Expand Down Expand Up @@ -78,8 +79,10 @@ class Exchange implements RabbitMqObjectInterface{
* @param string $name
* @param string $type direct, topic, headers or fanout
*/
public function __contruct(Binding $to, $name, $type) {
$this->to = $to;
public function __construct(Client $client, $name, $type) {
$this->client = $client;
$this->name = $name;
$this->type = $type;
}

/**
Expand Down Expand Up @@ -231,8 +234,12 @@ public function init(AMQPChannel $amqpChannel) {
}
}

public function publish($message) {

public function publish(AMQPMessage $message, $routingKey, $mandatory = false,
$immediate = false,
$ticket = null) {
$channel = $this->client->getChannel();

$channel->basic_publish($message, $this->name, $routingKey, $mandatory, $immediate, $ticket);
}

}
25 changes: 25 additions & 0 deletions tests/Objects/ExchangeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php


namespace Mouf\AmqpClient\Objects;


use Mouf\AmqpClient\Client;

class ExchangeTest extends \PHPUnit_Framework_TestCase
{
public function testExchange()
{
global $rabbitmq_host;
global $rabbitmq_port;
global $rabbitmq_user;
global $rabbitmq_password;

$client = new Client($rabbitmq_host, $rabbitmq_port, $rabbitmq_user, $rabbitmq_password);
$client->setPrefetchCount(1);

$exchange = new Exchange('test_exchange', 'fanout');


}
}

0 comments on commit ca5b132

Please sign in to comment.