@@ -84,7 +84,8 @@ private function run_script( array $args ): array {
8484 $ command .= ' ' . escapeshellarg ( $ arg );
8585 }
8686
87- $ command = 'cd ' . escapeshellarg ( $ this ->temp_dir ) . ' && ' . $ command . ' 2>&1 ' ;
87+ $ cd_command = Utils \is_windows () ? 'cd /d ' : 'cd ' ;
88+ $ command = $ cd_command . escapeshellarg ( $ this ->temp_dir ) . ' && ' . $ command . ' 2>&1 ' ;
8889
8990 $ output = array ();
9091 $ exit_code = 0 ;
@@ -235,6 +236,14 @@ public function test_extracts_multiple_blocks_from_one_feature_file(): void {
235236 ),
236237 $ this ->get_extracted_files ()
237238 );
239+ $ this ->assertSame (
240+ "\n\n\n\n\n<?php \n\$foo = 'bar'; \n" ,
241+ $ this ->get_extracted_contents ( 'example.feature_L5_E8_HASPHP.php ' )
242+ );
243+ $ this ->assertSame (
244+ "\n\n\n\n\n\n\n\n\n\n<?php \n\$baz = 'qux'; \n" ,
245+ $ this ->get_extracted_contents ( 'example.feature_L10_E13_HASPHP.php ' )
246+ );
238247 }
239248
240249 public function test_extracts_from_nested_directories (): void {
@@ -366,21 +375,50 @@ public function test_extraction_refuses_to_use_the_source_directory_as_target():
366375 }
367376
368377 public function test_extraction_refuses_to_use_the_current_directory_as_target (): void {
369- $ this ->create_feature_file (
370- 'example.feature ' ,
371- "Feature: Example \n"
378+ $ contents = "Feature: Example \n"
372379 . " Scenario: A PHP block \n"
373380 . " Given a test.php file: \n"
374381 . " \"\"\"\n"
375382 . " <?php \n"
376383 . " \$foo = 'bar'; \n"
377- . " \"\"\"\n"
378- );
384+ . " \"\"\"\n" ;
385+
386+ $ feature_file = $ this ->create_feature_file ( 'example.feature ' , $ contents );
379387
380388 $ result = $ this ->run_script ( array ( 'extract ' , 'features ' , '. ' ) );
381389
382390 $ this ->assertSame ( 1 , $ result ['exit_code ' ] );
383391 $ this ->assertDirectoryExists ( $ this ->features_dir );
392+ $ this ->assertSame ( $ contents , file_get_contents ( $ feature_file ) );
393+
394+ $ extracted_files = array ();
395+ $ iterator = new \RecursiveIteratorIterator (
396+ new \RecursiveDirectoryIterator ( $ this ->temp_dir , \FilesystemIterator::SKIP_DOTS )
397+ );
398+ foreach ( $ iterator as $ file ) {
399+ if ( $ file ->isFile () && 'php ' === $ file ->getExtension () ) {
400+ $ extracted_files [] = $ file ->getPathname ();
401+ }
402+ }
403+ $ this ->assertSame ( array (), $ extracted_files );
404+ }
405+
406+ public function test_extraction_reports_unterminated_docstring (): void {
407+ $ this ->create_feature_file (
408+ 'unterminated.feature ' ,
409+ "Feature: Unterminated \n"
410+ . " Scenario: Unterminated docstring \n"
411+ . " Given a test.php file: \n"
412+ . " \"\"\"\n"
413+ . " <?php \n"
414+ . " \$foo = 'bar'; \n"
415+ );
416+
417+ $ result = $ this ->run_script ( array ( 'extract ' , 'features ' , 'extracted ' ) );
418+
419+ $ this ->assertSame ( 1 , $ result ['exit_code ' ] );
420+ $ this ->assertStringContainsString ( 'Unterminated docstring ' , $ result ['output ' ] );
421+ $ this ->assertSame ( array (), $ this ->get_extracted_files () );
384422 }
385423
386424 public function test_directories_are_not_mistaken_for_an_action (): void {
0 commit comments