Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/pint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Pint

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
pint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.2'
coverage: none

- name: Install Composer dependencies
run: composer install --prefer-dist --no-interaction --no-progress

- name: Run Pint
run: vendor/bin/pint --test
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,8 @@
"Example": "VendorName\\ExamplePackage\\Facades\\Example"
}
}
},
"require-dev": {
"laravel/pint": "^1.27"
}
}
18 changes: 9 additions & 9 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function resolveValues(array $options): array
}

if ($missing !== []) {
fwrite(STDERR, 'Missing required options for --no-interaction: ' . implode(', ', $missing) . "\n");
fwrite(STDERR, 'Missing required options for --no-interaction: '.implode(', ', $missing)."\n");
exit(1);
}

Expand Down Expand Up @@ -249,7 +249,7 @@ function updateComposerJson(array $values, bool $dryRun): int
return 0;
}

printChange(($dryRun ? 'Would update' : 'Updated') . ' composer.json');
printChange(($dryRun ? 'Would update' : 'Updated').' composer.json');

if (! $dryRun) {
file_put_contents('composer.json', $new);
Expand Down Expand Up @@ -317,7 +317,7 @@ function updateTextFiles(array $values, bool $dryRun): int
continue;
}

printChange(($dryRun ? 'Would update' : 'Updated') . " {$file}");
printChange(($dryRun ? 'Would update' : 'Updated')." {$file}");

if (! $dryRun) {
file_put_contents($file, $updated);
Expand Down Expand Up @@ -353,7 +353,7 @@ function renameFiles(array $values, bool $dryRun): int
exit(1);
}

printChange(($dryRun ? 'Would rename' : 'Renamed') . " {$source} -> {$target}");
printChange(($dryRun ? 'Would rename' : 'Renamed')." {$source} -> {$target}");

if (! $dryRun) {
rename($source, $target);
Expand All @@ -374,7 +374,7 @@ function cleanupScaffoldFiles(bool $dryRun): int
continue;
}

printChange(($dryRun ? 'Would remove' : 'Removed') . " {$file}");
printChange(($dryRun ? 'Would remove' : 'Removed')." {$file}");

if (! $dryRun) {
unlink($file);
Expand All @@ -392,7 +392,7 @@ function cleanupScaffoldFiles(bool $dryRun): int
continue;
}

printChange(($dryRun ? 'Would remove empty directory' : 'Removed empty directory') . " {$directory}");
printChange(($dryRun ? 'Would remove empty directory' : 'Removed empty directory')." {$directory}");

if (! $dryRun) {
rmdir($directory);
Expand Down Expand Up @@ -427,7 +427,7 @@ function encodeComposerJson(array $composer): string
return str_repeat(' ', intdiv(strlen($matches[1]), 2));
}, $json);

return (string) $json . "\n";
return (string) $json."\n";
}

function readComposerJson(): array
Expand All @@ -453,12 +453,12 @@ function printSummary(array $values, array $options): void
echo "- class_name: {$values['class_name']}\n";
echo "- package_description: {$values['package_description']}\n";
echo "- command_signature: {$values['command_signature']}\n";
echo "- mode: " . ($options['dry_run'] ? 'dry-run' : 'apply') . "\n\n";
echo '- mode: '.($options['dry_run'] ? 'dry-run' : 'apply')."\n\n";
}

function printHelp(): void
{
echo <<<TXT
echo <<<'TXT'
Usage:
php configure.php [options]

Expand Down
1 change: 0 additions & 1 deletion src/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Example
/**
* Create a new Example instance.
*
* @param \Roots\Acorn\Application $app
* @return void
*/
public function __construct(Application $app)
Expand Down
46 changes: 24 additions & 22 deletions tests/smoke/configure_smoke.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
declare(strict_types=1);

$sourceRoot = dirname(__DIR__, 2);
$tempRoot = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'acorn-example-configure-' . bin2hex(random_bytes(6));
$tempRoot = rtrim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'acorn-example-configure-'.bin2hex(random_bytes(6));

recursiveCopy($sourceRoot, $tempRoot, ['.git', 'vendor']);

Expand All @@ -22,9 +22,9 @@
'--yes',
];

$command = 'cd ' . escapeshellarg($tempRoot) . ' && ' . implode(' ', array_map('escapeshellarg', $args));
exec($command . ' 2>&1', $output, $exitCode);
assertTrue($exitCode === 0, "configure.php failed:\n" . implode("\n", $output));
$command = 'cd '.escapeshellarg($tempRoot).' && '.implode(' ', array_map('escapeshellarg', $args));
exec($command.' 2>&1', $output, $exitCode);
assertTrue($exitCode === 0, "configure.php failed:\n".implode("\n", $output));

$expectedFiles = [
'src/HelloPackage.php',
Expand All @@ -45,11 +45,11 @@
];

foreach ($expectedFiles as $file) {
assertTrue(is_file($tempRoot . DIRECTORY_SEPARATOR . $file), "Expected file missing: {$file}");
assertTrue(is_file($tempRoot.DIRECTORY_SEPARATOR.$file), "Expected file missing: {$file}");
}

foreach ($oldFiles as $file) {
assertTrue(! file_exists($tempRoot . DIRECTORY_SEPARATOR . $file), "Old file still present: {$file}");
assertTrue(! file_exists($tempRoot.DIRECTORY_SEPARATOR.$file), "Old file still present: {$file}");
}

