first commit
This commit is contained in:
commit
d0e185820a
2710 files changed
+465112
No files matched your search
+99
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use App\Mailer\TestEmail;
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\Core\Configure;
|
||||
use Cake\Mailer\Email;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Queue\Shell\Task\QueueEmailTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueEmailTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'plugin.Queue.QueuedJobs',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueEmailTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueEmailTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRunArray() {
|
||||
$settings = [
|
||||
'from' => '[email protected]',
|
||||
'to' => '[email protected]',
|
||||
];
|
||||
|
||||
$this->Task->run(['settings' => $settings, 'content' => 'Foo Bar'], null);
|
||||
|
||||
$this->assertInstanceOf(Email::class, $this->Task->Email);
|
||||
|
||||
$debugEmail = $this->Task->Email;
|
||||
|
||||
$transportConfig = $debugEmail->getTransport()->getConfig();
|
||||
$this->assertSame('Debug', $transportConfig['className']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRunToolsEmailObject() {
|
||||
$email = new TestEmail();
|
||||
$email->setFrom('[email protected]');
|
||||
$email->setTo('[email protected]');
|
||||
|
||||
Configure::write('Config.live', true);
|
||||
|
||||
$this->Task->run(['settings' => $email, 'content' => 'Foo Bar'], null);
|
||||
|
||||
$this->assertInstanceOf(TestEmail::class, $this->Task->Email);
|
||||
|
||||
/** @var \App\Mailer\TestEmail $debugEmail */
|
||||
$debugEmail = $this->Task->Email;
|
||||
$this->assertNull($debugEmail->getError());
|
||||
|
||||
$transportConfig = $debugEmail->getTransport()->getConfig();
|
||||
$this->assertSame('Debug', $transportConfig['className']);
|
||||
|
||||
$result = $debugEmail->debug();
|
||||
$this->assertTextContains('Foo Bar', $result['message']);
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+60
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Queue\Shell\Task\QueueExceptionExampleTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueExceptionExampleTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'plugin.Queue.QueuedJobs',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueExceptionExampleTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueExceptionExampleTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testRun() {
|
||||
$this->Task->run([], null);
|
||||
}
|
||||
|
||||
}
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Exception;
|
||||
use Queue\Shell\Task\QueueExecuteTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueExecuteTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'plugin.Queue.QueuedJobs',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueExecuteTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueExecuteTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRun() {
|
||||
$this->Task->run(['command' => 'php -v'], null);
|
||||
|
||||
$this->assertTextContains('PHP ', $this->out->output());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRunFailureWithRedirect() {
|
||||
$exception = null;
|
||||
try {
|
||||
$this->Task->run(['command' => 'fooooobbbaraar -eeee'], null);
|
||||
} catch (\Exception $e) {
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(Exception::class, $e);
|
||||
$this->assertSame('Failed with error code 127: `fooooobbbaraar -eeee`', $e->getMessage());
|
||||
|
||||
$this->assertTextContains('Error (code 127)', $this->err->output());
|
||||
$this->assertTextContains('fooooobbbaraar: not found', $this->out->output());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRunFailureWithRedirectAndIgnoreCode() {
|
||||
$this->Task->run(['command' => 'fooooobbbaraar -eeee', 'accepted' => []], null);
|
||||
|
||||
$this->assertTextContains('Success (code 127)', $this->out->output());
|
||||
$this->assertTextContains('fooooobbbaraar: not found', $this->out->output());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Failed with error code 127: `fooooobbbaraar -eeee`
|
||||
*/
|
||||
public function testRunFailureWithoutRedirect() {
|
||||
$this->skipIf((bool)getenv('TRAVIS'), 'Not redirecting stderr to stdout prints noise to the CLI output in between test runs.');
|
||||
|
||||
$this->Task->run(['command' => 'fooooobbbaraar -eeee', 'redirect' => false], null);
|
||||
}
|
||||
|
||||
}
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Queue\Shell\Task\QueueMonitorExampleTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueMonitorExampleTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueMonitorExampleTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueMonitorExampleTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRun() {
|
||||
$this->Task->run([], null);
|
||||
|
||||
$this->assertTextContains('Success, the MonitorExample Job was run', $this->out->output());
|
||||
}
|
||||
|
||||
}
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Queue\Shell\Task\QueueProgressExampleTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueProgressExampleTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueProgressExampleTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueProgressExampleTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRun() {
|
||||
$this->Task->run(['duration' => 1], null);
|
||||
|
||||
$this->assertTextContains('Success, the ProgressExample Job was run', $this->out->output());
|
||||
}
|
||||
|
||||
}
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\Console\Exception\StopException;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Queue\Shell\Task\QueueRetryExampleTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueRetryExampleTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueRetryExampleTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueRetryExampleTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRun() {
|
||||
$file = TMP . 'task_retry.txt';
|
||||
file_put_contents($file, '0');
|
||||
|
||||
$exception = null;
|
||||
try {
|
||||
$this->Task->run([], null);
|
||||
} catch (\Exception $e) {
|
||||
$exception = $e;
|
||||
}
|
||||
|
||||
$this->assertInstanceOf(StopException::class, $exception);
|
||||
$this->assertTextContains('Sry, the RetryExample Job failed. Try again.', $this->err->output());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRunSuccess() {
|
||||
$file = TMP . 'task_retry.txt';
|
||||
file_put_contents($file, '3');
|
||||
|
||||
$this->Task->run([], null);
|
||||
|
||||
$this->assertTextContains('Success, the RetryExample Job was run', $this->out->output());
|
||||
}
|
||||
|
||||
}
|
||||
+61
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace Queue\Test\TestCase\Shell;
|
||||
|
||||
use Cake\Console\ConsoleIo;
|
||||
use Cake\TestSuite\TestCase;
|
||||
use Queue\Shell\Task\QueueSuperExampleTask;
|
||||
use Tools\TestSuite\ConsoleOutput;
|
||||
use Tools\TestSuite\ToolsTestTrait;
|
||||
|
||||
class QueueSuperExampleTaskTest extends TestCase {
|
||||
|
||||
use ToolsTestTrait;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $fixtures = [
|
||||
'plugin.Queue.QueuedJobs',
|
||||
];
|
||||
|
||||
/**
|
||||
* @var \Queue\Shell\Task\QueueSuperExampleTask|\PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $Task;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $out;
|
||||
|
||||
/**
|
||||
* @var \Tools\TestSuite\ConsoleOutput
|
||||
*/
|
||||
protected $err;
|
||||
|
||||
/**
|
||||
* Setup Defaults
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->out = new ConsoleOutput();
|
||||
$this->err = new ConsoleOutput();
|
||||
$io = new ConsoleIo($this->out, $this->err);
|
||||
|
||||
$this->Task = new QueueSuperExampleTask($io);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testRun() {
|
||||
$this->Task->run([], null);
|
||||
|
||||
$this->assertTextContains('Success, the SuperExample Job was run', $this->out->output());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user