Skip to content

Commit ba624f1

Browse files
Merge pull request #77 from TheDragonCode/3.x
Fixed status sorting
2 parents ebe3b1c + 4ce6cb0 commit ba624f1

File tree

5 files changed

+73
-22
lines changed

5 files changed

+73
-22
lines changed

src/Helpers/Sorter.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,17 @@ public function byKeys(array $items): array
2020
return Arr::ksort($items, $this->callback());
2121
}
2222

23+
public function byRan(array $actions, array $completed): array
24+
{
25+
foreach ($this->byValues($actions) as $value) {
26+
if (! in_array($value, $completed, true)) {
27+
$completed[] = $value;
28+
}
29+
}
30+
31+
return $completed;
32+
}
33+
2334
protected function callback(): Closure
2435
{
2536
return function (string $a, string $b): int {

src/Processors/Status.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ protected function showCaption(): void
4141

4242
protected function showStatus(array $actions, array $completed): void
4343
{
44-
foreach ($actions as $action) {
44+
foreach ($this->merge($actions, array_keys($completed)) as $action) {
4545
$status = $this->getStatusFor($completed, $action);
4646

4747
$this->notification->twoColumn($action, $status);
4848
}
4949
}
5050

51+
protected function merge(array $actions, array $completed): array
52+
{
53+
return $this->sorter->byRan($actions, $completed);
54+
}
55+
5156
protected function getData(): array
5257
{
5358
$files = $this->getFiles($this->options->path);

tests/Commands/MigrateTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,6 @@ public function testSorting(): void
547547
$files[] = date('Y_m_d_His_') . 'test6';
548548
$this->artisan(Names::MAKE, ['name' => 'test6'])->assertExitCode(0);
549549

550-
$this->assertDatabaseCount($this->table, 0);
551550
$this->artisan(Names::MIGRATE)->assertExitCode(0);
552551
$this->assertDatabaseCount($this->table, 6);
553552

tests/Helpers/SorterTest.php

Lines changed: 49 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ public function testByValues(): void
1313
{
1414
$expected = [
1515
'2022_10_13_013321_test1',
16-
'foo/2022_10_13_013321_test2',
17-
'bar/2022_10_13_013321_test3',
18-
'foo/2022_10_13_013321_test4',
19-
'bar/2022_10_13_013321_test5',
20-
'2022_10_13_013321_test6',
16+
'foo/2022_10_13_013322_test2',
17+
'bar/2022_10_13_013323_test3',
18+
'foo/2022_10_13_013324_test4',
19+
'bar/2022_10_13_013325_test5',
20+
'2022_10_13_013326_test6',
2121
];
2222

2323
$values = [
2424
'2022_10_13_013321_test1',
25-
'2022_10_13_013321_test6',
26-
'bar/2022_10_13_013321_test3',
27-
'bar/2022_10_13_013321_test5',
28-
'foo/2022_10_13_013321_test2',
29-
'foo/2022_10_13_013321_test4',
25+
'2022_10_13_013326_test6',
26+
'bar/2022_10_13_013323_test3',
27+
'bar/2022_10_13_013325_test5',
28+
'foo/2022_10_13_013322_test2',
29+
'foo/2022_10_13_013324_test4',
3030
];
3131

3232
$this->assertSame($expected, $this->sorter()->byValues($values));
@@ -36,25 +36,54 @@ public function testByKeys(): void
3636
{
3737
$expected = [
3838
'2022_10_13_013321_test1' => 1,
39-
'foo/2022_10_13_013321_test2' => 2,
40-
'bar/2022_10_13_013321_test3' => 3,
41-
'foo/2022_10_13_013321_test4' => 4,
42-
'bar/2022_10_13_013321_test5' => 5,
43-
'2022_10_13_013321_test6' => 6,
39+
'foo/2022_10_13_013322_test2' => 2,
40+
'bar/2022_10_13_013323_test3' => 3,
41+
'foo/2022_10_13_013324_test4' => 4,
42+
'bar/2022_10_13_013325_test5' => 5,
43+
'2022_10_13_013326_test6' => 6,
4444
];
4545

4646
$values = [
4747
'2022_10_13_013321_test1' => 1,
48-
'2022_10_13_013321_test6' => 6,
49-
'bar/2022_10_13_013321_test3' => 3,
50-
'bar/2022_10_13_013321_test5' => 5,
51-
'foo/2022_10_13_013321_test2' => 2,
52-
'foo/2022_10_13_013321_test4' => 4,
48+
'2022_10_13_013326_test6' => 6,
49+
'bar/2022_10_13_013323_test3' => 3,
50+
'bar/2022_10_13_013325_test5' => 5,
51+
'foo/2022_10_13_013322_test2' => 2,
52+
'foo/2022_10_13_013324_test4' => 4,
5353
];
5454

5555
$this->assertSame($expected, $this->sorter()->byKeys($values));
5656
}
5757

58+
public function testByRan(): void
59+
{
60+
$actions = [
61+
'2022_10_13_013321_test1',
62+
'foo/2022_10_13_013322_test2',
63+
'bar/2022_10_13_013323_test3',
64+
'foo/2022_10_13_013324_test4',
65+
'bar/2022_10_13_013325_test5',
66+
'2022_10_13_013326_test6',
67+
];
68+
69+
$completed = [
70+
'2022_10_13_013321_test1',
71+
'foo/2022_10_13_013324_test4',
72+
'bar/2022_10_13_013325_test5',
73+
];
74+
75+
$expected = [
76+
'2022_10_13_013321_test1',
77+
'foo/2022_10_13_013324_test4',
78+
'bar/2022_10_13_013325_test5',
79+
'foo/2022_10_13_013322_test2',
80+
'bar/2022_10_13_013323_test3',
81+
'2022_10_13_013326_test6',
82+
];
83+
84+
$this->assertSame($expected, $this->sorter()->byRan($actions, $completed));
85+
}
86+
5887
protected function sorter(): Sorter
5988
{
6089
return new Sorter();

tests/TestCase.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
namespace Tests;
44

55
use DragonCode\LaravelActions\Concerns\Anonymous;
6+
use DragonCode\LaravelActions\Repositories\ActionRepository;
67
use DragonCode\LaravelActions\ServiceProvider;
8+
use Illuminate\Container\Container;
79
use Illuminate\Database\Query\Builder;
810
use Illuminate\Foundation\Testing\RefreshDatabase;
911
use Illuminate\Support\Facades\DB;
@@ -44,4 +46,9 @@ protected function table(): Builder
4446
{
4547
return DB::table($this->table);
4648
}
49+
50+
protected function repository(): ActionRepository
51+
{
52+
return Container::getInstance()->make(ActionRepository::class);
53+
}
4754
}

0 commit comments

Comments
 (0)