Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InteractiveCollectorTest.php
Go to the documentation of this file.
1 <?php
7 
9 use PHPUnit_Framework_MockObject_MockObject as MockObject;
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\Question\QuestionFactory;
14 use Symfony\Component\Console\Helper\QuestionHelper;
15 
16 class InteractiveCollectorTest extends \PHPUnit\Framework\TestCase
17 {
21  private $questionFactoryMock;
22 
26  private $questionHelperMock;
27 
31  private $inputMock;
32 
36  private $outputMock;
37 
41  private $model;
42 
46  protected function setUp()
47  {
48  $this->questionFactoryMock = $this->getMockBuilder(QuestionFactory::class)
49  ->disableOriginalConstructor()
50  ->setMethods(['create'])
51  ->getMock();
52  $this->questionHelperMock = $this->getMockBuilder(QuestionHelper::class)
53  ->disableOriginalConstructor()
54  ->getMock();
55  $this->inputMock = $this->getMockBuilder(InputInterface::class)
56  ->getMockForAbstractClass();
57  $this->outputMock = $this->getMockBuilder(OutputInterface::class)
58  ->getMockForAbstractClass();
59 
60  $this->model = new InteractiveCollector(
61  $this->questionFactoryMock,
62  $this->questionHelperMock
63  );
64  }
65 
66  public function testGetValues()
67  {
68  $configPaths = [
69  'some/config/path1',
70  'some/config/path2',
71  'some/config/path3'
72  ];
73 
74  $questionMock = $this->getMockBuilder(Question::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77  $this->questionHelperMock->expects($this->exactly(3))
78  ->method('ask')
79  ->with($this->inputMock, $this->outputMock, $questionMock)
80  ->willReturn('someValue');
81  $this->questionFactoryMock->expects($this->exactly(3))
82  ->method('create')
83  ->withConsecutive(
84  [['question' => $configPaths[0] . ': ']],
85  [['question' => $configPaths[1] . ': ']],
86  [['question' => $configPaths[2] . ': ']]
87  )
88  ->willReturn($questionMock);
89 
90  $this->assertEquals(
91  [
92  'some/config/path1' => 'someValue',
93  'some/config/path2' => 'someValue',
94  'some/config/path3' => 'someValue'
95  ],
96  $this->model->getValues(
97  $this->inputMock,
98  $this->outputMock,
99  $configPaths
100  )
101  );
102  }
103 }