Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename method ArrayDefinition::setReferenceContainer() to withReferenceContainer() and make him immutable #38

Merged
merged 2 commits into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- New #37: Make method `DefinitionValidator::validateArrayDefinition()` public (vjik)
- Chg #37: Remove method `ParameterDefinition::isBuiltin()` (vjik)
- Chg #30: Rename method `ArrayDefinition::setReferenceContainer()` to `withReferenceContainer()` and make it
immutable (vjik)

## 1.0.2 April 01, 2022

Expand Down
6 changes: 4 additions & 2 deletions src/ArrayDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ private function __construct(string $class, array $constructorArguments, array $
/**
* @param ContainerInterface|null $referenceContainer Container to resolve references with.
*/
public function setReferenceContainer(?ContainerInterface $referenceContainer): void
public function withReferenceContainer(?ContainerInterface $referenceContainer): self
{
$this->referenceContainer = $referenceContainer;
$new = clone $this;
$new->referenceContainer = $referenceContainer;
return $new;
}

/**
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/ArrayDefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,12 @@ public function testReferenceContainer(): void
'class' => Car::class,
'setColor()' => [Reference::to(ColorInterface::class)],
]);
$definition->setReferenceContainer($referenceContainer);
$newDefinition = $definition->withReferenceContainer($referenceContainer);

/** @var Car $object */
$object = $definition->resolve($container);
$object = $newDefinition->resolve($container);

$this->assertNotSame($definition, $newDefinition);
$this->assertInstanceOf(Car::class, $object);
$this->assertInstanceOf(EngineMarkOne::class, $object->getEngine());
}
Expand Down