Skip to content

Commit

Permalink
feat: add sponsor method
Browse files Browse the repository at this point in the history
Signed-off-by: asciito <ayax.cordova@aydev.mx>
  • Loading branch information
asciito committed Oct 4, 2023
1 parent 0ec26a4 commit 1525cca
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Package/Concerns/HasInstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,29 @@ public function preConfigureInstallCommand(Command $command): void
}

$command->addOption('all', description: 'Install all the package components');

$command::macro('sponsor', function (string $message, string $url) use ($command) {
$ans = $command->confirm($message);

if (! $ans) {
return;
}

$url = urlencode($url);

if (PHP_OS_FAMILY == 'Darwin') {
exec("open $url");
}

if (PHP_OS_FAMILY == 'Windows') {
exec("start $url");
}

if (PHP_OS_FAMILY == 'Linux') {
exec("xdg-open $url");
}

$command->info('Thanks!');
});
}
}
8 changes: 8 additions & 0 deletions tests/Feature/Command/PackageInstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ protected function configurePackage(Package $package): void
'package:install',
function ($command) {
$command->info('This is a message');

$command->sponsor('Please, give us a star on Github', 'https://example.com');
}
);
}
Expand All @@ -35,6 +37,8 @@ function ($command) {
->expectsOutputToContain('Installing Package Components')
->expectsOutput('This is a message')
->expectsOutputToContain('None package components were installed')
->expectsQuestion('Please, give us a star on Github', 'yes')
->expectsOutputToContain('Thanks!')
->assertSuccessful();
});

Expand All @@ -44,6 +48,8 @@ function ($command) {
->doesntExpectOutputToContain('Publishing Component [Migration] files')
->doesntExpectOutputToContain('None package components were installed')
->expectsOutputToContain('Package Component(s) installed')
->expectsQuestion('Please, give us a star on Github', false)
->doesntExpectOutputToContain('Thanks!')
->assertSuccessful();

expect(config_path('one.php'))
Expand All @@ -58,6 +64,7 @@ function ($command) {
->doesntExpectOutputToContain('Publishing Component [Config] files')
->doesntExpectOutputToContain('None package components were installed')
->expectsOutputToContain('Package Component(s) installed')
->expectsQuestion('Please, give us a star on Github', false)
->assertSuccessful();

expect(database_path('migrations/create_package_test_one_table.php'))
Expand All @@ -72,5 +79,6 @@ function ($command) {
->expectsOutputToContain('Publishing Component [Config] files')
->expectsOutputToContain('Package Component(s) installed')
->doesntExpectOutputToContain('None package components were installed')
->expectsQuestion('Please, give us a star on Github', false)
->assertSuccessful();
});

0 comments on commit 1525cca

Please sign in to comment.