Skip to content
This repository has been archived by the owner on Dec 9, 2022. It is now read-only.

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bupy7 committed Aug 18, 2017
1 parent a24e27d commit 2bceb0d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Options/ModuleOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function getOneTimeLimit(): int

public function setErrorLimit(int $errorLimit): ModuleOptions
{
$this->errorLimit = $errorLimit;
$this->errorLimit = $errorLimit >= 0 ? $errorLimit : 0;
return $this;
}

Expand Down
5 changes: 4 additions & 1 deletion src/Service/QueueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ protected function executeTask(TaskEntity $entity): void
$entity->setStatusId(TaskEntity::STATUS_OK);
} else {
$entity->incNumberErrors();
if ($entity->getNumberErrors() >= $this->config->getErrorLimit()) {
if (
$this->config->getErrorLimit() !== 0
&& $entity->getNumberErrors() >= $this->config->getErrorLimit()
) {
$entity->setStatusId(TaskEntity::STATUS_IMPOSSIBLE);
} else {
$entity->setStatusId(TaskEntity::STATUS_ERROR);
Expand Down
3 changes: 2 additions & 1 deletion test/AppTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
trait AppTrait
{
protected function getSm(): ServiceManager
protected function getSm(array $config = []): ServiceManager
{
$moduleLoader = new ModuleLoader([
'modules' => [
Expand All @@ -22,6 +22,7 @@ protected function getSm(): ServiceManager
__DIR__ . '/../config/module.config.php',
__DIR__ . '/config/module.config.php',
],
'extra_config' => $config,
'module_paths' => [],
'config_cache_enabled' => false,
'module_map_cache_enabled' => false,
Expand Down
49 changes: 49 additions & 0 deletions test/Options/ModuleOptionsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Bupy7\Queue\Test\Options;

use PHPUnit\Framework\TestCase;
use Bupy7\Queue\Options\ModuleOptions;
use Bupy7\Queue\Test\AppTrait;
use Queue\Hydrator\ArrayHydrator;

/**
* @author Vasily Belosludcev <https://github.com/bupy7>
*/
class ModuleOptionsTest extends TestCase
{
use AppTrait;

public function testInstance()
{
$options = $this->getSm()->get('Bupy7\Queue\Options\ModuleOptions');
$this->assertInstanceOf(ModuleOptions::class, $options);
}

public function testGet()
{
$options = $this->getSm()->get('Bupy7\Queue\Options\ModuleOptions');
$this->assertEquals(100, $options->getOneTimeLimit());
$this->assertEquals(5, $options->getErrorLimit());
}

public function testSet()
{
$options = $this->getSm()->get('Bupy7\Queue\Options\ModuleOptions');
$options->setOneTimeLimit(-50);
$this->assertEquals(0, $options->getOneTimeLimit());
$options->setErrorLimit(-10);
$this->assertEquals(0, $options->getErrorLimit());
}

public function testConfiguration()
{
$config = [
'one_time_limit' => 32,
'error_limit' => 10,
];
$options = $this->getSm(['queue' => $config])->get('Bupy7\Queue\Options\ModuleOptions');
$this->assertEquals(32, $options->getOneTimeLimit());
$this->assertEquals(10, $options->getErrorLimit());
}
}

0 comments on commit 2bceb0d

Please sign in to comment.