Skip to content

Commit

Permalink
Raise the minimum version of PHP to 8.0 & version of psr/log to `…
Browse files Browse the repository at this point in the history
…^2.0|^3.0` (#122)
  • Loading branch information
rustamwin committed Jun 17, 2022
1 parent f10b2f3 commit d221841
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest', 'windows-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1']
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Expand Up @@ -28,4 +28,4 @@ jobs:
os: >-
['ubuntu-latest']
php: >-
['7.4', '8.0', '8.1']
['8.0', '8.1']
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -26,8 +26,8 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": "^7.4|^8.0",
"psr/log": "^1.1",
"php": "^8.0",
"psr/log": "^2.0|^3.0",
"yiisoft/yii-console": "^1.0",
"yiisoft/definitions": "^1.0|^2.0",
"yiisoft/factory": "^1.0",
Expand All @@ -39,7 +39,7 @@
"roave/infection-static-analysis-plugin": "^1.16",
"spatie/phpunit-watcher": "^1.23",
"vimeo/psalm": "^4.18",
"yiisoft/test-support": "^1.0"
"yiisoft/test-support": "^2.0"
},
"suggest": {
"ext-pcntl": "Need for process signals"
Expand Down
41 changes: 21 additions & 20 deletions tests/Unit/WorkerTest.php
Expand Up @@ -6,9 +6,9 @@

use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\Test\TestLogger;
use Yiisoft\Injector\Injector;
use Yiisoft\Test\Support\Container\SimpleContainer;
use Yiisoft\Test\Support\Log\SimpleLogger;
use Yiisoft\Yii\Queue\Exception\JobFailureException;
use Yiisoft\Yii\Queue\Message\Message;
use Yiisoft\Yii\Queue\Message\MessageInterface;
Expand All @@ -23,7 +23,7 @@ public function testJobExecutedWithCallableHandler(): void
{
$handleMessage = null;
$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$container = new SimpleContainer();
$handlers = [
'simple' => function (MessageInterface $message) use (&$handleMessage) {
Expand All @@ -37,15 +37,15 @@ public function testJobExecutedWithCallableHandler(): void
$worker->process($message, $queue);
$this->assertSame($message, $handleMessage);

$this->assertTrue(
$logger->hasInfoThatContains('Processing message #{message}.')
);
$messages = $logger->getMessages();
$this->assertNotEmpty($messages);
$this->assertStringContainsString('Processing message #{message}.', $messages[0]['message']);
}

public function testJobExecutedWithDefinitionHandler(): void
{
$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer([FakeHandler::class => $handler]);
$handlers = ['simple' => FakeHandler::class];
Expand All @@ -60,7 +60,7 @@ public function testJobExecutedWithDefinitionHandler(): void
public function testJobExecutedWithDefinitionClassHandler(): void
{
$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer([FakeHandler::class => $handler]);
$handlers = ['simple' => [FakeHandler::class, 'execute']];
Expand All @@ -75,7 +75,7 @@ public function testJobExecutedWithDefinitionClassHandler(): void
public function testJobFailWithDefinitionNotFoundClassButExistInContainerHandler(): void
{
$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer(['not-found-class-name' => $handler]);
$handlers = ['simple' => ['not-found-class-name', 'execute']];
Expand All @@ -90,7 +90,7 @@ public function testJobFailWithDefinitionNotFoundClassButExistInContainerHandler
public function testJobExecutedWithStaticDefinitionHandler(): void
{
$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer([FakeHandler::class => $handler]);
$handlers = ['simple' => [FakeHandler::class, 'staticExecute']];
Expand All @@ -107,7 +107,7 @@ public function testJobFailWithDefinitionUndefinedMethodHandler(): void
$this->expectExceptionMessage("Queue handler with name simple doesn't exist");

$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer([FakeHandler::class => $handler]);
$handlers = ['simple' => [FakeHandler::class, 'undefinedMethod']];
Expand All @@ -123,7 +123,7 @@ public function testJobFailWithDefinitionUndefinedClassHandler(): void
$this->expectExceptionMessage("Queue handler with name simple doesn't exist");

$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer([FakeHandler::class => $handler]);
$handlers = ['simple' => ['UndefinedClass', 'handle']];
Expand All @@ -134,17 +134,17 @@ public function testJobFailWithDefinitionUndefinedClassHandler(): void
try {
$worker->process($message, $queue);
} finally {
$this->assertTrue(
$logger->hasErrorThatContains("UndefinedClass doesn't exist.")
);
$messages = $logger->getMessages();
$this->assertNotEmpty($messages);
$this->assertStringContainsString('UndefinedClass doesn\'t exist.', $messages[1]['message']);
}
}

public function testJobFailWithDefinitionClassNotFoundInContainerHandler(): void
{
$this->expectExceptionMessage("Queue handler with name simple doesn't exist");
$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$container = new SimpleContainer();
$handlers = ['simple' => [FakeHandler::class, 'execute']];

Expand All @@ -162,7 +162,7 @@ public function testJobFailWithDefinitionHandlerException(): void
);

$message = new Message('simple', ['test-data']);
$logger = new TestLogger();
$logger = new SimpleLogger();
$handler = new FakeHandler();
$container = new SimpleContainer([FakeHandler::class => $handler]);
$handlers = ['simple' => [FakeHandler::class, 'executeWithException']];
Expand All @@ -173,10 +173,11 @@ public function testJobFailWithDefinitionHandlerException(): void
try {
$worker->process($message, $queue);
} finally {
$this->assertTrue(
$logger->hasErrorThatContains(
"Processing of message #null is stopped because of an exception:\nTest exception."
)
$messages = $logger->getMessages();
$this->assertNotEmpty($messages);
$this->assertStringContainsString(
"Processing of message #null is stopped because of an exception:\nTest exception.",
$messages[1]['message']
);
}
}
Expand Down

0 comments on commit d221841

Please sign in to comment.