Skip to content

Commit

Permalink
Refactor tests (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorprogger authored Mar 13, 2020
1 parent c849e34 commit af5f096
Show file tree
Hide file tree
Showing 26 changed files with 134 additions and 1,000 deletions.
20 changes: 9 additions & 11 deletions config/common.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Serializer\PhpSerializer;
use Yiisoft\Serializer\SerializerInterface;
use Yiisoft\Yii\Queue\Drivers\Sync\Queue;
use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\EventDispatcher\ListenerProviderInterface;
use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
use Yiisoft\EventDispatcher\Provider\Provider;
use Yiisoft\Yii\Queue\Workers\Worker as QueueWorker;
use Yiisoft\Yii\Queue\Workers\WorkerInterface;

return [
// 'queue' => [
// '__class' => Queue::class,
// ],
// SerializerInterface::class => Reference::to('queue.serializer'),
// 'queue.serializer' => [
// '__class' => PhpSerializer::class,
// ],
EventDispatcherInterface::class => Dispatcher::class,
WorkerInterface::class => QueueWorker::class,
ListenerProviderInterface::class => Provider::class,
];
26 changes: 2 additions & 24 deletions config/console.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
<?php

use Yiisoft\Factory\Definitions\Reference;
declare(strict_types=1);

return [
// 'app' => [
// 'bootstrap' => [
// 'queue' => 'queue',
// ],
// ],
// \PDO::class => Reference::to('pdo'),
// 'pdo' => [
// '__class' => \PDO::class,
// '__construct()' => [
// 'dsn' => 'pgsql:dbname='.$params['db.name']
// .(!empty($params['db.host']) ? (';host='.$params['db.host']) : '')
// .(!empty($params['db.port']) ? (';port='.$params['db.port']) : ''),
// 'username' => $params['db.user'],
// 'password' => $params['db.password'],
// 'options' => [],
// ],
// ],
// \yii\mutex\Mutex::class => Reference::to('mutex'),
// 'mutex' => [
// '__class' => \yii\mutex\MysqlMutex::class,
// ],
];
return [];
5 changes: 1 addition & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>./tests</directory>
<exclude>./tests/app</exclude>
<exclude>./tests/docker</exclude>
<exclude>./tests/runtime</exclude>
<directory>./tests/unit</directory>
</testsuite>
</testsuites>
</phpunit>
4 changes: 2 additions & 2 deletions src/Events/BeforeExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public function getQueue(): Queue
return $this->queue;
}

public function isPropagationStopped(): bool
public function isExecutionStopped(): bool
{
return $this->stop;
}

public function stopPropagation(): void
public function stopExecution(): void
{
$this->stop = true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Events/BeforePush.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public function getQueue(): Queue
return $this->queue;
}

public function isPropagationStopped(): bool
public function isExecutionStopped(): bool
{
return $this->stop;
}

public function stopPropagation(): void
public function stopExecution(): void
{
$this->stop = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Workers/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function process(MessageInterface $message, Queue $queue): void
try {
$this->dispatcher->dispatch($event);

if ($event->isPropagationStopped() === false) {
if ($event->isExecutionStopped() === false) {
$message->getJob()->execute();

$event = new AfterExecution($queue, $message);
Expand Down
16 changes: 16 additions & 0 deletions tests/App/ExceptionalSimpleJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Yiisoft\Yii\Queue\Tests\App;

use RuntimeException;

class ExceptionalSimpleJob extends SimpleJob
{
public function execute(): void
{
parent::execute();
throw new RuntimeException('Test exception');
}
}
22 changes: 5 additions & 17 deletions tests/App/SimpleJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,19 @@

namespace Yiisoft\Yii\Queue\Tests\App;

use yii\base\BaseObject;
use yii\helpers\Yii;
use Yiisoft\Yii\Queue\JobInterface;
use Yiisoft\Yii\Queue\Jobs\JobInterface;

/**
* Simple Job.
*
* @author Roman Zhuravlev <[email protected]>
*/
class SimpleJob extends BaseObject implements JobInterface
class SimpleJob implements JobInterface
{
public $uid;
public bool $executed = false;

public function __construct($uid = null)
public function execute(): void
{
$this->uid = $uid;
}

public function execute($queue)
{
file_put_contents($this->getFileName(), '');
}

public function getFileName()
{
return Yii::getAlias("@runtime/job-{$this->uid}.lock");
$this->executed = true;
}
}
28 changes: 0 additions & 28 deletions tests/App/config/main.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,4 @@
<?php

use Yiisoft\Factory\Definitions\Reference;
use Yiisoft\Mutex\File\FileMutex;
use Yiisoft\Mutex\Mutex as YiiMutex;
use Yiisoft\Yii\Queue\Drivers\Interop\Queue as InteropQueue;
use Yiisoft\Yii\Queue\Drivers\Sync\Queue as SyncQueue;

return [
'aliases' => [
'@runtime' => dirname(__DIR__, 2) . '/runtime',
],

'syncQueue' => [
'__class' => SyncQueue::class,
],
YiiMutex::class => Reference::to('mutex-file'),
'mutex-file' => [
'__class' => FileMutex::class,
'__construct()' => [
'mutexPath' => dirname(__DIR__, 2) . '/runtime/mutex',
],
],
'interopQueue' => [
'__class' => InteropQueue::class,
'host' => getenv('RABBITMQ_HOST') ?: 'localhost',
'user' => getenv('RABBITMQ_USER') ?: 'guest',
'password' => getenv('RABBITMQ_PASSWORD') ?: 'guest',
'queueName' => 'queue-interop',
'exchangeName' => 'exchange-interop',
],
];
69 changes: 0 additions & 69 deletions tests/Closure/ClosureTest.php

This file was deleted.

89 changes: 0 additions & 89 deletions tests/Drivers/CliTestCase.php

This file was deleted.

27 changes: 0 additions & 27 deletions tests/Drivers/Db/MysqlQueueTest.php

This file was deleted.

Loading

0 comments on commit af5f096

Please sign in to comment.