Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 561cd7e

Browse files
srozenicolas-grekas
authored andcommitted
Add tests on the ContainerBag
1 parent 0e18d3e commit 561cd7e

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\DependencyInjection\Tests\ParameterBag;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Psr\Container\ContainerInterface;
16+
use Symfony\Component\DependencyInjection\Container;
17+
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBag;
18+
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
19+
use Symfony\Component\DependencyInjection\ParameterBag\FrozenParameterBag;
20+
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
21+
22+
class ContainerBagTest extends TestCase
23+
{
24+
/** @var ParameterBag */
25+
private $parameterBag;
26+
/** @var ContainerBag */
27+
private $containerBag;
28+
29+
public function setUp()
30+
{
31+
$this->parameterBag = new ParameterBag(array('foo' => 'value'));
32+
$this->containerBag = new ContainerBag(new Container($this->parameterBag));
33+
}
34+
35+
public function testGetAllParameters()
36+
{
37+
$this->assertSame(array('foo' => 'value'), $this->containerBag->all());
38+
}
39+
40+
public function testHasAParameter()
41+
{
42+
$this->assertTrue($this->containerBag->has('foo'));
43+
$this->assertFalse($this->containerBag->has('bar'));
44+
}
45+
46+
public function testGetParameter()
47+
{
48+
$this->assertSame('value', $this->containerBag->get('foo'));
49+
}
50+
51+
/**
52+
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
53+
*/
54+
public function testGetParameterNotFound()
55+
{
56+
$this->containerBag->get('bar');
57+
}
58+
59+
public function testInstanceOf()
60+
{
61+
$this->assertInstanceOf(FrozenParameterBag::class, $this->containerBag);
62+
$this->assertInstanceOf(ContainerBagInterface::class, $this->containerBag);
63+
$this->assertInstanceOf(ContainerInterface::class, $this->containerBag);
64+
}
65+
}

0 commit comments

Comments
 (0)