Skip to content

Commit

Permalink
added command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe Green committed Sep 4, 2015
1 parent 95b03e3 commit 6ad008b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Command/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DbSync\Hash\Md5Hash;
use DbSync\Table;
use DbSync\Transfer\Transfer;
use DbSync\WhereClause;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -60,7 +61,7 @@ protected function configure()
->addOption('target.user',null , InputOption::VALUE_REQUIRED, 'The name of the user to connect to the target host with if different to the source.')
->addOption('target.table',null , InputOption::VALUE_REQUIRED, 'The name of the table on the target host if different to the source.')
->addOption('target.password',null , InputOption::VALUE_REQUIRED, 'The password for the target host if the target user is specified. Will be solicited on the tty if not given.')
//->addOption('where', null , InputOption::VALUE_REQUIRED, 'A where clause to apply to the source table')
->addOption('where', null , InputOption::VALUE_REQUIRED, 'A where clause to apply to the tables')
;
}

Expand Down Expand Up @@ -153,9 +154,18 @@ private function fire()

$sync->setLogger($logger);

$sourceTableObj = new Table($source, $sourceDatabase, $sourceTable);
$destTableObj = new Table($target, $targetDatabase, $targetTable);

if($where = $this->input->getOption('where'))
{
$sourceTableObj->setWhereClause(new WhereClause($where));
$destTableObj->setWhereClause(new WhereClause($where));
}

$result = $sync->sync(
new Table($source, $sourceDatabase, $sourceTable),
new Table($target, $targetDatabase, $targetTable),
$sourceTableObj,
$destTableObj,
new ColumnConfiguration($this->input->getOption('columns'), $this->input->getOption('ignore-columns'))
);

Expand Down
23 changes: 22 additions & 1 deletion tests/integration/FullSyncTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ class FullSyncTest extends PHPUnit_Framework_TestCase

protected $connection;

protected $config;

public function setUp()
{
$this->connection = (new \Database\Connectors\ConnectionFactory())->make(include __DIR__ . '/config.php');
$this->config = include __DIR__ . '/config.php';

$this->connection = (new \Database\Connectors\ConnectionFactory())->make($this->config);
}

public function providerHashStrategy()
Expand All @@ -19,6 +23,23 @@ public function providerHashStrategy()
);
}

public function testItRunsCommand()
{
$this->createTestDatabases();

$db = self::DATABASE;

$host = $this->config['host'];
$user = $this->config['username'];
$password = $this->config['password'];

$command = __DIR__ . "/../../bin/sync $host $host $db.customers1 --target.table=$db.customers2 -u $user -p $password -e";

exec($command, $output, $code);

$this->assertEquals(0, $code);
}

/**
* @dataProvider providerHashStrategy
*/
Expand Down

0 comments on commit 6ad008b

Please sign in to comment.