Skip to content

Commit

Permalink
Fixes from uts
Browse files Browse the repository at this point in the history
  • Loading branch information
edusca committed Feb 5, 2025
1 parent d9bbdf8 commit 81f309b
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 25 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
"php": ">=8.0",
"beberlei/assert": "^2.1 || ^3.0",
"bernard/normalt": "^1.0",
"symfony/event-dispatcher": "^3.0 || ^4.0"
"symfony/event-dispatcher": "v6.0.19",
"symfony/event-dispatcher-contracts": "^2"
},
"require-dev": {
"doctrine/dbal": "^2.5",
"doctrine/instantiator": "^1.0.5",
"friends-of-phpspec/phpspec-code-coverage": "^6.0",
"phpspec/phpspec": "^7.0",
"phpspec/prophecy-phpunit": "^2.0",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^9.3",
"psr/container": "^1.0",
"psr/log": "^1.0",
"symfony/console": "^3.0 || ^4.0"
"symfony/console": "v6.0.19"
},
"suggest": {
"doctrine/dbal": "Allow sending messages to simulated message queue in a database via doctrine dbal",
Expand Down
4 changes: 3 additions & 1 deletion src/Command/ConsumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ public function configure(): void
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output): void
public function execute(InputInterface $input, OutputInterface $output): int
{
$queue = $this->getQueue($input->getArgument('queue'));

$this->consumer->consume($queue, $input->getOptions());

return self::SUCCESS;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Command/ProduceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function configure(): void
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output): void
public function execute(InputInterface $input, OutputInterface $output): int
{
$name = $input->getArgument('name');
$queue = $input->getOption('queue');
Expand All @@ -52,5 +52,7 @@ public function execute(InputInterface $input, OutputInterface $output): void
}

$this->producer->produce(new PlainMessage($name, $message), $queue);

return self::SUCCESS;
}
}
4 changes: 3 additions & 1 deletion src/Driver/Delayable/DelayablePheanstalkDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
class DelayablePheanstalkDriver extends Pheanstalk\Driver implements DelayableDriver
{
public const DEFAULT_PRIORITY = 1024; // most urgent: 0, least urgent: 4294967295

/**
* {@inheritDoc}
*/
Expand All @@ -21,7 +23,7 @@ public function pushMessageWithDelay($queueName, $message, $delay): void
$this->pheanstalk->putInTube(
$queueName,
$message,
PheanstalkInterface::DEFAULT_PRIORITY,
self::DEFAULT_PRIORITY,
(int) $delay
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/Driver/Doctrine/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function configure(): void
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output): void
public function execute(InputInterface $input, OutputInterface $output): int
{
$schema = new Schema();
MessagesSchema::create($schema);
Expand All @@ -40,13 +40,15 @@ public function execute(InputInterface $input, OutputInterface $output): void
if ($input->getOption('dump-sql')) {
$output->writeln(implode(';'.\PHP_EOL, $this->getSql($sync, $schema)).';');

return;
return self::SUCCESS;
}

$output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.'.\PHP_EOL);
$output->writeln('Applying database schema changes...');
$this->applySql($sync, $schema);
$output->writeln('Schema changes applied successfully!');

return self::SUCCESS;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Envelope.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __construct(Message $message, int $delay = 0)

$this->message = $message;
$this->delay = $delay;
$this->class = $message::class;
$this->class = get_class($message);
$this->timestamp = time();
}

Expand Down
3 changes: 2 additions & 1 deletion tests/ConsumerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
use Bernard\Queue\InMemoryQueue;
use Bernard\Receiver;
use Bernard\Router;
use Prophecy\PhpUnit\ProphecyTrait;
use Prophecy\Prophecy\ObjectProphecy;

class ConsumerTest extends \PHPUnit\Framework\TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
use ProphecyTrait;

/**
* @var Router|ObjectProphecy
Expand Down
4 changes: 2 additions & 2 deletions tests/Driver/Delayable/DelayablePheanstalkDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DelayablePheanstalkDriverTest extends TestCase
{
public function setUp(): void
{
$this->pheanstalk = $this->getMockBuilder('Pheanstalk\Pheanstalk')
$this->pheanstalk = $this->getMockBuilder('Pheanstalk\PheanstalkInterface')
->setMethods(array(
'putInTube'
))
Expand All @@ -27,7 +27,7 @@ public function testItPushesMessagesWithDelay(): void
->with(
$this->equalTo('my-queue'),
$this->equalTo('This is a message'),
$this->equalTo(PheanstalkInterface::DEFAULT_PRIORITY),
$this->equalTo(DelayablePheanstalkDriver::DEFAULT_PRIORITY),
$this->equalTo(10)
);

Expand Down
3 changes: 2 additions & 1 deletion tests/Driver/Doctrine/ConnectionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

use Bernard\Driver\Doctrine\ConnectionListener;
use Doctrine\DBAL\DBALException;
use Prophecy\PhpUnit\ProphecyTrait;

class ConnectionListenerTest extends \PHPUnit\Framework\TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
use ProphecyTrait;

protected function setUp(): void
{
Expand Down
10 changes: 5 additions & 5 deletions tests/EnvelopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Bernard\Tests;

use Bernard\Exception\InvalidOperationException;
use Bernard\Message\PlainMessage;
use Bernard\Envelope;

Expand Down Expand Up @@ -33,12 +34,11 @@ public function testDelayedMetadata(): void
$this->assertEquals(10, $envelope->getDelay());
}

/**
* @expectedException Bernard\Exception\InvalidOperationException
* @expectedExceptionMessage Delay must be greater or equal than zero
*/
public function testNegativeDelay(): void
{
$envelope = new Envelope($message = new PlainMessage('SendNewsletter'), -10);
$this->expectException(InvalidOperationException::class);
$this->expectExceptionMessage('Delay must be greater or equal than zero');

new Envelope(new PlainMessage('SendNewsletter'), -10);
}
}
3 changes: 2 additions & 1 deletion tests/Event/EnvelopeEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bernard\Envelope;
use Bernard\Event\EnvelopeEvent;
use Bernard\Message;
use Symfony\Contracts\EventDispatcher\Event;

