88namespace Magento \MagentoCloud \Test \Unit \Step \Build ;
99
1010use Magento \MagentoCloud \App \Error ;
11+ use Magento \MagentoCloud \Config \ConfigException ;
12+ use Magento \MagentoCloud \Config \Stage \BuildInterface ;
1113use Magento \MagentoCloud \Step \Build \ComposerDumpAutoload ;
1214use Magento \MagentoCloud \Shell \ShellException ;
1315use Magento \MagentoCloud \Shell \ShellInterface ;
1416use Magento \MagentoCloud \Step \StepException ;
1517use PHPUnit \Framework \MockObject \MockObject ;
1618use PHPUnit \Framework \TestCase ;
19+ use Psr \Log \LoggerInterface ;
1720
1821/**
1922 * @inheritdoc
@@ -28,18 +31,31 @@ class ComposerDumpAutoloadTest extends TestCase
2831 /**
2932 * @var ShellInterface|MockObject
3033 */
31- private $ shell ;
34+ private $ shellMock ;
35+
36+ /**
37+ * @var BuildInterface|MockObject
38+ */
39+ private $ stageConfigMock ;
40+
41+ /**
42+ * @var LoggerInterface|MockObject
43+ */
44+ private $ loggerMock ;
3245
3346 /**
3447 * @inheritdoc
3548 */
3649 protected function setUp (): void
3750 {
38- $ this ->shell = $ this ->getMockBuilder (ShellInterface::class)
39- ->getMockForAbstractClass ();
51+ $ this ->shellMock = $ this ->getMockForAbstractClass (ShellInterface::class);
52+ $ this ->stageConfigMock = $ this ->getMockForAbstractClass (BuildInterface::class);
53+ $ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
4054
4155 $ this ->step = new ComposerDumpAutoload (
42- $ this ->shell
56+ $ this ->shellMock ,
57+ $ this ->stageConfigMock ,
58+ $ this ->loggerMock
4359 );
4460 }
4561
@@ -48,13 +64,37 @@ protected function setUp(): void
4864 */
4965 public function testExecute (): void
5066 {
51- $ this ->shell ->expects ($ this ->once ())
67+ $ this ->stageConfigMock ->expects ($ this ->once ())
68+ ->method ('get ' )
69+ ->with (BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD )
70+ ->willReturn (false );
71+ $ this ->shellMock ->expects ($ this ->once ())
5272 ->method ('execute ' )
5373 ->with ('composer dump-autoload -o --ansi --no-interaction ' );
5474
5575 $ this ->step ->execute ();
5676 }
5777
78+ /**
79+ * @throws StepException
80+ */
81+ public function testExecuteDumpSkipped (): void
82+ {
83+ $ this ->stageConfigMock ->expects ($ this ->once ())
84+ ->method ('get ' )
85+ ->with (BuildInterface::VAR_SKIP_COMPOSER_DUMP_AUTOLOAD )
86+ ->willReturn (true );
87+ $ this ->loggerMock ->expects ($ this ->once ())
88+ ->method ('info ' )
89+ ->with (
90+ 'The composer dump-autoload command was skipped as SKIP_COMPOSER_DUMP_AUTOLOAD variable is set to true '
91+ );
92+ $ this ->shellMock ->expects ($ this ->never ())
93+ ->method ('execute ' );
94+
95+ $ this ->step ->execute ();
96+ }
97+
5898 /**
5999 * @throws StepException
60100 */
@@ -64,11 +104,29 @@ public function testExecuteWithException(): void
64104 $ this ->expectExceptionMessage ('something went wrong ' );
65105 $ this ->expectExceptionCode (Error::BUILD_COMPOSER_DUMP_AUTOLOAD_FAILED );
66106
67- $ this ->shell ->expects ($ this ->once ())
107+ $ this ->shellMock ->expects ($ this ->once ())
68108 ->method ('execute ' )
69109 ->with ('composer dump-autoload -o --ansi --no-interaction ' )
70110 ->willThrowException (new ShellException ('something went wrong ' ));
71111
72112 $ this ->step ->execute ();
73113 }
114+
115+ /**
116+ * @throws StepException
117+ */
118+ public function testExecuteWithConfigException (): void
119+ {
120+ $ this ->expectException (StepException::class);
121+ $ this ->expectExceptionMessage ('something went wrong ' );
122+ $ this ->expectExceptionCode (10 );
123+
124+ $ this ->stageConfigMock ->expects ($ this ->once ())
125+ ->method ('get ' )
126+ ->willThrowException (new ConfigException ('something went wrong ' , 10 ));
127+ $ this ->shellMock ->expects ($ this ->never ())
128+ ->method ('execute ' );
129+
130+ $ this ->step ->execute ();
131+ }
74132}
0 commit comments