Skip to content

Commit

Permalink
Merge pull request #9 from jadu/symfony5
Browse files Browse the repository at this point in the history
Symfony5 support
  • Loading branch information
irinikp authored Oct 27, 2023
2 parents 7cfdb00 + c256d4b commit a6dccae
Show file tree
Hide file tree
Showing 25 changed files with 303 additions and 288 deletions.
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
}
],
"require": {
"doctrine/orm": "^2.7",
"php": ">=7.1.0",
"doctrine/orm": "^2.7|^2.10",
"doctrine/doctrine-bundle": "^1.12|^2.6",
"php": ">=7.3.0",
"psr/log": "~1.0",
"symfony/options-resolver": "~2.6|~3.0"
"symfony/options-resolver": "~3.0|~4.0|~5.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
"mockery/mockery": "^0.9"
"ext-amqp": "*",
"mockery/mockery": "^1.3|^1.4",
"phpunit/phpunit": "^6.0|^7.0|^8.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Broker/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Queue implements QueueInterface
*/
protected $maxPriority;

public function __construct(Connection $connection, $name, $durable = true, array $bindings)
public function __construct(Connection $connection, $name, $durable = true, array $bindings = [])
{
$this->connection = $connection;
$this->name = $name;
Expand Down
8 changes: 4 additions & 4 deletions src/Middleware/Doctrine/ObjectManagerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Radish\Middleware\Doctrine;

use Doctrine\Common\Persistence\ManagerRegistry;
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Events;
use Doctrine\ORM\Internal\Hydration\AbstractHydrator;
Expand All @@ -14,7 +14,7 @@
class ObjectManagerMiddleware implements MiddlewareInterface
{
/**
* @var ManagerRegistry
* @var Registry
*/
protected $managerRegistry;
/**
Expand All @@ -23,10 +23,10 @@ class ObjectManagerMiddleware implements MiddlewareInterface
private $logger;

/**
* @param ManagerRegistry $managerRegistry
* @param Registry $managerRegistry
* @param LoggerInterface $logger
*/
public function __construct(ManagerRegistry $managerRegistry, LoggerInterface $logger)
public function __construct(Registry $managerRegistry, LoggerInterface $logger)
{
$this->logger = $logger;
$this->managerRegistry = $managerRegistry;
Expand Down
21 changes: 11 additions & 10 deletions tests/Broker/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
namespace Radish\Broker;

use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;

class ConnectionTest extends \PHPUnit_Framework_TestCase
class ConnectionTest extends MockeryTestCase
{
public $amqpConnection;
public $amqpChannel;
Expand All @@ -14,7 +15,7 @@ class ConnectionTest extends \PHPUnit_Framework_TestCase
public $credentials;
public $connection;

public function setUp()
public function setUp(): void
{
$this->amqpConnection = Mockery::mock('AMQPConnection', [
'connect' => null
Expand All @@ -24,7 +25,7 @@ public function setUp()
$this->amqpExchange = Mockery::mock('AMQPExchange');
$this->amqpQueue = Mockery::mock('AMQPQueue');

$this->amqpFactory = Mockery::mock('Radish\Broker\AMQPFactory', [
$this->amqpFactory = Mockery::mock(AMQPFactory::class, [
'createConnection' => $this->amqpConnection,
'createChannel' => $this->amqpChannel,
'createExchange' => $this->amqpExchange,
Expand All @@ -38,7 +39,7 @@ public function setUp()
$this->connection = new Connection($this->amqpFactory, $this->credentials);
}

public function testConnect()
public function testConnect(): void
{
$this->amqpFactory->shouldReceive('createConnection')
->with($this->credentials)
Expand All @@ -51,27 +52,27 @@ public function testConnect()
$this->connection->connect();
}

public function testDeconstructDisconnects()
public function testDeconstructDisconnects(): void
{
$this->amqpConnection->shouldReceive('disconnect')->once();

$this->connection->connect();
$this->connection->__deconstruct();
}

public function testIsConnectedWhenConnected()
public function testIsConnectedWhenConnected(): void
{
$this->connection->connect();

$this->assertTrue($this->connection->isConnected());
}

public function testIsConnectedWhenNotConnected()
public function testIsConnectedWhenNotConnected(): void
{
$this->assertFalse($this->connection->isConnected());
}

public function testGetChannel()
public function testGetChannel(): void
{
$this->amqpFactory->shouldReceive('createChannel')
->with($this->amqpConnection)
Expand All @@ -82,7 +83,7 @@ public function testGetChannel()
$this->assertTrue($this->connection->isConnected());
}

public function testCreateExchange()
public function testCreateExchange(): void
{
$this->amqpFactory->shouldReceive('createExchange')
->with($this->amqpChannel)
Expand All @@ -92,7 +93,7 @@ public function testCreateExchange()
$this->assertSame($this->amqpExchange, $this->connection->createExchange());
}

public function testCreateQueue()
public function testCreateQueue(): void
{
$this->amqpFactory->shouldReceive('createQueue')
->with($this->amqpChannel)
Expand Down
13 changes: 7 additions & 6 deletions tests/Broker/ExchangeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
namespace Radish\Broker;

use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;

class ExchangeTest extends \PHPUnit_Framework_TestCase
class ExchangeTest extends MockeryTestCase
{
public $connection;
public $exchange;

public function setUp()
public function setUp(): void
{
$this->connection = Mockery::mock('Radish\Broker\Connection');
$this->connection = Mockery::mock(Connection::class);
$this->exchange = new Exchange($this->connection, 'test_exchange', 'direct', true);
}

public function testDeclareExchange()
public function testDeclareExchange(): void
{
$amqpExchange = Mockery::mock('AMQPExchange');

Expand All @@ -40,7 +41,7 @@ public function testDeclareExchange()
$this->exchange->declareExchange();
}

public function testPublish()
public function testPublish(): void
{
$amqpExchange = Mockery::mock('AMQPExchange');

Expand All @@ -67,7 +68,7 @@ public function testPublish()
$this->exchange->publish('body', 'routing_key', 1, []);
}

public function testPublishReusesSameExchangeInstance()
public function testPublishReusesSameExchangeInstance(): void
{
$amqpExchange = Mockery::mock('AMQPExchange', [
'setName' => null,
Expand Down
29 changes: 15 additions & 14 deletions tests/Broker/QueueCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Radish\Broker;

use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\Mock;
use PHPUnit_Framework_TestCase;

class QueueCollectionTest extends PHPUnit_Framework_TestCase
class QueueCollectionTest extends MockeryTestCase
{
/**
* @var QueueCollection
Expand All @@ -21,43 +22,43 @@ class QueueCollectionTest extends PHPUnit_Framework_TestCase
*/
private $queue2;

public function setUp()
public function setUp(): void
{
$this->collection = new QueueCollection();
$this->queue1 = Mockery::mock('Radish\Broker\Queue', [
$this->queue1 = Mockery::mock(Queue::class, [
'getName' => 'a',
'pop' => Mockery::mock('Radish\Broker\Message')
'pop' => Mockery::mock(Message::class)
]);
$this->queue2 = Mockery::mock('Radish\Broker\Queue', [
$this->queue2 = Mockery::mock(Queue::class, [
'getName' => 'b',
'pop' => Mockery::mock('Radish\Broker\Message')
'pop' => Mockery::mock(Message::class)
]);
}

public function testPopReturnsMessage()
public function testPopReturnsMessage(): void
{
$this->collection->add($this->queue1);
$this->collection->add($this->queue2);

$this->queue1->shouldReceive('pop')
->once()
->andReturn(Mockery::mock('Radish\Broker\Message'));
->andReturn(Mockery::mock(Message::class));

$this->queue2->shouldReceive('pop')
->never();

$message = $this->collection->pop();

static::assertInstanceOf('Radish\Broker\Message', $message);
static::assertInstanceOf(Message::class, $message);
}

public function testPopPopsEachQueueInOrder()
public function testPopPopsEachQueueInOrder(): void
{
$this->collection->add($this->queue1);
$this->collection->add($this->queue2);

$message1 = Mockery::mock('Radish\Broker\Message');
$message2 = Mockery::mock('Radish\Broker\Message');
$message1 = Mockery::mock(Message::class);
$message2 = Mockery::mock(Message::class);

$this->queue1->shouldReceive('pop')
->once()
Expand All @@ -71,11 +72,11 @@ public function testPopPopsEachQueueInOrder()
static::assertSame($message2, $this->collection->pop());
}

public function testPopReturnsNullWhenNoMoreMessages()
public function testPopReturnsNullWhenNoMoreMessages(): void
{
$this->collection->add($this->queue1);

$message1 = Mockery::mock('Radish\Broker\Message');
$message1 = Mockery::mock(Message::class);

$this->queue1->shouldReceive('pop')
->once()
Expand Down
20 changes: 10 additions & 10 deletions tests/Broker/QueueLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
namespace Radish\Broker;

use Mockery;
use Mockery\Adapter\Phpunit\MockeryTestCase;
use Mockery\Mock;
use PHPUnit_Framework_TestCase;

class QueueLoaderTest extends PHPUnit_Framework_TestCase
class QueueLoaderTest extends MockeryTestCase
{
/**
* @var Mock|QueueRegistry
Expand All @@ -17,39 +17,39 @@ class QueueLoaderTest extends PHPUnit_Framework_TestCase
*/
private $loader;

public function setUp()
public function setUp(): void
{
$this->queueRegistry = Mockery::mock('Radish\Broker\QueueRegistry', [
'get' => Mockery::mock('Radish\Broker\Queue', [
$this->queueRegistry = Mockery::mock(QueueRegistry::class, [
'get' => Mockery::mock(Queue::class, [
'getName' => 'a',
]),
]);
$this->loader = new QueueLoader($this->queueRegistry);
}

public function testLoadGetsEachQueueFromRegistry()
public function testLoadGetsEachQueueFromRegistry(): void
{
$this->queueRegistry->shouldReceive('get')
->with('a')
->times(1)
->andReturn(Mockery::mock('Radish\Broker\Queue', [
->andReturn(Mockery::mock(Queue::class, [
'getName' => 'a',
]));

$this->queueRegistry->shouldReceive('get')
->with('b')
->times(1)
->andReturn(Mockery::mock('Radish\Broker\Queue', [
->andReturn(Mockery::mock(Queue::class, [
'getName' => 'a',
]));

$this->loader->load(['a', 'b']);
}

public function testLoadReturnsQueueCollection()
public function testLoadReturnsQueueCollection(): void
{
$collection = $this->loader->load(['a']);

static::assertInstanceOf('Radish\Broker\QueueCollection', $collection);
static::assertInstanceOf(QueueCollection::class, $collection);
}
}
Loading

0 comments on commit a6dccae

Please sign in to comment.