-
-
Notifications
You must be signed in to change notification settings - Fork 293
/
Copy pathStoppableTest.php
70 lines (63 loc) · 1.59 KB
/
StoppableTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace tests\stoppable;
use tests\app\SimpleJob;
use tests\TestCase;
use Yii;
use yii\caching\ArrayCache;
use yii\queue\stoppable\Behavior as Stoppable;
use yii\queue\sync\Queue as SyncQueue;
/**
* Stoppable Test
*
* @author Roman Zhuravlev <[email protected]>
*/
class StoppableTest extends TestCase
{
public function testStop()
{
$job = new SimpleJob(['uid' => uniqid()]);
$id = $this->getQueue()->push($job);
$this->getQueue()->stop($id);
$this->getQueue()->run();
$this->assertFileNotExists($job->getFileName());
}
public function testNotStop()
{
$job = new SimpleJob(['uid' => uniqid()]);
$this->getQueue()->push($job);
$this->getQueue()->run();
$this->assertFileExists($job->getFileName());
}
/**
* @return SyncQueue|Stoppable
*/
protected function getQueue()
{
if (!$this->_queue) {
$this->_queue = new SyncQueue([
'handle' => false,
'as stoppable' => [
'class' => Stoppable::class,
'cache' => ArrayCache::class,
],
]);
}
return $this->_queue;
}
private $_queue;
/**
* @inheritdoc
*/
protected function tearDown()
{
foreach (glob(Yii::getAlias("@runtime/job-*.lock")) as $fileName) {
unlink($fileName);
}
parent::tearDown();
}
}