class EnvelopeEventTest extends \PHPUnit\Framework\TestCase
{
Expand All @@ -20,7 +21,7 @@ protected function setUp(): void

public function testIsEvent(): void
{
$this->assertInstanceOf('Symfony\Component\EventDispatcher\Event', new EnvelopeEvent($this->envelope, $this->queue));
$this->assertInstanceOf(Event::class, new EnvelopeEvent($this->envelope, $this->queue));
}

public function hasEnvelopeAndQueue(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/EventListener/LoggerSubscriberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
use Bernard\Event\EnvelopeEvent;
use Bernard\Event\RejectEnvelopeEvent;
use Bernard\EventListener\LoggerSubscriber;
use Prophecy\PhpUnit\ProphecyTrait;
use Psr\Log\LoggerInterface;

class LoggerSubscriberTest extends \PHPUnit\Framework\TestCase
{
use \Prophecy\PhpUnit\ProphecyTrait;
use ProphecyTrait;

public function testLogsInfoOnProduce(): void
{
Expand Down
2 changes: 1 addition & 1 deletion tests/ProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testItUsesGivenQueueName(): void

public function testWithDelay()
{
$message = new DefaultMessage('SendNewsletter');
$message = new PlainMessage('SendNewsletter');

$this->producer->produce($message, null, 10);

Expand Down
8 changes: 4 additions & 4 deletions tests/Queue/PersistentQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Bernard\Tests\Queue;

use Bernard\Envelope;
use Bernard\Exception\InvalidOperationException;
use Bernard\Queue\PersistentQueue;

class PersistentQueueTest extends AbstractQueueTest
Expand Down Expand Up @@ -123,12 +124,11 @@ protected function createQueue($name)
return new PersistentQueue($name, $this->driver, $this->serializer);
}

/**
* @expectedException Bernard\Exception\InvalidOperationException
* @expectedExceptionMessage This driver can't manage delayed messages
*/
public function testEnqueueDelayedWithNotDelayableDriver(): void
{
$this->expectException(InvalidOperationException::class);
$this->expectExceptionMessage('This driver can\'t manage delayed messages');

$envelope = new Envelope($this->createMock('Bernard\Message'), 10);

$queue = $this->createQueue('send-newsletter');
Expand Down

0 comments on commit 81f309b

Please sign in to comment.