Skip to content

Commit b70b9ca

Browse files
committed
Merge branch 'main' of github.com:thettler/laravel-console-toolkit
2 parents d9850fc + 5235f89 commit b70b9ca

File tree

10 files changed

+56
-27
lines changed

10 files changed

+56
-27
lines changed

.github/workflows/dependabot-auto-merge.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- name: Dependabot metadata
1515
id: metadata
16-
uses: dependabot/fetch-metadata@v1.3.5
16+
uses: dependabot/fetch-metadata@v1.4.0
1717
with:
1818
github-token: "${{ secrets.GITHUB_TOKEN }}"
1919

.github/workflows/run-tests.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ jobs:
1313
fail-fast: true
1414
matrix:
1515
os: [ubuntu-latest, windows-latest]
16-
php: [8.1]
17-
laravel: [9.*]
16+
php: [8.1, 8.2]
17+
laravel: [9.*, 10.*]
1818
stability: [prefer-lowest, prefer-stable]
1919
include:
20+
- laravel: 10.*
21+
testbench: 8.*
2022
- laravel: 9.*
21-
testbench: ^7.0
23+
testbench: 7.*
2224

2325
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
2426

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-console-toolkit` will be documented in this file.
44

5+
## v0.1.1 - 2022-11-22
6+
7+
- Fixes Issue described in #8
8+
59
## 0.1.0 - 2022-03-1
610

711
- initial release

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
"php": "^8.1",
2020
"symfony/console": "^6.0",
2121
"spatie/laravel-package-tools": "^1.9.2",
22-
"illuminate/contracts": "^9.0"
22+
"illuminate/contracts": "^9.0|^10.0"
2323
},
2424
"require-dev": {
2525
"laravel/sail": "^1.13",
2626
"nunomaduro/collision": "^v6.1.0",
27-
"nunomaduro/larastan": "^1.0",
28-
"orchestra/testbench": "^7.0",
27+
"nunomaduro/larastan": "^2.0",
28+
"orchestra/testbench": "^7.0|^8.0",
2929
"pestphp/pest": "^1.21",
30-
"pestphp/pest-plugin-laravel": "^1.1",
30+
"pestphp/pest-plugin-laravel": "^1.4",
3131
"phpstan/extension-installer": "^1.1",
3232
"phpstan/phpstan-deprecation-rules": "^1.0",
3333
"phpstan/phpstan-phpunit": "^1.0",

src/Concerns/UsesInputValidation.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ protected function validate(Collection $collection): Collection
3535
$messages
3636
);
3737

38-
if (!$validator->fails()) {
38+
if (! $validator->fails()) {
3939
return $collection;
4040
}
4141

42-
$inputErrors = $collection->mapWithKeys(fn(InputReflection $reflection) => [
42+
$inputErrors = $collection->mapWithKeys(fn (InputReflection $reflection) => [
4343
$reflection->getName() => new InputErrorData(
4444
key: $reflection->getName(),
4545
choices: $choices[$reflection->getName()] ?? [],
@@ -56,7 +56,7 @@ protected function validate(Collection $collection): Collection
5656
*/
5757
protected function extractValidationData(Collection $collection): array
5858
{
59-
return $collection->reduce(fn(array $carry, InputReflection $reflection) => [
59+
return $collection->reduce(fn (array $carry, InputReflection $reflection) => [
6060
'values' => [...$carry['values'], ...$this->extractInputValues($reflection)],
6161
'rules' => [...$carry['rules'], ...$this->extractInputRules($reflection)],
6262
'messages' => [...$carry['messages'], ...$this->extractValidationMessages($reflection)],
@@ -71,12 +71,12 @@ protected function extractValidationData(Collection $collection): array
7171

7272
protected function extractValidationMessages(InputReflection $reflection): array
7373
{
74-
if (!$reflection->getValidationMessage()) {
74+
if (! $reflection->getValidationMessage()) {
7575
return [];
7676
}
7777

7878
return collect($reflection->getValidationMessage())
79-
->mapWithKeys(fn(string $value, string $key) => ["{$reflection->getName()}.{$key}" => $value])
79+
->mapWithKeys(fn (string $value, string $key) => ["{$reflection->getName()}.{$key}" => $value])
8080
->all();
8181
}
8282

@@ -98,7 +98,7 @@ protected function extractInputRules(
9898
): array {
9999
$rules = [];
100100

101-
if ($this->hasAutoAskEnabled($reflection) && !$reflection->isArray()) {
101+
if ($this->hasAutoAskEnabled($reflection) && ! $reflection->isArray()) {
102102
$rules[] = 'required';
103103
}
104104

src/Reflections/ArgumentReflection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
use Thettler\LaravelConsoleToolkit\Attributes\Argument;
66
use Thettler\LaravelConsoleToolkit\Enums\ConsoleInputType;
77

8+
/**
9+
* @extends InputReflection<Argument>
10+
*/
811
class ArgumentReflection extends InputReflection
912
{
1013
public static function isArgument(\ReflectionProperty $property): bool

src/Reflections/CommandReflection.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public function usesInputAttributes(): bool
3636
return $this->getArguments()->isNotEmpty() || $this->getOptions()->isNotEmpty();
3737
}
3838

39+
/**
40+
* @return Collection<int, ArgumentReflection>
41+
*/
3942
public function getArguments(): Collection
4043
{
4144
return collect($this->reflection->getProperties())
@@ -49,6 +52,9 @@ public function getArguments(): Collection
4952
);
5053
}
5154

55+
/**
56+
* @return Collection<int, OptionReflection>
57+
*/
5258
public function getOptions(): Collection
5359
{
5460
return collect($this->reflection->getProperties())

src/Transfers/InputErrorData.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22

33
namespace Thettler\LaravelConsoleToolkit\Transfers;
44

5+
use Thettler\LaravelConsoleToolkit\Contracts\ConsoleInput;
56
use Thettler\LaravelConsoleToolkit\Reflections\InputReflection;
67

78
class InputErrorData
89
{
10+
/**
11+
* @param string $key
12+
* @param array $choices
13+
* @param InputReflection<ConsoleInput> $reflection
14+
* @param bool $hasAutoAsk
15+
*/
916
public function __construct(
1017
public readonly string $key,
1118
public readonly array $choices,

tests/ConsoleInputAutoAskTest.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use Illuminate\Console\Application as Artisan;
44
use Illuminate\Console\Command;
5+
use Illuminate\Support\Facades\App;
6+
use Illuminate\Translation\Translator;
57
use Thettler\LaravelConsoleToolkit\Attributes\Argument;
68
use Thettler\LaravelConsoleToolkit\Attributes\Option;
79
use Thettler\LaravelConsoleToolkit\Concerns\UsesConsoleToolkit;
@@ -143,11 +145,12 @@ public function handle()
143145
};
144146

145147
Artisan::starting(fn (Artisan $artisan) => $artisan->add($command));
148+
$translator = App::make(Translator::class);
146149

147150
\Pest\Laravel\artisan('validate LongerThan5 --shortOption=alsoLonger')
148-
->expectsOutput('The short argument must not be greater than 5 characters.')
151+
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short argument', 'max' => 5]))
149152
->expectsQuestion('Please enter "shortArgument"', 'short')
150-
->expectsOutput('The short option must not be greater than 5 characters.')
153+
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short option', 'max' => 5]))
151154
->expectsQuestion('Please enter "shortOption"', 'small')
152155
->expectsOutput('short small')
153156
->assertSuccessful();

tests/ConsoleInputValidationTest.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use Illuminate\Console\Application as Artisan;
44
use Illuminate\Console\Command;
5+
use Illuminate\Support\Facades\App;
6+
use Illuminate\Translation\Translator;
57
use Thettler\LaravelConsoleToolkit\Attributes\Argument;
68
use Thettler\LaravelConsoleToolkit\Attributes\Option;
79
use Thettler\LaravelConsoleToolkit\Concerns\UsesConsoleToolkit;
@@ -30,15 +32,17 @@
3032

3133
public function handle()
3234
{
33-
$this->line($this->shortArgument . ' ' . $this->shortOption);
35+
$this->line($this->shortArgument.' '.$this->shortOption);
3436
}
3537
};
3638

3739
Artisan::starting(fn (Artisan $artisan) => $artisan->add($command));
3840

41+
$translator = App::make(Translator::class);
42+
3943
\Pest\Laravel\artisan('validate LongerThan5 --shortOption=alsoLonger')
40-
->expectsOutput('The short argument must not be greater than 5 characters.')
41-
->expectsOutput('The short option must not be greater than 5 characters.')
44+
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short argument', 'max' => 5]))
45+
->expectsOutput($translator->get('validation.max.string', ['attribute' => 'short option', 'max' => 5]))
4246
->doesntExpectOutput('LongerThan5 alsoLonger')
4347
->assertFailed();
4448
});
@@ -59,7 +63,7 @@ public function handle()
5963

6064
public function handle()
6165
{
62-
$this->line($this->A->name . ' ' . $this->O->value);
66+
$this->line($this->A->name.' '.$this->O->value);
6367
}
6468
};
6569

@@ -68,14 +72,14 @@ public function handle()
6872
\Pest\Laravel\artisan('validate notValid --O=notValid')
6973
->expectsOutput('The selected a is invalid.')
7074
->expectsOutput('Possible values for: A.')
71-
->expectsOutput(' - ' . Enum::A->name)
72-
->expectsOutput(' - ' . Enum::B->name)
73-
->expectsOutput(' - ' . Enum::C->name)
75+
->expectsOutput(' - '.Enum::A->name)
76+
->expectsOutput(' - '.Enum::B->name)
77+
->expectsOutput(' - '.Enum::C->name)
7478
->expectsOutput('The selected o is invalid.')
7579
->expectsOutput('Possible values for: O.')
76-
->expectsOutput(' - ' . StringEnum::A->value)
77-
->expectsOutput(' - ' . StringEnum::B->value)
78-
->expectsOutput(' - ' . StringEnum::C->value)
80+
->expectsOutput(' - '.StringEnum::A->value)
81+
->expectsOutput(' - '.StringEnum::B->value)
82+
->expectsOutput(' - '.StringEnum::C->value)
7983
->assertFailed();
8084
});
8185

@@ -105,7 +109,7 @@ public function handle()
105109

106110
public function handle()
107111
{
108-
$this->line($this->shortArgument . ' ' . $this->shortOption);
112+
$this->line($this->shortArgument.' '.$this->shortOption);
109113
}
110114
};
111115

0 commit comments

Comments
 (0)