1
0
mirror of https://github.com/deployphp/deployer.git synced 2025-02-22 16:27:39 +01:00

Update readme file example. 🐠

This commit is contained in:
Elfet 2013-11-16 17:35:07 +04:00
parent b425e8bbf1
commit da58a865cd
7 changed files with 247 additions and 30 deletions

@ -22,8 +22,8 @@ task('clear', function () {
run('php bin/clear');
});
task('prod', ['prod_server', 'upload', 'clear']);
task('test', ['test_server', 'upload', 'clear']);
task('prod', 'Deploy on production.', ['prod_server', 'upload', 'clear']);
task('test', 'Deploy on test server.', ['test_server', 'upload', 'clear']);
start();
```

@ -11,31 +11,6 @@ use Symfony\Component\Console\Tester\ApplicationTester;
class TaskTest extends \PHPUnit_Framework_TestCase
{
public function testTask()
{
$tool = deployer();
$str = '';
task('first', function () use (&$str) {
$str .= 'first';
});
task('second', function () use (&$str) {
$str .= 'second';
});
task('all', 'Run all', ['second', 'first']);
$tool->getApp()->addCommands($tool->getCommands());
$tool->getApp()->setAutoExit(false);
$tool->getApp()->setCatchExceptions(false);
$app = new ApplicationTester($tool->getApp());
$app->run(array('command' => 'all'));
$this->assertEquals('secondfirst', $str);
}
public function testRun()
{
$called = false;

@ -8,7 +8,6 @@
namespace Deployer\Tool;
use Deployer\Tool\Context;
use Deployer\Tool;
class ContextTest extends \PHPUnit_Framework_TestCase
{
@ -16,11 +15,11 @@ class ContextTest extends \PHPUnit_Framework_TestCase
{
Context::clear();
$t1 = new Tool();
$t1 = $this->getMockBuilder('Deployer\Tool')->disableOriginalConstructor()->getMock();
Context::push($t1);
$this->assertInstanceOf('Deployer\Tool', Context::get());
$t2 = new Tool();
$t2 = $this->getMockBuilder('Deployer\Tool')->disableOriginalConstructor()->getMock();
Context::push($t2);
$this->assertInstanceOf('Deployer\Tool', Context::get());

243
test/Deployer/ToolTest.php Normal file

@ -0,0 +1,243 @@
<?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;
use Deployer\Tool\Context;
use Deployer\Utils\Local;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Tester\ApplicationTester;
class ToolTest extends \PHPUnit_Framework_TestCase
{
/**
* @var Application
*/
private $app;
/**
* @var Tool
*/
private $tool;
public function testCreate()
{
$tool = deployer(false);
$this->assertInstanceOf('Deployer\Tool', $tool);
}
public function testIncludeFunctions()
{
deployer();
$this->assertTrue(function_exists('start'), 'Functions does not included.');
}
public function testTask()
{
$this->deployer();
$called = false;
task('one', 'One task', function () use (&$called) {
$called = true;
});
$this->start('one');
$this->assertTrue($called, 'Task was not called.');
}
public function testTaskCreateWithAndWithoutDesc()
{
$this->deployer();
task('one', function () {
});
task('two', 'Task two', function () {
});
$this->assertArrayHasKey('one', $this->tool->getTasks());
$this->assertArrayHasKey('two', $this->tool->getTasks());
}
public function testTaskArrayDefinition()
{
$this->deployer();
$calls = [];
task('one', function () use (&$calls) {
$calls[] = 'one';
});
task('two', function () use (&$calls) {
$calls[] = 'two';
});
task('comp', 'Call one and two', ['one', 'two']);
$this->start('comp');
$this->assertContains('one', $calls);
$this->assertContains('two', $calls);
}
public function testConnectCdRunAndUploadFile()
{
$localFile = realpath(__DIR__ . '/../fixture/file');
$remote = $this->getMock('Deployer\Remote\RemoteInterface');
$remote
->expects($this->once())
->method('cd')
->with('/home');
$remote
->expects($this->once())
->method('execute')
->with('command');
$remote
->expects($this->once())
->method('uploadFile')
->with($localFile, '/remote');
$remoteFactory = $this->getMock('Deployer\Remote\RemoteFactory');
$remoteFactory
->expects($this->once())
->method('create')
->will($this->returnValue($remote));
$this->deployer($remoteFactory);
connect('localhost', 'user', 'password');
cd('/home');
run('command');
upload($localFile, '/remote');
}
public function testUploadOfDirectory()
{
$local = realpath(__DIR__ . '/../fixture/');
$remote = $this->getMock('Deployer\Remote\RemoteInterface');
$remote
->expects($this->at(0))
->method('uploadFile')
->with($local . '/file', '/remote/file');
$remote
->expects($this->at(1))
->method('uploadFile')
->with($local . '/src/some.php', '/remote/src/some.php');
$remoteFactory = $this->getMock('Deployer\Remote\RemoteFactory');
$remoteFactory
->expects($this->once())
->method('create')
->will($this->returnValue($remote));
$this->deployer($remoteFactory);
connect('localhost', 'user', 'password');
ignore(['ignor*']);
upload($local, '/remote');
}
public function testLocal()
{
$local = $this->getMock('\Deployer\Utils\Local');
$local
->expects($this->once())
->method('execute')
->with('command');
$this->deployer(null, $local);
runLocally('command');
}
public function testGroup()
{
$remote1 = $this->getMock('Deployer\Remote\RemoteInterface');
$remote1
->expects($this->exactly(1))
->method('execute')
->with('command1');
$remote2 = $this->getMock('Deployer\Remote\RemoteInterface');
$remote2
->expects($this->exactly(2))
->method('execute')
->with('command2');
$remoteFactory = $this->getMock('Deployer\Remote\RemoteFactory');
$remoteFactory
->expects($this->any())
->method('create')
->will($this->returnCallback(function ($host) use ($remote1, $remote2) {
return $host === 'host1' ? $remote1 : $remote2;
}));
$this->deployer($remoteFactory);
connect('host1', 'user', 'password', 'one');
connect('host2', 'user', 'password', 'two');
connect('host3', 'user', 'password', 'two');
group('one', function () {
run('command1');
});
group('two', function () {
run('command2');
});
}
public static function setUpBeforeClass()
{
include_once __DIR__ . '/../../src/Deployer/functions.php';
}
private function deployer($remoteFactory = null, $local = null)
{
$this->app = new Application();
$this->app->setAutoExit(false);
$this->app->setCatchExceptions(false);
$this->tool = new Tool(
$this->app,
$this->getMock('\Symfony\Component\Console\Input\InputInterface'),
$this->getMock('\Symfony\Component\Console\Output\OutputInterface'),
null === $local ? $this->getMock('\Deployer\Utils\Local') : $local,
null === $remoteFactory ? $this->getMock('Deployer\Remote\RemoteFactory') : $remoteFactory
);
Context::push($this->tool);
}
protected function tearDown()
{
Context::clear();
}
private function start($command = null)
{
$this->app->addCommands($this->tool->getCommands());
$app = new ApplicationTester($this->app);
if (null !== $command) {
$app->run(array('command' => $command));
}
return $app;
}
}

0
test/fixture/file Normal file

0
test/fixture/ignore/file Normal file