Skip to content

Commit

Permalink
Tweak cli scripts to run composer dump-autoload upon successful compl…
Browse files Browse the repository at this point in the history
…etion
  • Loading branch information
rotimi committed May 26, 2024
1 parent df3480e commit 38f637e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/scripts/cli-script-helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,6 @@ function createController($argc, array $argv): CreateControllerReturnValue {
}

$success_messages .= PHP_EOL . "All done!!";
$success_messages .= PHP_EOL . "Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `$studly_controller_name` in `{$dest_controller_class_file}`.";

return new CreateControllerReturnValue(
CliExitCodes::SUCCESS_EXIT,
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/smvc-create-controller
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,19 @@ if( !\SlimMvcTools\Functions\CliHelpers\isPhpRunningInCliMode() ) {
} else {

try {
$current_directory = getcwd();
echo "Current working directory: " . getcwd() . PHP_EOL;
$result = \SlimMvcTools\Functions\CliHelpers\createController($argc, $argv);

\SlimMvcTools\Functions\CliHelpers\printType(
$result->getReturnCode(), $result->getReturnMessage(), true
);

if($result->getReturnCode() === \SlimMvcTools\Functions\CliHelpers\CliExitCodes::SUCCESS_EXIT) {

passthru("cd {$current_directory} && composer dump-autoload -o");
}

exit($result->getReturnCode());

} catch(\Exception $e) {
Expand Down
8 changes: 8 additions & 0 deletions src/scripts/smvc-create-controller-wizard
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if( !\SlimMvcTools\Functions\CliHelpers\isPhpRunningInCliMode() ) {
} else {

try {
$current_directory = getcwd();
echo "Current working directory: " . getcwd() . PHP_EOL;

// we are going to mimic $argc and $argv
$psuedo_argv = [];

Expand Down Expand Up @@ -103,6 +106,11 @@ if( !\SlimMvcTools\Functions\CliHelpers\isPhpRunningInCliMode() ) {
true
);

if($result->getReturnCode() === \SlimMvcTools\Functions\CliHelpers\CliExitCodes::SUCCESS_EXIT) {

passthru("cd {$current_directory} && composer dump-autoload -o");
}

exit($result->getReturnCode());

} catch(\Exception $e) {
Expand Down
4 changes: 0 additions & 4 deletions tests/CliScriptHelperFunctionsNamespacedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,6 @@ public function testThatCreateControllerWorksAsExpectedWithValidParamsAndNoNames
$expected_message3 = PHP_EOL . "Creating index view for `BlogComments::actionIndex()` in `{$dest_view_file}` ....";
$expected_message4 = PHP_EOL . "Successfully created `{$dest_view_file}` ....".PHP_EOL;
$expected_message5 = PHP_EOL . "All done!!";
$expected_message6 = PHP_EOL . "Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `BlogComments` in `{$dest_controller_class_file}`.";

self::assertEquals(\SlimMvcTools\Functions\CliHelpers\CliExitCodes::SUCCESS_EXIT, $return_val->getReturnCode());

Expand All @@ -503,7 +502,6 @@ public function testThatCreateControllerWorksAsExpectedWithValidParamsAndNoNames
self::assertStringContainsString($expected_message3, $return_val->getReturnMessage());
self::assertStringContainsString($expected_message4, $return_val->getReturnMessage());
self::assertStringContainsString($expected_message5, $return_val->getReturnMessage());
self::assertStringContainsString($expected_message6, $return_val->getReturnMessage());

// clean-up
$this->rmdirRecursive($src_path . DIRECTORY_SEPARATOR . 'controllers');
Expand Down Expand Up @@ -550,7 +548,6 @@ public function testThatCreateControllerWorksAsExpectedWithValidParamsAndNamespa
$expected_message3 = PHP_EOL . "Creating index view for `BlogComments::actionIndex()` in `{$dest_view_file}` ....";
$expected_message4 = PHP_EOL . "Successfully created `{$dest_view_file}` ....".PHP_EOL;
$expected_message5 = PHP_EOL . "All done!!";
$expected_message6 = PHP_EOL . "Remember to run `composer dumpautoload` so that composer can pick up the newly created controller class `BlogComments` in `{$dest_controller_class_file}`.";

self::assertEquals(\SlimMvcTools\Functions\CliHelpers\CliExitCodes::SUCCESS_EXIT, $return_val->getReturnCode());

Expand All @@ -567,7 +564,6 @@ public function testThatCreateControllerWorksAsExpectedWithValidParamsAndNamespa
self::assertStringContainsString($expected_message3, $return_val->getReturnMessage());
self::assertStringContainsString($expected_message4, $return_val->getReturnMessage());
self::assertStringContainsString($expected_message5, $return_val->getReturnMessage());
self::assertStringContainsString($expected_message6, $return_val->getReturnMessage());

// clean-up
$this->rmdirRecursive($src_path . DIRECTORY_SEPARATOR . 'controllers');
Expand Down

0 comments on commit 38f637e

Please sign in to comment.