Skip to content

Commit

Permalink
Add more tests and allow partly run (yiisoft#49)
Browse files Browse the repository at this point in the history
* Add more tests and allow partly run
* Add CallableJob tests
* Apply fixes from StyleCI
* Remove unused use
* Adjust tests for changes the master branch
* More tests and bugfixes
* Remove debug
* Typed property accessing bugfix
* Make test classes final
* New event configuration
* Upgrade infection version
* Fix more tests with events
* Remove unused
* Cover QueueDependentInterface
* Apply fixes from StyleCI
* Test bugfixes
* Dependency removing is started
* Continue with dependency removing
* Apply fixes from StyleCI
* Continue with dependency removing
* Replace $this->assert with self::assert
* Remove redundant test
* Remove unused and fix code style
* Apply fixes from StyleCI
* Skip failed tests
* Update phpunit configuration
* Sort packages in composer.json
* Rename namespace to fit the convention
* Minor fixes
* Make new test class final
* Remove infection log file
  • Loading branch information
viktorprogger authored Sep 21, 2020
1 parent ff63a29 commit 3f557f0
Show file tree
Hide file tree
Showing 40 changed files with 765 additions and 564 deletions.
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,14 @@
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.1",
"yiisoft/friendly-exception": "^1.0",
"yiisoft/injector": "^1.0",
"yiisoft/serializer": "^3.0@dev"
},
"require-dev": {
"infection/infection": "^0.16.0",
"pda/pheanstalk": "*",
"infection/infection": "^0.17.0",
"phan/phan": "^3.0",
"phpunit/phpunit": "^9.3",
"yiisoft/composer-config-plugin": "^1.0@dev",
"yiisoft/di": "^3.0@dev",
"yiisoft/log": "^3.0@dev",
"yiisoft/yii-console": "^3.0@dev",
"phan/phan": "^3.0"
"yiisoft/test-support": "3.0.x-dev"
},
"suggest": {
"ext-pcntl": "Need for process signals"
Expand Down
6 changes: 4 additions & 2 deletions config/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
use Psr\Container\ContainerInterface;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\ListenerProviderInterface;
use Yiisoft\Di\Container;
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
use Yiisoft\EventDispatcher\Provider\Provider;
use Yiisoft\Serializer\JsonSerializer;
use Yiisoft\Serializer\SerializerInterface;
use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Yii\Queue\Cli\LoopInterface;
use Yiisoft\Yii\Queue\Cli\SignalLoop;
Expand All @@ -21,5 +22,6 @@
WorkerInterface::class => Reference::to(QueueWorker::class),
ListenerProviderInterface::class => Provider::class,
ContainerInterface::class => fn (ContainerInterface $container) => $container,
LoopInterface::class => SignalLoop::class
LoopInterface::class => SignalLoop::class,
SerializerInterface::class => JsonSerializer::class,
];
5 changes: 3 additions & 2 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
]
},
"logs": {
"text": "php:\/\/stderr",
"text": "infection.log",
"badge": {
"branch": "master"
}
},
"mutators": {
"@default": true
"@default": true,
"ProtectedVisibility": false
}
}
29 changes: 16 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
>
<coverage>
<include>
<directory>./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Test Suite">
<directory>./tests/unit</directory>
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>./src</directory>
</whitelist>
</filter>
</phpunit>
4 changes: 2 additions & 2 deletions src/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use InvalidArgumentException;
use Yiisoft\Yii\Queue\Enum\JobStatus;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Payload\AttemptsRestrictedPayloadInterface;
use Yiisoft\Yii\Queue\Payload\DelayablePayloadInterface;
use Yiisoft\Yii\Queue\Payload\PrioritisedPayloadInterface;
use Yiisoft\Yii\Queue\Payload\AttemptsRestrictedPayloadInterface;
use Yiisoft\Yii\Queue\MessageInterface;

interface DriverInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/SynchronousDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
use InvalidArgumentException;
use Yiisoft\Yii\Queue\Cli\LoopInterface;
use Yiisoft\Yii\Queue\Enum\JobStatus;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Payload\PayloadInterface;
use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Queue;
use Yiisoft\Yii\Queue\QueueDependentInterface;
use Yiisoft\Yii\Queue\Worker\WorkerInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AfterExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Yii\Queue\Event;

use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

final class AfterExecution
Expand Down
2 changes: 1 addition & 1 deletion src/Event/AfterPush.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Yii\Queue\Event;

use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

