Skip to content

Commit

Permalink
Merge pull request #152 from jenssegers/set-concrete
Browse files Browse the repository at this point in the history
Add getConcrete and setConcrete on the definition
  • Loading branch information
philipobenito committed Aug 13, 2018
2 parents 68c148e + a446b14 commit 72ce2d7
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Definition/Definition.php
Expand Up @@ -116,6 +116,24 @@ public function isShared() : bool
return $this->shared;
}

/**
* {@inheritdoc}
*/
public function getConcrete()
{
return $this->concrete;
}

/**
* {@inheritdoc}
*/
public function setConcrete($concrete): DefinitionInterface
{
$this->concrete = $concrete;

return $this;
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions src/Definition/DefinitionInterface.php
Expand Up @@ -54,6 +54,22 @@ public function setShared(bool $shared) : DefinitionInterface;
*/
public function isShared() : bool;

/**
* Get the concrete of the definition.
*
* @return mixed
*/
public function getConcrete();

/**
* Set the concrete of the definition.
*
* @param mixed $concrete
*
* @return DefinitionInterface
*/
public function setConcrete($concrete): DefinitionInterface;

/**
* Add an argument to be injected.
*
Expand Down
24 changes: 24 additions & 0 deletions tests/Definition/DefinitionTest.php
Expand Up @@ -167,4 +167,28 @@ public function testDefinitionCanAddTags()
$this->assertTrue($definition->hasTag('tag2'));
$this->assertFalse($definition->hasTag('tag3'));
}

/**
* Assert that the definition returns the concrete.
*/
public function testDefinitionCanGetConcrete()
{
$concrete = new ClassName(Foo::class);
$definition = new Definition('callable', $concrete);

$this->assertSame($concrete, $definition->getConcrete());
}

/**
* Assert that the definition set the concrete.
*/
public function testDefinitionCanSetConcrete()
{
$definition = new Definition('callable', null);

$concrete = new ClassName(Foo::class);
$definition->setConcrete($concrete);

$this->assertSame($concrete, $definition->getConcrete());
}
}

0 comments on commit 72ce2d7

Please sign in to comment.