8000 [DI][FrameworkBundle] Add PSR-11 "ContainerBag" to access parameters as-a-service by nicolas-grekas · Pull Request #25288 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI][FrameworkBundle] Add PSR-11 "ContainerBag" to access parameters as-a-service #25288

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

Merged
merged 2 commits into from
Dec 8, 2017
Merged
Changes from 1 commit
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
Prev Previous commit
Add tests on the ContainerBag
  • Loading branch information
sroze authored and nicolas-grekas committed Dec 4, 2017
commit 561cd7e317e44bf106d5c2aee8eaa8ed3fa5a3aa
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;

use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;

class ContainerBagTest extends TestCase
{
/** @var ParameterBag */
private $parameterBag;
/** @var ContainerBag */
private $containerBag;

public function setUp()
{
$this->parameterBag = new ParameterBag(array('foo' => 'value'));
$this->containerBag = new ContainerBag(new Container($this->parameterBag));
}

public function testGetAllParameters()
{
$this->assertSame(array('foo' => 'value'), $this->containerBag->all());
}

public function testHasAParameter()
{
$this->assertTrue($this->containerBag->has('foo'));
$this->assertFalse($this->containerBag->has('bar'));
}

public function testGetParameter()
{
$this->assertSame('value', $this->containerBag->get('foo'));
}

/**
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
*/
public function testGetParameterNotFound()
{
$this->containerBag->get('bar');
}

public function testInstanceOf()
{
$this->assertInstanceOf(FrozenParameterBag::class, $this->containerBag);
$this->assertInstanceOf(ContainerBagInterface::class, $this->containerBag);
$this->assertInstanceOf(ContainerInterface::class, $this->containerBag);
}
}
0