Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests and allow partly run #49

Merged
merged 33 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3809795
Add more tests and allow partly run
viktorprogger Jul 8, 2020
a52c579
Add CallableJob tests
viktorprogger Jul 8, 2020
fda15e2
Apply fixes from StyleCI
samdark Jul 8, 2020
370dc16
Remove unused use
samdark Jul 10, 2020
b1fdb01
Merge branch 'master' into tests
viktorprogger Aug 3, 2020
1f6c65b
Adjust tests for changes the master branch
viktorprogger Aug 3, 2020
016268b
More tests and bugfixes
viktorprogger Aug 3, 2020
1a72788
Remove debug
viktorprogger Aug 3, 2020
c7ed560
Typed property accessing bugfix
viktorprogger Aug 25, 2020
c66fcfa
Make test classes final
viktorprogger Aug 25, 2020
b34ba53
New event configuration
viktorprogger Aug 25, 2020
9070819
Upgrade infection version
viktorprogger Aug 26, 2020
4e18b3e
Fix more tests with events
viktorprogger Sep 3, 2020
7835cfa
Remove unused
viktorprogger Sep 3, 2020
03112bd
Cover QueueDependentInterface
viktorprogger Sep 3, 2020
f5b0a30
Apply fixes from StyleCI
samdark Sep 3, 2020
49f3db7
Test bugfixes
viktorprogger Sep 10, 2020
6a3476c
Merge branch 'master' into tests
samdark Sep 11, 2020
b4afdc6
Dependency removing is started
viktorprogger Sep 11, 2020
668dd16
Continue with dependency removing
viktorprogger Sep 13, 2020
4d19e28
Apply fixes from StyleCI
samdark Sep 13, 2020
4774175
Continue with dependency removing
viktorprogger Sep 13, 2020
870ccdb
Replace $this->assert with self::assert
viktorprogger Sep 13, 2020
c16f0a9
Remove redundant test
viktorprogger Sep 13, 2020
84ec9b9
Remove unused and fix code style
viktorprogger Sep 13, 2020
66d83ed
Apply fixes from StyleCI
samdark Sep 13, 2020
53a1529
Skip failed tests
viktorprogger Sep 13, 2020
b7ee33c
Update phpunit configuration
viktorprogger Sep 16, 2020
a0a0129
Sort packages in composer.json
viktorprogger Sep 16, 2020
233601e
Rename namespace to fit the convention
viktorprogger Sep 16, 2020
b82e270
Minor fixes
viktorprogger Sep 16, 2020
e564ed0
Make new test class final
viktorprogger Sep 16, 2020
915cde9
Remove infection log file
viktorprogger Sep 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
samdark marked this conversation as resolved.
Show resolved Hide resolved
{
$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