-
Notifications
You must be signed in to change notification settings - Fork 139
Expand file tree
/
Copy pathRunCommandTest.php
More file actions
85 lines (69 loc) · 1.98 KB
/
Copy pathRunCommandTest.php
File metadata and controls
85 lines (69 loc) · 1.98 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace Queue\Test\TestCase\Command;
use Cake\Console\TestSuite\ConsoleIntegrationTestTrait;
use Cake\Core\Configure;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
* @uses \Queue\Command\RunCommand
*/
class RunCommandTest extends TestCase {
use ConsoleIntegrationTestTrait;
/**
* @var array<string>
*/
protected array $fixtures = [
'plugin.Queue.QueueProcesses',
'plugin.Queue.QueuedJobs',
];
/**
* @return void
*/
public function setUp(): void {
parent::setUp();
$this->loadPlugins(['Queue']);
Configure::write('Queue', [
'sleeptime' => 1,
'defaultRequeueTimeout' => 180, // 3 minutes - higher than any task timeout
'workerLifetime' => 3,
'cleanuptimeout' => 10,
'exitwhennothingtodo' => false,
]);
}
/**
* @return void
*/
public function testExecute(): void {
$this->_needsConnection();
$this->exec('queue run');
$output = $this->_out->output();
// Worker loop ran to completion. The per-iteration heartbeat is
// verbose-only now, so assert on the always-on termination event.
$this->assertStringContainsString('terminating.', $output);
$this->assertExitCode(0);
}
/**
* @return void
*/
public function testServiceInjection(): void {
$this->_needsConnection();
$this->exec('queue add Foo');
$this->exec('queue run');
$output = $this->_out->output();
$this->assertStringContainsString('Running Job of type "Foo"', $output);
$this->assertStringContainsString('CakePHP Foo Example.', $output);
$this->assertStringContainsString('My TestService', $output);
$this->assertExitCode(0);
}
/**
* Helper method for skipping tests that need a real connection.
*
* @return void
*/
protected function _needsConnection() {
$config = ConnectionManager::getConfig('test');
$skip = !str_contains((string)$config['driver'], 'Mysql') && !str_contains((string)$config['driver'], 'Postgres');
$this->skipIf($skip, 'Only Mysql/Postgres is working yet for this.');
}
}