1010
1111namespace AllInData \ContentFuzzyfyr \Test \Unit \Console \Command ;
1212
13- use Symfony \Component \Console \Tester \CommandTester ;
13+ use AllInData \ContentFuzzyfyr \Model \Configuration ;
14+ use AllInData \ContentFuzzyfyr \Test \Unit \AbstractTest ;
15+ use Magento \Framework \App \State ;
16+ use Magento \Framework \EntityManager \EventManager ;
17+ use AllInData \ContentFuzzyfyr \Model \ConfigurationFactory ;
1418use AllInData \ContentFuzzyfyr \Console \Command \FuzzyfyrCommand ;
19+ use PHPUnit \Framework \MockObject \MockObject ;
20+ use Symfony \Component \Console \Input \InputInterface ;
21+ use Symfony \Component \Console \Output \OutputInterface ;
1522
16- class FuzzyfyrCommandTest extends \PHPUnit \Framework \TestCase
23+ /**
24+ * Class FuzzyfyrCommandTest
25+ * @package AllInData\ContentFuzzyfyr\Test\Unit\Console\Command
26+ */
27+ class FuzzyfyrCommandTest extends AbstractTest
1728{
1829 /**
19- * @var FuzzyfyrCommand
30+ * @test
2031 */
21- private $ command ;
32+ public function runSuccessfully ()
33+ {
34+ $ state = $ this ->getState ();
35+
36+ $ eventManager = $ this ->getEventManager ();
37+
38+ $ configuration = $ this ->getMockBuilder (Configuration::class)->getMock ();
39+ $ configurationFactory = $ this ->getConfigurationFactory ();
40+ $ configurationFactory ->expects ($ this ->once ())
41+ ->method ('create ' )
42+ ->willReturn ($ configuration );
43+
44+ $ command = new FuzzyfyrCommand (
45+ $ state ,
46+ $ eventManager ,
47+ $ configurationFactory
48+ );
49+
50+ $ input = $ this ->getInput ();
51+ $ output = $ this ->getOutput ();
2252
23- public function setUp ()
53+ $ this ->assertEquals (FuzzyfyrCommand::SUCCESS , $ command ->run ($ input , $ output ));
54+ }
55+ /**
56+ * @test
57+ */
58+ public function runFailsInProductionMode ()
2459 {
25- $ this ->command = new FuzzyfyrCommand ();
60+ $ state = $ this ->getState ();
61+ $ state ->expects ($ this ->any ())
62+ ->method ('getMode ' )
63+ ->willReturn (\Magento \Framework \App \State::MODE_PRODUCTION );
64+
65+ $ eventManager = $ this ->getEventManager ();
66+
67+ $ configurationFactory = $ this ->getConfigurationFactory ();
68+ $ configurationFactory ->expects ($ this ->never ())
69+ ->method ('create ' );
70+
71+ $ command = new FuzzyfyrCommand (
72+ $ state ,
73+ $ eventManager ,
74+ $ configurationFactory
75+ );
76+
77+ $ input = $ this ->getInput ();
78+ $ output = $ this ->getOutput ();
79+
80+ $ this ->assertEquals (FuzzyfyrCommand::ERROR_PRODUCTION_MODE , $ command ->run ($ input , $ output ));
2681 }
2782
28- public function testExecuteAnonymous ()
83+ /**
84+ * @return MockObject|State
85+ */
86+ private function getState ()
2987 {
30- $ commandTester = new CommandTester ($ this ->command );
31- $ commandTester ->execute (
32- [
33- '-a ' => true
34- ]
35- );
88+ return $ this ->getMockBuilder (State::class)
89+ ->disableOriginalConstructor ()
90+ ->getMock ();
91+ }
3692
37- $ this ->assertContains ('Hello Anonymous! ' , $ commandTester ->getDisplay ());
93+ /**
94+ * @return MockObject|EventManager
95+ */
96+ private function getEventManager ()
97+ {
98+ return $ this ->getMockBuilder (EventManager::class)
99+ ->disableOriginalConstructor ()
100+ ->getMock ();
38101 }
39102
40- public function testExecuteName ()
103+ /**
104+ * @return MockObject|ConfigurationFactory
105+ */
106+ private function getConfigurationFactory ()
41107 {
42- $ commandTester = new CommandTester ($ this ->command );
43- $ commandTester ->execute (
44- [
45- FuzzyfyrCommand::NAME_ARGUMENT => 'Test '
46- ]
47- );
108+ return $ this ->getMockBuilder (ConfigurationFactory::class)
109+ ->disableOriginalConstructor ()
110+ ->getMock ();
111+ }
48112
49- $ this ->assertContains ('Hello Test! ' , $ commandTester ->getDisplay ());
113+ /**
114+ * @return MockObject|InputInterface
115+ */
116+ private function getInput ()
117+ {
118+ return $ this ->getMockBuilder (InputInterface::class)
119+ ->disableOriginalConstructor ()
120+ ->getMock ();
50121 }
51122
52123 /**
53- * @expectedException \InvalidArgumentException
54- * @expectedExceptionMessage Argument name is missing
124+ * @return MockObject|OutputInterface
55125 */
56- public function testExecuteError ()
126+ private function getOutput ()
57127 {
58- $ commandTester = new CommandTester ($ this ->command );
59- $ commandTester ->execute ([]);
128+ return $ this ->getMockBuilder (OutputInterface::class)
129+ ->disableOriginalConstructor ()
130+ ->getMock ();
60131 }
61- }
132+ }
0 commit comments