Skip to content

Commit

Permalink
Rework our examples
Browse files Browse the repository at this point in the history
  • Loading branch information
lyrixx committed Nov 15, 2024
1 parent 8017946 commit ca38d02
Show file tree
Hide file tree
Showing 19 changed files with 71 additions and 98 deletions.
2 changes: 1 addition & 1 deletion bin/generate-tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
'watch:stop',
'open:documentation',
'open:multiple',
'release',
// Not examples
'castor:compile',
'castor:phar:build',
Expand All @@ -72,6 +71,7 @@
'castor:phar:linux',
'castor:phar:update',
'castor:phar:windows',
'castor:release:release',
'castor:repack',
'castor:static:darwin-amd64',
'castor:static:darwin-arm64',
Expand Down
4 changes: 2 additions & 2 deletions doc/getting-started/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace then the task will have no namespace.
From now on, we will omit the leading `<?php` in all doc examples.

> [!TIP]
> Related example: [foo.php](https://github.com/jolicode/castor/blob/main/examples/foo.php)
> Related example: [configuration](https://github.com/jolicode/castor/blob/main/examples/configuration)
Castor will also look for a `.castor/castor.php` file in the current directory,
or in its parents.
Expand Down Expand Up @@ -102,7 +102,7 @@ function a_very_long_function_name_that_is_very_painful_to_write(): void
```

> [!TIP]
> Related example: [foo.php](https://github.com/jolicode/castor/blob/main/examples/foo.php)
> Related example: [configuration](https://github.com/jolicode/castor/blob/main/examples/configuration)
## Setting a default task

Expand Down
16 changes: 0 additions & 16 deletions examples/bar.php

This file was deleted.

48 changes: 48 additions & 0 deletions examples/configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

// Play with configuration and namespaces

namespace configuration\foo;

use Castor\Attribute\AsTask;

use function Castor\io;

#[AsTask(description: 'Prints foo')]
function foo(): void
{
io()->writeln('foo');
}

namespace configuration\bar;

use Castor\Attribute\AsTask;

use function Castor\io;
use function configuration\foo\foo;

#[AsTask(description: 'Prints bar, but also executes foo')]
function bar(): void
{
foo();

io()->writeln('bar');
}

namespace configuration\rename;

use Castor\Attribute\AsTask;

use function Castor\io;

#[AsTask(name: 'renamed', namespace: 'configuration', description: 'Task that was renamed')]
function a_very_long_function_name_that_is_very_painful_to_write(): void
{
io()->writeln('Foo bar');
}

#[AsTask(name: 'no-namespace', namespace: '', description: 'Task without a namespace')]
function no_namespace(): void
{
io()->writeln('renamed');
}
19 changes: 0 additions & 19 deletions examples/foo.php

This file was deleted.

19 changes: 0 additions & 19 deletions examples/rename.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function renderThrowable(\Throwable $e, OutputInterface $output): void
$process = $e->getProcess();
$runnable = $this->processRunner->buildRunnableCommand($process);

$this->io->writeln(sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a'))));
$this->io->writeln(\sprintf('<comment>%s</comment>', OutputFormatter::escape(\sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a'))));
$this->io->error('The following process did not finish successfully (exit code ' . $process->getExitCode() . '):');
$this->io->writeln("<fg=yellow>{$runnable}</>");
$this->io->newLine();
Expand Down
22 changes: 0 additions & 22 deletions tests/Generated/BarBarTest.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Castor\Tests\TaskTestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;

class FooBarTest extends TaskTestCase
class ConfigurationBarBarTest extends TaskTestCase
{
// foo:bar
// configuration:bar:bar
public function test(): void
{
$process = $this->runTask(['foo:bar']);
$process = $this->runTask(['configuration:bar:bar']);

if (0 !== $process->getExitCode()) {
throw new ProcessFailedException($process);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Castor\Tests\TaskTestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;

class FooFooTest extends TaskTestCase
class ConfigurationFooFooTest extends TaskTestCase
{
// foo:foo
// configuration:foo:foo
public function test(): void
{
$process = $this->runTask(['foo:foo']);
$process = $this->runTask(['configuration:foo:foo']);

if (0 !== $process->getExitCode()) {
throw new ProcessFailedException($process);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
use Castor\Tests\TaskTestCase;
use Symfony\Component\Process\Exception\ProcessFailedException;

class NotRenameRenamedTest extends TaskTestCase
class ConfigurationRenamedTest extends TaskTestCase
{
// not-rename:renamed
// configuration:renamed
public function test(): void
{
$process = $this->runTask(['not-rename:renamed']);
$process = $this->runTask(['configuration:renamed']);

if (0 !== $process->getExitCode()) {
throw new ProcessFailedException($process);
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/Generated/FilesystemFindTest.php.output.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Number of PHP files: 34
Number of PHP files: 32
9 changes: 4 additions & 5 deletions tests/Generated/ListTest.php.output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ hello hello
help Display help for a command
list List commands
no-namespace Task without a namespace
release Release a new version of castor
args:another-args Dumps all arguments and options, without configuration
args:args Dumps all arguments and options, with custom configuration
args:autocomplete-argument Provides autocomplete for an argument
args:passthru Dumps all arguments and options, without configuration nor validation
bar:bar Prints bar, but also executes foo
cache:complex Cache with usage of CacheItemInterface
cache:simple Cache a simple call
castor:composer Interact with built-in Composer for castor
Expand All @@ -18,6 +16,7 @@ castor:phar:install install depend
castor:phar:linux Build phar for Linux system
castor:phar:update update dependencies
castor:phar:windows Build phar for Windows system
castor:release:release Release a new version of castor
castor:static:darwin-amd64 Build static binary for MacOS (amd64) system
castor:static:darwin-arm64 Build static binary for MacOS (arm64) system
castor:static:linux Build static binary for Linux system
Expand All @@ -27,6 +26,9 @@ castor:watcher:linux Build watcher
castor:watcher:windows Build watcher for Windows system
cd:directory Changes directory
command-builder:ls Run a sub-process and display information about it
configuration:bar:bar Prints bar, but also executes foo
configuration:foo:foo Prints foo
configuration:renamed Task that was renamed
context:context Displays information about the context
context:context-info-forced Displays information about the context
context:context-with Displays information about the context, using a specific context
Expand All @@ -41,15 +43,12 @@ fingerprint:task-with-a-fingerprint Execute a call
fingerprint:task-with-a-fingerprint-and-force Check if the fingerprint has changed before executing a callback (with force option)
fingerprint:task-with-a-fingerprint-global Execute a callback only if the global fingerprint has changed (Shared across all projects)
fingerprint:task-with-complete-fingerprint-check Check if the fingerprint has changed before executing some code
foo:bar Echo foo bar
foo:foo Prints foo
http:download Download a file through HTTP
http:request Make HTTP request
log:all-level Logs some messages with different levels
log:error Logs an "error" message
log:info Logs an "info" message
log:with-context Logs an "error" message
not-rename:renamed Task that was renamed
notify:notify-on-finish Sends a notification when the task finishes
notify:send-notify Sends a notification
notify:send-notify-with-custom-title Sends a notification with a custom title
Expand Down
1 change: 0 additions & 1 deletion tests/Generated/NotRenameRenamedTest.php.output.txt

This file was deleted.

3 changes: 2 additions & 1 deletion tests/Monolog/Processor/ProcessProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public function test(): void
$mock = $this->getMockBuilder(ProcessRunner::class)
->onlyMethods(['buildRunnableCommand'])
->disableOriginalConstructor()
->getMock();
->getMock()
;

$processor = new ProcessProcessor($mock);

Expand Down
4 changes: 3 additions & 1 deletion tools/release/castor.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace castor\release;

use Castor\Attribute\AsTask;
use Castor\Console\Application;
use Castor\Exception\ProblemException;
Expand All @@ -16,7 +18,7 @@
const REPO = 'jolicode/castor';
const EXPECTED_ARTIFACTS = 8;

#[AsTask(description: 'Release a new version of castor')]
#[AsTask(description: 'Release a new version of castor', aliases: ['release'])]
function release(): int
{
io()->title('Release a new version of Castor');
Expand Down

0 comments on commit ca38d02

Please sign in to comment.