Skip to content

Commit

Permalink
Review changes from PR
Browse files Browse the repository at this point in the history
  • Loading branch information
philipobenito committed Nov 10, 2024
1 parent dcfc926 commit b4dbbf0
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 27 deletions.
13 changes: 11 additions & 2 deletions src/Definition/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Definition implements ArgumentResolverInterface, DefinitionInterface
*/
public function __construct(string $id, $concrete = null)
{
$id = Util::normalizeAlias($id);
$id = static::normaliseAlias($id);

$concrete = $concrete ?? $id;
$this->alias = $id;
Expand All @@ -87,7 +87,7 @@ public function hasTag(string $tag): bool

public function setAlias(string $id): DefinitionInterface
{
$id = Util::normalizeAlias($id);
$id = static::normaliseAlias($id);

$this->alias = $id;
return $this;
Expand Down Expand Up @@ -239,4 +239,13 @@ protected function invokeMethods(object $instance): object

return $instance;
}

public static function normaliseAlias(string $alias): string
{
if (strpos($alias, '\\') === 0) {
return substr($alias, 1);
}

return $alias;
}
}
4 changes: 2 additions & 2 deletions src/Definition/DefinitionAggregate.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function addShared(string $id, $definition): DefinitionInterface

public function has(string $id): bool
{
$id = Util::normalizeAlias($id);
$id = Definition::normaliseAlias($id);

foreach ($this->getIterator() as $definition) {
if ($id === $definition->getAlias()) {
Expand All @@ -67,7 +67,7 @@ public function hasTag(string $tag): bool

public function getDefinition(string $id): DefinitionInterface
{
$id = Util::normalizeAlias($id);
$id = Definition::normaliseAlias($id);

foreach ($this->getIterator() as $definition) {
if ($id === $definition->getAlias()) {
Expand Down
17 changes: 0 additions & 17 deletions src/Definition/Util.php

This file was deleted.

40 changes: 34 additions & 6 deletions tests/Definition/DefinitionAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ public function testAggregateThrowsExceptionWhenCannotResolve(): void
$aggregate->resolveNew('alias');
}

public function testDefinitionPreceedingSlash(): void
public function testDefinitionPrecedingSlash(): void
{
$container = $this->getMockBuilder(Container::class)->getMock();
$aggregate = new DefinitionAggregate();
$container = $this->getMockBuilder(Container::class)->getMock();
$aggregate = new DefinitionAggregate();
$aggregate->setContainer($container);

$some_class = "\\League\\Container\\Test\\Asset\\Foo";
Expand All @@ -243,10 +243,10 @@ public function testDefinitionPreceedingSlash(): void
self::assertInstanceOf(Definition::class, $definition);
}

public function testGetPreceedingSlash(): void
public function testGetPrecedingSlash(): void
{
$container = $this->getMockBuilder(Container::class)->getMock();
$aggregate = new DefinitionAggregate();
$container = $this->getMockBuilder(Container::class)->getMock();
$aggregate = new DefinitionAggregate();
$aggregate->setContainer($container);

$some_class = Foo::class;
Expand All @@ -256,4 +256,32 @@ public function testGetPreceedingSlash(): void

self::assertInstanceOf(Definition::class, $definition);
}

public function testDefinitionPrecedingSlashSingularQuotes(): void
{
$container = $this->getMockBuilder(Container::class)->getMock();
$aggregate = new DefinitionAggregate();
$aggregate->setContainer($container);

$some_class = '\\League\\Container\\Test\\Asset\\Foo';
$aggregate->add($some_class, null);

$definition = $aggregate->getDefinition(Foo::class);

self::assertInstanceOf(Definition::class, $definition);
}

public function testGetPrecedingSlashSingularQuote(): void
{
$container = $this->getMockBuilder(Container::class)->getMock();
$aggregate = new DefinitionAggregate();
$aggregate->setContainer($container);

$some_class = Foo::class;
$aggregate->add($some_class, null);

$definition = $aggregate->getDefinition('\\League\\Container\\Test\\Asset\\Foo');

self::assertInstanceOf(Definition::class, $definition);
}
}

0 comments on commit b4dbbf0

Please sign in to comment.