@@ -86,7 +86,7 @@ protected function tearDown(): void
8686 #[Test]
8787 public function detectRuntimeWillPreferTheConsumerLocalInstallation (): void
8888 {
89- $ this ->createRuntimeFiles ($ this ->workspace . ' /vendor ' );
89+ $ this ->createInstalledRuntimeFiles ($ this ->workspace );
9090 $ resolvedWorkspace = realpath ($ this ->workspace );
9191
9292 $ files = $ this ->createGitHubActionFiles ();
@@ -123,10 +123,33 @@ public function detectRuntimeWillFallbackToTheWorkflowSourceWhenTheConsumerDoesN
123123
124124 self ::assertSame ('workflow ' , $ outputs ['source ' ]);
125125 self ::assertSame ('true ' , $ outputs ['needs-fallback ' ]);
126- self ::assertSame ($ resolvedWorkspace . '/.dev-tools-actions/vendor/ bin/dev-tools ' , $ outputs ['binary ' ]);
126+ self ::assertSame ($ resolvedWorkspace . '/.dev-tools-actions/bin/dev-tools ' , $ outputs ['binary ' ]);
127127 self ::assertSame ($ resolvedWorkspace . '/.dev-tools-actions/vendor/autoload.php ' , $ outputs ['autoload ' ]);
128128 }
129129
130+ /**
131+ * @return void
132+ */
133+ #[Test]
134+ public function detectRuntimeWillPreferTheWorkspaceRootRepositoryCheckout (): void
135+ {
136+ $ this ->createRepositoryRuntimeFiles ($ this ->workspace );
137+ $ resolvedWorkspace = realpath ($ this ->workspace );
138+
139+ $ files = $ this ->createGitHubActionFiles ();
140+
141+ $ this ->runActionScript ('detect-dev-tools-runtime.sh ' , [
142+ 'GITHUB_OUTPUT ' => $ files ['output ' ],
143+ ]);
144+
145+ $ outputs = $ this ->parseKeyValueFile ($ files ['output ' ]);
146+
147+ self ::assertSame ('local ' , $ outputs ['source ' ]);
148+ self ::assertSame ('false ' , $ outputs ['needs-fallback ' ]);
149+ self ::assertSame ($ resolvedWorkspace . '/bin/dev-tools ' , $ outputs ['binary ' ]);
150+ self ::assertSame ($ resolvedWorkspace . '/vendor/autoload.php ' , $ outputs ['autoload ' ]);
151+ }
152+
130153 /**
131154 * @return void
132155 */
@@ -135,7 +158,7 @@ public function exposeRuntimeWillPublishWrapperAndEnvironmentVariablesForTheWork
135158 {
136159 mkdir ($ this ->workspace . '/.dev-tools-actions ' , 0o777 , true );
137160 file_put_contents ($ this ->workspace . '/.dev-tools-actions/composer.json ' , "{} \n" );
138- $ this ->createRuntimeFiles ($ this ->workspace . '/.dev-tools-actions/vendor ' );
161+ $ this ->createRepositoryRuntimeFiles ($ this ->workspace . '/.dev-tools-actions ' );
139162 $ resolvedWorkspace = realpath ($ this ->workspace );
140163
141164 $ files = $ this ->createGitHubActionFiles ();
@@ -154,7 +177,7 @@ public function exposeRuntimeWillPublishWrapperAndEnvironmentVariablesForTheWork
154177 $ pathEntries = array_filter (explode ("\n" , trim (file_get_contents ($ files ['path ' ]))));
155178
156179 self ::assertSame ('workflow ' , $ outputs ['source ' ]);
157- self ::assertSame ($ resolvedWorkspace . '/.dev-tools-actions/vendor/ bin/dev-tools ' , $ outputs ['binary ' ]);
180+ self ::assertSame ($ resolvedWorkspace . '/.dev-tools-actions/bin/dev-tools ' , $ outputs ['binary ' ]);
158181 self ::assertSame ($ resolvedWorkspace . '/.dev-tools-actions/vendor/autoload.php ' , $ outputs ['autoload ' ]);
159182 self ::assertSame ($ outputs ['binary ' ], $ environment ['DEV_TOOLS_BINARY ' ]);
160183 self ::assertSame ($ outputs ['autoload ' ], $ environment ['DEV_TOOLS_AUTOLOAD ' ]);
@@ -170,19 +193,36 @@ public function exposeRuntimeWillPublishWrapperAndEnvironmentVariablesForTheWork
170193 }
171194
172195 /**
173- * @param string $runtimeVendorDirectory
196+ * @param string $runtimeRoot
197+ *
198+ * @return void
199+ */
200+ private function createInstalledRuntimeFiles (string $ runtimeRoot ): void
201+ {
202+ mkdir ($ runtimeRoot . '/vendor/bin ' , 0o777 , true );
203+ file_put_contents (
204+ $ runtimeRoot . '/vendor/bin/dev-tools ' ,
205+ "#!/usr/bin/env bash \nprintf 'dev-tools:%s \\n' \"\$* \"\n" ,
206+ );
207+ chmod ($ runtimeRoot . '/vendor/bin/dev-tools ' , 0o755 );
208+ file_put_contents ($ runtimeRoot . '/vendor/autoload.php ' , "<?php \n" );
209+ }
210+
211+ /**
212+ * @param string $runtimeRoot
174213 *
175214 * @return void
176215 */
177- private function createRuntimeFiles (string $ runtimeVendorDirectory ): void
216+ private function createRepositoryRuntimeFiles (string $ runtimeRoot ): void
178217 {
179- mkdir ($ runtimeVendorDirectory . '/bin ' , 0o777 , true );
218+ mkdir ($ runtimeRoot . '/bin ' , 0o777 , true );
219+ mkdir ($ runtimeRoot . '/vendor ' , 0o777 , true );
180220 file_put_contents (
181- $ runtimeVendorDirectory . '/bin/dev-tools ' ,
221+ $ runtimeRoot . '/bin/dev-tools ' ,
182222 "#!/usr/bin/env bash \nprintf 'dev-tools:%s \\n' \"\$* \"\n" ,
183223 );
184- chmod ($ runtimeVendorDirectory . '/bin/dev-tools ' , 0o755 );
185- file_put_contents ($ runtimeVendorDirectory . '/autoload.php ' , "<?php \n" );
224+ chmod ($ runtimeRoot . '/bin/dev-tools ' , 0o755 );
225+ file_put_contents ($ runtimeRoot . '/vendor /autoload.php ' , "<?php \n" );
186226 }
187227
188228 /**
0 commit comments