This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
forked from samsonasik/expressive-composer-installer
/
ProcessAnswersTest.php
115 lines (91 loc) · 4.04 KB
/
ProcessAnswersTest.php
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository
* @copyright Copyright (c) 2015-2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-expressive-skeleton/blob/master/LICENSE.md New BSD License
*/
declare(strict_types=1);
namespace ExpressiveInstallerTest;
use ExpressiveInstaller\OptionalPackages;
use Prophecy\Argument;
class ProcessAnswersTest extends OptionalPackagesTestCase
{
use ProjectSandboxTrait;
/**
* @var OptionalPackages
*/
private $installer;
protected function setUp()
{
parent::setUp();
$this->projectRoot = $this->copyProjectFilesToTempFilesystem();
$this->installer = $this->createOptionalPackages($this->projectRoot);
$this->prepareSandboxForInstallType(OptionalPackages::INSTALL_MINIMAL, $this->installer);
}
protected function tearDown()
{
parent::tearDown();
chdir($this->packageRoot);
$this->recursiveDelete($this->projectRoot);
}
public function testInvalidAnswer()
{
$this->io->write()->shouldNotBeCalled();
$config = $this->getInstallerConfig($this->installer);
$question = $config['questions']['container'];
$answer = 'foobar';
$result = $this->installer->processAnswer($question, $answer);
$this->assertFalse($result);
$this->assertFileNotExists($this->projectRoot . '/config/container.php');
}
public function testAnsweredWithN()
{
$this->io->write()->shouldNotBeCalled();
$config = $this->getInstallerConfig($this->installer);
$question = $config['questions']['container'];
$answer = 'n';
$result = $this->installer->processAnswer($question, $answer);
$this->assertFalse($result);
$this->assertFileNotExists($this->projectRoot . '/config/container.php');
}
public function testAnsweredWithInvalidOption()
{
$this->io->write()->shouldNotBeCalled();
$config = $this->getInstallerConfig($this->installer);
$question = $config['questions']['container'];
$answer = 10;
$result = $this->installer->processAnswer($question, $answer);
$this->assertFalse($result);
$this->assertFileNotExists($this->projectRoot . '/config/container.php');
}
public function testAnsweredWithValidOption()
{
// Prepare the installer
$this->installer->removeDevDependencies();
// @codingStandardsIgnoreStart
$this->io->write(Argument::containingString('Adding package <info>zendframework/zend-auradi-config</info>'))->shouldBeCalled();
$this->io->write(Argument::containingString('Copying <info>config/container.php</info>'))->shouldBeCalled();
// @codingStandardsIgnoreEnd
$config = $this->getInstallerConfig($this->installer);
$question = $config['questions']['container'];
$answer = 1;
$result = $this->installer->processAnswer($question, $answer);
$this->assertTrue($result);
$this->assertFileExists($this->projectRoot . '/config/container.php');
$this->assertPackage('zendframework/zend-auradi-config', $this->installer);
}
public function testAnsweredWithPackage()
{
// Prepare the installer
$this->installer->removeDevDependencies();
$this->io->write(Argument::containingString('Adding package <info>league/container</info>'))->shouldBeCalled();
$this->io->write(Argument::containingString('<warning>You need to edit public/index.php'))->shouldBeCalled();
$config = $this->getInstallerConfig($this->installer);
$question = $config['questions']['container'];
$answer = 'league/container:2.2.0';
$result = $this->installer->processAnswer($question, $answer);
$this->assertTrue($result);
$this->assertFileNotExists($this->projectRoot . '/config/container.php');
$this->assertPackage('league/container', $this->installer);
}
}