-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathAddenvCommandTest.php
More file actions
77 lines (61 loc) · 1.97 KB
/
AddenvCommandTest.php
File metadata and controls
77 lines (61 loc) · 1.97 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
<?php
/**
* User: aguidet
* Date: 27/02/15
* Time: 17:21
*/
namespace Migrate\Command;
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;
use Migrate\Test\Command\AbstractCommandTester;
class AddenvCommandTest extends AbstractCommandTester
{
public function setUp()
{
$this->cleanEnv();
}
public function tearDown()
{
$this->cleanEnv();
}
public function testExecute()
{
$application = new Application();
$application->add(new AddEnvCommand());
$command = $application->find('migrate:addenv');
$commandTester = new CommandTester($command);
$pdoDrivers = pdo_drivers();
$driverKey = array_search('sqlite', $pdoDrivers);
if (empty($driverKey)) {
echo "install sqlite php driver (php-sqlite3)\n";
exit(-1);
}
$driverSelect = '';
foreach ($pdoDrivers as $key => $driver) {
$driverSelect .= " [$key] $driver\n";
}
/* @var $question QuestionHelper */
$question = $command->getHelper('question');
$question->setInputStream(InputStreamUtil::type("testing\n$driverKey\nmigrate_test\nlocalhost\n5432\naguidet\naguidet\nutf8\nchangelog\nvim\n"));
$commandTester->execute(array('command' => $command->getName()));
$this->assertRegExp('/Please enter the name of the new environment/', $commandTester->getDisplay());
$envDir = Directory::getEnvPath();
$expected = <<<EXPECTED
connection:
host: localhost
driver: sqlite
port: 5432
username: aguidet
password: aguidet
database: migrate_test
charset: utf8
changelog: changelog
default_editor: vim
EXPECTED;
$fileContent = file_get_contents($envDir . '/testing.yml');
$this->assertEquals($expected, $fileContent);
}
}