Skip to content

Commit 260431f

Browse files
Merge pull request #78 from TheDragonCode/3.x
Fixed resolving file names
2 parents ba624f1 + 4e004eb commit 260431f

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

src/Helpers/Sorter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function byKeys(array $items): array
2222

2323
public function byRan(array $actions, array $completed): array
2424
{
25-
foreach ($this->byValues($actions) as $value) {
25+
foreach ($actions as $value) {
2626
if (! in_array($value, $completed, true)) {
2727
$completed[] = $value;
2828
}

src/Services/Migrator.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function runUp(string $filename, int $batch, Options $options): void
4646
{
4747
$path = $this->resolvePath($filename, $options->path);
4848
$action = $this->resolveAction($path);
49-
$name = $this->resolveActionName($filename);
49+
$name = $this->resolveActionName($path);
5050

5151
if ($this->allowAction($action, $name, $options)) {
5252
$this->hasAction($action, '__invoke')
@@ -63,7 +63,7 @@ public function runDown(string $filename, Options $options): void
6363
{
6464
$path = $this->resolvePath($filename, $options->path);
6565
$action = $this->resolveAction($path);
66-
$name = $this->resolveActionName($filename);
66+
$name = $this->resolveActionName($path);
6767

6868
if (! $this->hasAction($action, '__invoke') && $this->hasAction($action, 'down')) {
6969
$this->runAction($action, $name, 'down');
@@ -176,11 +176,11 @@ protected function resolveAction(string $path): Action
176176
throw new FileNotFoundException($path);
177177
}
178178

179-
protected function resolveActionName(string $filename): string
179+
protected function resolveActionName(string $path): string
180180
{
181-
return Str::of($filename)
182-
->ltrim('\\/')
183-
->replace('\\', '/')
181+
return Str::of(realpath($path))
182+
->after(realpath($this->config->path()) . DIRECTORY_SEPARATOR)
183+
->replace(['\\', '/'], '/')
184184
->before('.php')
185185
->toString();
186186
}

tests/Commands/MigrateTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ public function testPathAsFileWithExtension()
352352
$this->assertDatabaseCount($table, 1);
353353
$this->assertDatabaseCount($this->table, 1);
354354
$this->assertDatabaseMigrationHas($this->table, 'baz');
355+
356+
$this->assertSame('sub_path/2021_12_15_205804_baz', $this->table()->first()->action);
355357
}
356358

357359
public function testPathAsFileWithoutExtension()
@@ -372,6 +374,8 @@ public function testPathAsFileWithoutExtension()
372374
$this->assertDatabaseCount($table, 1);
373375
$this->assertDatabaseCount($this->table, 1);
374376
$this->assertDatabaseMigrationHas($this->table, 'baz');
377+
378+
$this->assertSame($path, $this->table()->first()->action);
375379
}
376380

377381
public function testPathAsDirectory()
@@ -392,6 +396,8 @@ public function testPathAsDirectory()
392396
$this->assertDatabaseCount($table, 1);
393397
$this->assertDatabaseCount($this->table, 1);
394398
$this->assertDatabaseMigrationHas($this->table, 'baz');
399+
400+
$this->assertSame('sub_path/2021_12_15_205804_baz', $this->table()->first()->action);
395401
}
396402

397403
public function testMigrationNotFound()

0 commit comments

Comments
 (0)