-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathAbstractCommandTester.php
More file actions
94 lines (77 loc) · 2.73 KB
/
AbstractCommandTester.php
File metadata and controls
94 lines (77 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* User: aguidet
* Date: 02/03/15
* Time: 15:19
*/
namespace Migrate\Test\Command;
use Migrate\Command\AddEnvCommand;
use Migrate\Command\InitCommand;
use Migrate\Enum\Directory;
use Migrate\Utils\InputStreamUtil;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Tester\CommandTester;
class AbstractCommandTester extends \PHPUnit_Framework_TestCase
{
public static $env = 'testing';
public static $driver = 'sqlite';
public static $bddName = 'migrate_test';
public static $username = 'aguidet';
public static $password = 'aguidet';
public static $host = 'localhost';
public static $port = '5432';
public function cleanEnv()
{
exec("rm -rf .php-database-migration");
if (file_exists('test.sqlite')) {
exec("rm test.sqlite");
}
}
public function createEnv($format = 'yml')
{
$application = new Application();
$application->add(new AddEnvCommand());
$command = $application->find('migrate:addenv');
$commandTester = new CommandTester($command);
$pdoDrivers = pdo_drivers();
$driverKey = array_search('sqlite', $pdoDrivers);
/* @var $question QuestionHelper */
$question = $command->getHelper('question');
$question->setInputStream(InputStreamUtil::type("testing\n$driverKey\ntest.sqlite\n\n\n\n\n\nchangelog\nvim\n"));
$commandTester->execute(array('command' => $command->getName(), 'format' => $format));
$question = $command->getHelper('question');
$question->setInputStream(InputStreamUtil::type("minimal\nsqlite\n\n\n\n\n\n\nchangelog\n\n"));
$commandTester->execute(array('command' => $command->getName(), 'format' => $format));
}
public function initEnv()
{
$application = new Application();
$application->add(new InitCommand());
$command = $application->find('migrate:init');
$commandTester = new CommandTester($command);
$commandTester->execute(array(
'command' => $command->getName(),
'env' => 'testing'
));
$commandTester->execute(array(
'command' => $command->getName(),
'env' => 'minimal',
'--database' => 'migrate_test',
'--driver' => 'sqlite'
));
}
public function createMigration($timestamp, $sqlUp, $sqlDown)
{
$filename = Directory::getMigrationsPath() . '/' . $timestamp . '_migration.sql';
$content =<<<SQL
--// unit testing migration
-- Migration SQL that makes the change goes here.
$sqlUp
-- @UNDO
-- SQL to undo the change goes here.
$sqlDown
SQL;
file_put_contents($filename, $content);
}
}