Skip to content

Commit

Permalink
bug #150 make entity, related class without namespace (LeJeanbono)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

make entity, related class without namespace

For #148

Commits
-------

5e5e5e6 make entity, related class without namespace
  • Loading branch information
weaverryan committed Apr 11, 2018
2 parents afbf1c0 + 5e5e5e6 commit 253cee4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ public static function asEventMethod(string $eventName): string

public static function getShortClassName(string $fullClassName): string
{
return substr($fullClassName, strrpos($fullClassName, '\\') + 1);
if (!empty(self::getNamespace($fullClassName))) {
return substr($fullClassName, strrpos($fullClassName, '\\') + 1);
} else {
return $fullClassName;
}
}

public static function getNamespace(string $fullClassName): string
Expand Down
14 changes: 14 additions & 0 deletions tests/StrTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,18 @@ public function getAsCamelCaseTests()

yield ['foo_bar.baz\\pizza', 'FooBarBazPizza'];
}

/**
* @dataProvider getShortClassNameCaseTests
*/
public function testShortClassName(string $original, string $expected)
{
$this->assertSame($expected, Str::getShortClassName($original));
}

public function getShortClassNameCaseTests()
{
yield ['App\\Entity\\Foo', 'Foo'];
yield ['Foo', 'Foo'];
}
}

0 comments on commit 253cee4

Please sign in to comment.