Skip to content

Commit 6ad008b

Browse files
author
Joe Green
committed
added command tests
1 parent 95b03e3 commit 6ad008b

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

src/Command/SyncCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DbSync\Hash\Md5Hash;
77
use DbSync\Table;
88
use DbSync\Transfer\Transfer;
9+
use DbSync\WhereClause;
910
use Symfony\Component\Console\Command\Command;
1011
use Symfony\Component\Console\Helper\QuestionHelper;
1112
use Symfony\Component\Console\Input\InputArgument;
@@ -60,7 +61,7 @@ protected function configure()
6061
->addOption('target.user',null , InputOption::VALUE_REQUIRED, 'The name of the user to connect to the target host with if different to the source.')
6162
->addOption('target.table',null , InputOption::VALUE_REQUIRED, 'The name of the table on the target host if different to the source.')
6263
->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.')
63-
//->addOption('where', null , InputOption::VALUE_REQUIRED, 'A where clause to apply to the source table')
64+
->addOption('where', null , InputOption::VALUE_REQUIRED, 'A where clause to apply to the tables')
6465
;
6566
}
6667

@@ -153,9 +154,18 @@ private function fire()
153154

154155
$sync->setLogger($logger);
155156

157+
$sourceTableObj = new Table($source, $sourceDatabase, $sourceTable);
158+
$destTableObj = new Table($target, $targetDatabase, $targetTable);
159+
160+
if($where = $this->input->getOption('where'))
161+
{
162+
$sourceTableObj->setWhereClause(new WhereClause($where));
163+
$destTableObj->setWhereClause(new WhereClause($where));
164+
}
165+
156166
$result = $sync->sync(
157-
new Table($source, $sourceDatabase, $sourceTable),
158-
new Table($target, $targetDatabase, $targetTable),
167+
$sourceTableObj,
168+
$destTableObj,
159169
new ColumnConfiguration($this->input->getOption('columns'), $this->input->getOption('ignore-columns'))
160170
);
161171

tests/integration/FullSyncTest.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ class FullSyncTest extends PHPUnit_Framework_TestCase
55

66
protected $connection;
77

8+
protected $config;
9+
810
public function setUp()
911
{
10-
$this->connection = (new \Database\Connectors\ConnectionFactory())->make(include __DIR__ . '/config.php');
12+
$this->config = include __DIR__ . '/config.php';
13+
14+
$this->connection = (new \Database\Connectors\ConnectionFactory())->make($this->config);
1115
}
1216

1317
public function providerHashStrategy()
@@ -19,6 +23,23 @@ public function providerHashStrategy()
1923
);
2024
}
2125

26+
public function testItRunsCommand()
27+
{
28+
$this->createTestDatabases();
29+
30+
$db = self::DATABASE;
31+
32+
$host = $this->config['host'];
33+
$user = $this->config['username'];
34+
$password = $this->config['password'];
35+
36+
$command = __DIR__ . "/../../bin/sync $host $host $db.customers1 --target.table=$db.customers2 -u $user -p $password -e";
37+
38+
exec($command, $output, $code);
39+
40+
$this->assertEquals(0, $code);
41+
}
42+
2243
/**
2344
* @dataProvider providerHashStrategy
2445
*/

0 commit comments

Comments
 (0)