Skip to content

Commit

Permalink
Added failing test to show class issue
Browse files Browse the repository at this point in the history
  • Loading branch information
aschempp committed Jun 11, 2021
1 parent 0d7f8d9 commit 5b9706c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions core-bundle/tests/Routing/ResponseContext/ResponseContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Contao\CoreBundle\Routing\ResponseContext\HtmlHeadBag\HtmlHeadBag;
use Contao\CoreBundle\Routing\ResponseContext\ResponseContext;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\HeaderBag;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;

Expand Down Expand Up @@ -44,6 +46,25 @@ public function testLazyServices(): void
$this->assertInstanceOf(HtmlHeadBag::class, $context->get(HtmlHeadBag::class));
}

public function testLazyServicesAreNotDuplicated(): void
{
$context = new ResponseContext();

$this->assertFalse($context->has(HtmlHeadBag::class));

$context->addLazy(ResponseHeaderBag::class, static function () { return new ResponseHeaderBag(); });

$this->assertTrue($context->has(ResponseHeaderBag::class));
$this->assertTrue($context->has(HeaderBag::class));

$original = $context->get(ResponseHeaderBag::class);
$parent = $context->get(HeaderBag::class);

$this->assertInstanceOf(ResponseHeaderBag::class, $original);
$this->assertInstanceOf(ResponseHeaderBag::class, $parent);
$this->assertSame($original, $parent);
}

public function testGettingANonExistentServiceThrows(): void
{
$this->expectException(\InvalidArgumentException::class);
Expand Down

0 comments on commit 5b9706c

Please sign in to comment.