Skip to content

Commit f9df5de

Browse files
authored
Make relativeClassName return class name relative to models namespace (#491)
1 parent 6863277 commit f9df5de

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/Tracer.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,6 @@ private function translateColumns(array $columns)
244244
private function relativeClassName($model)
245245
{
246246
$name = Blueprint::relativeNamespace(get_class($model));
247-
if (config('blueprint.models_namespace')) {
248-
return $name;
249-
}
250247

251248
return ltrim(str_replace(config('blueprint.models_namespace'), '', $name), '\\');
252249
}

tests/Feature/Commands/TraceCommandTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ public function it_shows_the_number_of_traced_models()
4949
}
5050

5151
/** @test */
52+
public function relative_class_name_removes_models_namespace()
53+
{
54+
$this->requireFixture('models/comment.php');
55+
$this->requireFixture('models/custom-models-namespace.php');
56+
57+
$method = new \ReflectionMethod(Tracer::class, 'relativeClassName');
58+
$method->setAccessible(true);
59+
60+
// App namespace
61+
config(['blueprint.models_namespace' => '']);
62+
63+
$this->assertEquals($method->invoke(new Tracer(), app('App\Comment')), 'Comment');
64+
$this->assertEquals($method->invoke(new Tracer(), app('App\Models\Tag')), 'Models\Tag');
65+
66+
// Models namespace
67+
config(['blueprint.models_namespace' => 'Models']);
68+
69+
$this->assertEquals($method->invoke(new Tracer(), app('App\Comment')), 'Comment');
70+
$this->assertEquals($method->invoke(new Tracer(), app('App\Models\Tag')), 'Tag');
71+
}
72+
5273
public function it_passes_the_command_path_to_tracer()
5374
{
5475
$this->filesystem->shouldReceive('exists')

tests/TestCase.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public function fixture(string $path)
3838
return file_get_contents(__DIR__ . '/' . 'fixtures' . '/' . ltrim($path, '/'));
3939
}
4040

41+
public function requireFixture(string $path)
42+
{
43+
require_once __DIR__ . '/' . 'fixtures' . '/' . ltrim($path, '/');
44+
}
45+
4146
public function stub(string $path)
4247
{
4348
return file_get_contents(__DIR__ . '/../' . 'stubs' . '/' . ltrim($path, '/'));

0 commit comments

Comments
 (0)