1919use Ymir \Cli \ExecutionContext ;
2020use Ymir \Cli \Project \Configuration \ImageDeploymentConfigurationChange ;
2121use Ymir \Cli \Project \Initialization \DockerInitializationStep ;
22+ use Ymir \Cli \Project \Type \ProjectTypeInterface ;
2223use Ymir \Cli \Tests \TestCase ;
2324
2425class DockerInitializationStepTest extends TestCase
@@ -59,35 +60,43 @@ protected function setUp(): void
5960
6061 public function testPerformAsksToOverwriteExistingDockerfile (): void
6162 {
63+ $ projectType = \Mockery::mock (ProjectTypeInterface::class);
64+ $ projectType ->shouldReceive ('getDefaultPhpVersion ' )->once ()->andReturn ('php-version ' );
65+
6266 $ this ->output ->shouldReceive ('confirm ' )->with ('Do you want to deploy this project using a container image? ' )->once ()->andReturn (true );
6367 $ this ->dockerfile ->shouldReceive ('exists ' )->once ()->andReturn (true );
6468 $ this ->output ->shouldReceive ('confirm ' )->with ('A <comment>Dockerfile</comment> already exists in the project directory. Do you want to overwrite it? ' , false )->once ()->andReturn (true );
65- $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-74 ' );
69+ $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-version ' );
6670 $ this ->dockerExecutable ->shouldReceive ('isInstalled ' )->once ()->andReturn (true );
6771
6872 $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
6973
70- $ result = $ step ->perform ($ this ->context , []);
74+ $ result = $ step ->perform ($ this ->context , [' type ' => $ projectType ]);
7175
7276 $ this ->assertInstanceOf (ImageDeploymentConfigurationChange::class, $ result );
7377 }
7478
7579 public function testPerformCreatesDockerfileAndReturnsImageDeploymentConfigurationChange (): void
7680 {
81+ $ projectType = \Mockery::mock (ProjectTypeInterface::class);
82+ $ projectType ->shouldReceive ('getDefaultPhpVersion ' )->once ()->andReturn ('php-version ' );
83+
7784 $ this ->output ->shouldReceive ('confirm ' )->with ('Do you want to deploy this project using a container image? ' )->once ()->andReturn (true );
7885 $ this ->dockerfile ->shouldReceive ('exists ' )->once ()->andReturn (false );
79- $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-74 ' );
86+ $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-version ' );
8087 $ this ->dockerExecutable ->shouldReceive ('isInstalled ' )->once ()->andReturn (true );
8188
8289 $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
8390
84- $ result = $ step ->perform ($ this ->context , []);
91+ $ result = $ step ->perform ($ this ->context , [' type ' => $ projectType ]);
8592
8693 $ this ->assertInstanceOf (ImageDeploymentConfigurationChange::class, $ result );
8794 }
8895
8996 public function testPerformDoesNotOverwriteExistingDockerfileIfUserDeclines (): void
9097 {
98+ $ projectType = \Mockery::mock (ProjectTypeInterface::class);
99+
91100 $ this ->output ->shouldReceive ('confirm ' )->with ('Do you want to deploy this project using a container image? ' )->once ()->andReturn (true );
92101 $ this ->dockerfile ->shouldReceive ('exists ' )->once ()->andReturn (true );
93102 $ this ->output ->shouldReceive ('confirm ' )->with ('A <comment>Dockerfile</comment> already exists in the project directory. Do you want to overwrite it? ' , false )->once ()->andReturn (false );
@@ -96,31 +105,62 @@ public function testPerformDoesNotOverwriteExistingDockerfileIfUserDeclines(): v
96105
97106 $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
98107
99- $ result = $ step ->perform ($ this ->context , []);
108+ $ result = $ step ->perform ($ this ->context , [' type ' => $ projectType ]);
100109
101110 $ this ->assertInstanceOf (ImageDeploymentConfigurationChange::class, $ result );
102111 }
103112
104113 public function testPerformReturnsNullIfUserDeclinesImageDeployment (): void
105114 {
115+ $ projectType = \Mockery::mock (ProjectTypeInterface::class);
116+
106117 $ this ->output ->shouldReceive ('confirm ' )->with ('Do you want to deploy this project using a container image? ' )->once ()->andReturn (false );
107118
108119 $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
109120
121+ $ this ->assertNull ($ step ->perform ($ this ->context , ['type ' => $ projectType ]));
122+ }
123+
124+ public function testPerformReturnsNullWithoutProjectType (): void
125+ {
126+ $ this ->output ->shouldNotReceive ('confirm ' );
127+
128+ $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
129+
110130 $ this ->assertNull ($ step ->perform ($ this ->context , []));
111131 }
112132
113133 public function testPerformShowsWarningIfDockerIsNotInstalled (): void
114134 {
135+ $ projectType = \Mockery::mock (ProjectTypeInterface::class);
136+ $ projectType ->shouldReceive ('getDefaultPhpVersion ' )->once ()->andReturn ('php-version ' );
137+
115138 $ this ->output ->shouldReceive ('confirm ' )->with ('Do you want to deploy this project using a container image? ' )->once ()->andReturn (true );
116139 $ this ->dockerfile ->shouldReceive ('exists ' )->once ()->andReturn (false );
117- $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-74 ' );
140+ $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-version ' );
118141 $ this ->dockerExecutable ->shouldReceive ('isInstalled ' )->once ()->andReturn (false );
119142 $ this ->output ->shouldReceive ('warning ' )->with ("<comment>Docker</comment> wasn't detected and is required to deploy the project locally " )->once ();
120143
121144 $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
122145
123- $ result = $ step ->perform ($ this ->context , []);
146+ $ result = $ step ->perform ($ this ->context , ['type ' => $ projectType ]);
147+
148+ $ this ->assertInstanceOf (ImageDeploymentConfigurationChange::class, $ result );
149+ }
150+
151+ public function testPerformUsesProjectTypeDefaultPhpVersion (): void
152+ {
153+ $ projectType = \Mockery::mock (ProjectTypeInterface::class);
154+ $ projectType ->shouldReceive ('getDefaultPhpVersion ' )->once ()->andReturn ('php-version ' );
155+
156+ $ this ->output ->shouldReceive ('confirm ' )->with ('Do you want to deploy this project using a container image? ' )->once ()->andReturn (true );
157+ $ this ->dockerfile ->shouldReceive ('exists ' )->once ()->andReturn (false );
158+ $ this ->dockerfile ->shouldReceive ('create ' )->once ()->with ('arm64 ' , 'php-version ' );
159+ $ this ->dockerExecutable ->shouldReceive ('isInstalled ' )->once ()->andReturn (true );
160+
161+ $ step = new DockerInitializationStep ($ this ->dockerExecutable , $ this ->dockerfile );
162+
163+ $ result = $ step ->perform ($ this ->context , ['type ' => $ projectType ]);
124164
125165 $ this ->assertInstanceOf (ImageDeploymentConfigurationChange::class, $ result );
126166 }
0 commit comments