$removedScaffoldFiles = [
Expand All @@ -58,10 +58,10 @@
];

foreach ($removedScaffoldFiles as $file) {
assertTrue(! file_exists($tempRoot . DIRECTORY_SEPARATOR . $file), "Scaffold file still present: {$file}");
assertTrue(! file_exists($tempRoot.DIRECTORY_SEPARATOR.$file), "Scaffold file still present: {$file}");
}

$composerPath = $tempRoot . DIRECTORY_SEPARATOR . 'composer.json';
$composerPath = $tempRoot.DIRECTORY_SEPARATOR.'composer.json';
$composer = json_decode((string) file_get_contents($composerPath), true, 512, JSON_THROW_ON_ERROR);

assertTrue(($composer['name'] ?? null) === 'acme/hello-package', 'composer.json name was not updated');
Expand All @@ -71,24 +71,24 @@
assertTrue(isset($composer['autoload']['psr-4']['Acme\\HelloPackage\\']), 'composer psr-4 key was not updated');
assertTrue(! isset($composer['scripts']['test:configure']), 'template-only composer script should be removed');

$providerFile = (string) file_get_contents($tempRoot . DIRECTORY_SEPARATOR . 'src/Providers/HelloPackageServiceProvider.php');
assertContains($providerFile, "namespace Acme\\HelloPackage\\Providers;", 'provider namespace mismatch');
$providerFile = (string) file_get_contents($tempRoot.DIRECTORY_SEPARATOR.'src/Providers/HelloPackageServiceProvider.php');
assertContains($providerFile, 'namespace Acme\\HelloPackage\\Providers;', 'provider namespace mismatch');
assertContains($providerFile, "singleton('HelloPackage'", 'provider singleton key mismatch');
assertContains($providerFile, "config/hello-package.php", 'provider config path mismatch');
assertContains($providerFile, 'config/hello-package.php', 'provider config path mismatch');
assertContains($providerFile, "'hello-package'", 'provider config key mismatch');
assertContains($providerFile, "configPath('hello-package.php')", 'provider config publish path mismatch');

$commandFile = (string) file_get_contents($tempRoot . DIRECTORY_SEPARATOR . 'src/Console/HelloPackageCommand.php');
assertContains($commandFile, "namespace Acme\\HelloPackage\\Console;", 'command namespace mismatch');
assertContains($commandFile, "class HelloPackageCommand extends Command", 'command class mismatch');
$commandFile = (string) file_get_contents($tempRoot.DIRECTORY_SEPARATOR.'src/Console/HelloPackageCommand.php');
assertContains($commandFile, 'namespace Acme\\HelloPackage\\Console;', 'command namespace mismatch');
assertContains($commandFile, 'class HelloPackageCommand extends Command', 'command class mismatch');
assertContains($commandFile, "protected \$signature = 'hello-package';", 'command signature mismatch');

$facadeFile = (string) file_get_contents($tempRoot . DIRECTORY_SEPARATOR . 'src/Facades/HelloPackage.php');
assertContains($facadeFile, "namespace Acme\\HelloPackage\\Facades;", 'facade namespace mismatch');
assertContains($facadeFile, "class HelloPackage extends Facade", 'facade class mismatch');
$facadeFile = (string) file_get_contents($tempRoot.DIRECTORY_SEPARATOR.'src/Facades/HelloPackage.php');
assertContains($facadeFile, 'namespace Acme\\HelloPackage\\Facades;', 'facade namespace mismatch');
assertContains($facadeFile, 'class HelloPackage extends Facade', 'facade class mismatch');
assertContains($facadeFile, "return 'HelloPackage';", 'facade accessor mismatch');

$readmeFile = (string) file_get_contents($tempRoot . DIRECTORY_SEPARATOR . 'README.md');
$readmeFile = (string) file_get_contents($tempRoot.DIRECTORY_SEPARATOR.'README.md');
assertContains($readmeFile, 'composer require acme/hello-package', 'README package install line mismatch');
assertContains($readmeFile, "@include('HelloPackage::hello-package')", 'README blade usage mismatch');
assertContains($readmeFile, '$ wp acorn hello-package', 'README command usage mismatch');
Expand Down Expand Up @@ -117,11 +117,12 @@ function recursiveCopy(string $source, string $target, array $excludeNames = [])
continue;
}

$srcPath = $source . DIRECTORY_SEPARATOR . $item;
$dstPath = $target . DIRECTORY_SEPARATOR . $item;
$srcPath = $source.DIRECTORY_SEPARATOR.$item;
$dstPath = $target.DIRECTORY_SEPARATOR.$item;

if (is_dir($srcPath)) {
recursiveCopy($srcPath, $dstPath, $excludeNames);

continue;
}

Expand All @@ -139,6 +140,7 @@ function recursiveRemove(string $path): void

if (is_file($path) || is_link($path)) {
unlink($path);

return;
}

Expand All @@ -152,7 +154,7 @@ function recursiveRemove(string $path): void
continue;
}

recursiveRemove($path . DIRECTORY_SEPARATOR . $item);
recursiveRemove($path.DIRECTORY_SEPARATOR.$item);
}

rmdir($path);
Expand All @@ -161,7 +163,7 @@ function recursiveRemove(string $path): void
function assertTrue(bool $condition, string $message): void
{
if (! $condition) {
fwrite(STDERR, $message . "\n");
fwrite(STDERR, $message."\n");
exit(1);
}
}
Expand Down