SilverStripeCommandTest::testGetOrAskForArgument()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace SilverLeague\Console\Tests\Command;
4
5
use SilverLeague\Console\Command\SilverStripeCommand;
6
use SilverLeague\Console\Framework\Scaffold;
7
use SilverStripe\Config\Collections\ConfigCollectionInterface;
8
use SilverStripe\Core\Injector\Injector;
9
use Symfony\Component\Console\Helper\QuestionHelper;
10
use Symfony\Component\Console\Input\InputInterface;
11
use Symfony\Component\Console\Output\OutputInterface;
12
use Symfony\Component\Console\Question\Question;
13
use Symfony\Component\Console\Tester\CommandTester;
14
15
/**
16
 * @coversDefaultClass \SilverLeague\Console\Command\SilverStripeCommand
17
 * @package silverstripe-console
18
 * @author  Robbie Averill <[email protected]>
19
 */
20
class SilverStripeCommandTest extends \PHPUnit_Framework_TestCase
21
{
22
    /**
23
     * Test that an argument is prompted for if it doesn't get provided, or returned if provided
24
     *
25
     * @covers ::getOrAskForArgument
26
     */
27
    public function testGetOrAskForArgument()
28
    {
29
        $questionHelper = $this
30
            ->getMockBuilder(QuestionHelper::class)
31
            ->setMethods(['ask'])
32
            ->getMock();
33
34
        $questionHelper
35
            ->expects($this->atLeastOnce())
36
            ->method('ask')
37
            ->with(
38
                $this->isInstanceOf(InputInterface::class),
39
                $this->isInstanceOf(OutputInterface::class),
40
                $this->isInstanceOf(Question::class)
41
            );
42
43
        $application = (new Scaffold)->getApplication();
44
        $application->getHelperSet()->set($questionHelper, 'question');
45
46
        $command = $application->find('member:create');
47
48
        $tester = new CommandTester($command);
49
        $tester->execute(['email' => '[email protected]']);
50
51
        // Check that the email is returned since it existed
52
        $this->assertSame('[email protected]', $tester->getInput()->getArgument('email'));
53
    }
54
55
    /**
56
     * Test that the Injector is returned
57
     *
58
     * @covers ::getInjector
59
     */
60
    public function testShouldReturnInjector()
61
    {
62
        $this->assertInstanceOf(Injector::class, (new SilverStripeCommand('foo'))->getInjector());
63
    }
64
65
    /**
66
     * Test that a ConfigCollectionInterface instance is returned
67
     *
68
     * @covers ::getConfig
69
     */
70
    public function testShouldReturnConfig()
71
    {
72
        $this->assertInstanceOf(ConfigCollectionInterface::class, (new SilverStripeCommand('bar'))->getConfig());
73
    }
74
}
75