final class AfterPush
Expand Down
2 changes: 1 addition & 1 deletion src/Event/BeforeExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Yii\Queue\Event;

use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

final class BeforeExecution
Expand Down
2 changes: 1 addition & 1 deletion src/Event/BeforePush.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Yii\Queue\Event;

use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

final class BeforePush
Expand Down
2 changes: 1 addition & 1 deletion src/Event/JobFailure.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Psr\EventDispatcher\StoppableEventInterface;
use Throwable;
use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

final class JobFailure implements StoppableEventInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/JobFailureException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use RuntimeException;
use Throwable;
use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;

class JobFailureException extends RuntimeException
{
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/PayloadNotSupportedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function getSolution(): ?string
The solution is in one of these:
- Check which interfaces does $driverClass support and remove not supported interfaces from $payloadName.
- Use another driver which supports all interfaces you need. Officially supported drivers are:
- None yet :) Work is in progress.
- yiisoft/yii-queue-amqp
SOLUTION;
}
}
2 changes: 1 addition & 1 deletion src/Message.php → src/Message/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Yii\Queue;
namespace Yiisoft\Yii\Queue\Message;

class Message implements MessageInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Yiisoft\Yii\Queue;
namespace Yiisoft\Yii\Queue\Message;

interface MessageInterface
{
Expand Down
3 changes: 3 additions & 0 deletions src/Payload/BasicPayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
class BasicPayload implements PayloadInterface
{
protected string $name;
/**
* @var mixed $data It can be anything what can be serialized with the queue driver serializer
*/
protected $data;
protected array $meta;

Expand Down
41 changes: 0 additions & 41 deletions src/Payload/PayloadDefinition.php

This file was deleted.

14 changes: 11 additions & 3 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
use Yiisoft\Yii\Queue\Event\BeforePush;
use Yiisoft\Yii\Queue\Event\JobFailure;
use Yiisoft\Yii\Queue\Exception\PayloadNotSupportedException;
use Yiisoft\Yii\Queue\Message\Message;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Payload\AttemptsRestrictedPayloadInterface;
use Yiisoft\Yii\Queue\Payload\BasicPayload;
use Yiisoft\Yii\Queue\Payload\DelayablePayloadInterface;
use Yiisoft\Yii\Queue\Payload\PayloadInterface;
use Yiisoft\Yii\Queue\Payload\PrioritisedPayloadInterface;
use Yiisoft\Yii\Queue\Payload\AttemptsRestrictedPayloadInterface;
use Yiisoft\Yii\Queue\Worker\WorkerInterface;

/**
Expand Down Expand Up @@ -107,13 +109,19 @@ public function push(PayloadInterface $payload): ?string

/**
* Execute all existing jobs and exit
*
* @param int $max
*/
public function run(): void
public function run(int $max = 0): void
{
$this->logger->debug('Start processing queue messages.');
$count = 0;

while ($this->loop->canContinue() && $message = $this->driver->nextMessage()) {
while (
($max <= 0 || $max > $count)
&& $this->loop->canContinue()
&& $message = $this->driver->nextMessage()
) {
$this->handle($message);
$count++;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Worker/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Yiisoft\Yii\Queue\Event\BeforeExecution;
use Yiisoft\Yii\Queue\Event\JobFailure;
use Yiisoft\Yii\Queue\Exception\JobFailureException;
use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

final class Worker implements WorkerInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Worker/WorkerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Yiisoft\Yii\Queue\Worker;

use Yiisoft\Yii\Queue\MessageInterface;
use Yiisoft\Yii\Queue\Message\MessageInterface;
use Yiisoft\Yii\Queue\Queue;

interface WorkerInterface
Expand Down
2 changes: 2 additions & 0 deletions tests/App/DelayablePayload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

class DelayablePayload extends SimplePayload implements DelayablePayloadInterface
{
protected string $name = 'delayable';

public function getDelay(): int
{
return 1;
Expand Down
7 changes: 7 additions & 0 deletions tests/App/DummyInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Yiisoft\Yii\Queue\Tests\App;

interface DummyInterface
{
}
20 changes: 0 additions & 20 deletions tests/App/EventManager.php

This file was deleted.

15 changes: 0 additions & 15 deletions tests/App/PrioritizedPayload.php

This file was deleted.

39 changes: 0 additions & 39 deletions tests/App/QueueHandler.php

This file was deleted.

Loading

0 comments on commit 3f557f0

Please sign in to comment.