2014-07-04 18:31:45 +04:00
|
|
|
<?php
|
|
|
|
/* (c) Anton Medvedev <anton@elfet.ru>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Deployer;
|
|
|
|
|
2014-07-05 12:59:06 +04:00
|
|
|
use Deployer\Task\TaskFactory;
|
|
|
|
|
2014-07-05 13:31:04 +04:00
|
|
|
class TaskTest extends DeployerTester
|
2014-07-04 18:31:45 +04:00
|
|
|
{
|
|
|
|
public function testRun()
|
|
|
|
{
|
2014-07-05 13:31:04 +04:00
|
|
|
$mock = $this->getMock('stdClass', ['callback']);
|
|
|
|
$mock->expects($this->exactly(1))
|
|
|
|
->method('callback')
|
|
|
|
->will($this->returnValue(true));
|
2014-07-04 18:31:45 +04:00
|
|
|
|
2014-07-05 13:31:04 +04:00
|
|
|
$task = new Task(function () use ($mock) {
|
|
|
|
$mock->callback();
|
2014-07-04 18:31:45 +04:00
|
|
|
});
|
2014-07-05 13:31:04 +04:00
|
|
|
|
2014-07-04 18:31:45 +04:00
|
|
|
$task->run();
|
|
|
|
}
|
2014-07-05 12:59:06 +04:00
|
|
|
|
|
|
|
public function testDescription()
|
|
|
|
{
|
|
|
|
$task = new Task(function () {
|
|
|
|
});
|
|
|
|
$task->description('desc');
|
|
|
|
|
|
|
|
$this->assertEquals('desc', $task->getDescription());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \InvalidArgumentException
|
|
|
|
*/
|
|
|
|
public function testFactoryInvalidArgumentException()
|
|
|
|
{
|
|
|
|
TaskFactory::create(null);
|
|
|
|
}
|
2014-07-05 13:31:04 +04:00
|
|
|
|
|
|
|
public function testAfter()
|
|
|
|
{
|
|
|
|
$mock = $this->getMock('stdClass', ['callback']);
|
|
|
|
$mock->expects($this->exactly(2))
|
|
|
|
->method('callback')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
task('task', function () {
|
|
|
|
});
|
|
|
|
|
|
|
|
after('task', function () use ($mock) {
|
|
|
|
$mock->callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
task('after', function () use ($mock) {
|
|
|
|
$mock->callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
after('task', 'after');
|
|
|
|
|
|
|
|
$this->runCommand('task');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBefore()
|
|
|
|
{
|
|
|
|
$mock = $this->getMock('stdClass', ['callback']);
|
|
|
|
$mock->expects($this->exactly(2))
|
|
|
|
->method('callback')
|
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
|
|
task('task', function () {
|
|
|
|
});
|
|
|
|
|
|
|
|
before('task', function () use ($mock) {
|
|
|
|
$mock->callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
task('before', function () use ($mock) {
|
|
|
|
$mock->callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
after('task', 'before');
|
|
|
|
|
|
|
|
$this->runCommand('task');
|
|
|
|
}
|
2014-07-04 18:31:45 +04:00
|
|
|
}
|
|
|
|
|