This repository has been archived by the owner on Jan 21, 2020. It is now read-only.
forked from samsonasik/expressive-composer-installer
/
RequestInstallTypeTest.php
94 lines (77 loc) · 2.75 KB
/
RequestInstallTypeTest.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
<?php
/**
* @see https://github.com/zendframework/zend-expressive-skeleton for the canonical source repository
* @copyright Copyright (c) 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 RequestInstallTypeTest extends OptionalPackagesTestCase
{
/**
* @var OptionalPackages
*/
private $installer;
protected function setUp()
{
parent::setUp();
$this->installer = $this->createOptionalPackages();
}
public function installSelections()
{
return [
OptionalPackages::INSTALL_MINIMAL => ['1', OptionalPackages::INSTALL_MINIMAL],
OptionalPackages::INSTALL_FLAT => ['2', OptionalPackages::INSTALL_FLAT],
OptionalPackages::INSTALL_MODULAR => ['3', OptionalPackages::INSTALL_MODULAR],
];
}
/**
* @dataProvider installSelections
*
* @param string $selection
* @param string $expected
*/
public function testRequestInstallTypeReturnsExpectedConstantValue($selection, $expected)
{
$this->io
->ask(Argument::that([__CLASS__, 'assertQueryPrompt']), '2')
->willReturn($selection);
$this->assertSame($expected, $this->installer->requestInstallType());
}
public function testWillContinueToPromptUntilValidAnswerPresented()
{
$io = $this->io;
$tries = mt_rand(1, 10);
// Handle a call to ask() by looping $tries times
$handle = function () use ($io, &$tries, &$handle) {
if (0 === $tries) {
// Valid choice to complete the loop
return '1';
}
// Otherwise, ask again.
$tries -= 1;
$io->ask(Argument::that([__CLASS__, 'assertQueryPrompt']), '2')->will($handle);
return 'n';
};
$this->io
->ask(Argument::that([__CLASS__, 'assertQueryPrompt']), '2')
->will($handle);
$this->io
->write(Argument::containingString('Invalid answer'))
->shouldBeCalledTimes($tries);
$this->assertSame(OptionalPackages::INSTALL_MINIMAL, $this->installer->requestInstallType());
$this->assertEquals(0, $tries);
}
public static function assertQueryPrompt($value)
{
$value = is_array($value) ? array_shift($value) : $value;
self::assertThat(
false !== strpos($value, 'What type of installation would you like?'),
self::isTrue(),
'Unexpected prompt value'
);
return true;
}
}