Skip to content

Commit 499b2bb

Browse files
committed
[Validator] Completed test coverage of ExecutionContext
1 parent adc1437 commit 499b2bb

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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\Validator\Tests\Context;
13+
14+
use Symfony\Component\Validator\Context\ExecutionContext;
15+
use Symfony\Component\Validator\Mapping\AdHocMetadata;
16+
use Symfony\Component\Validator\Mapping\ClassMetadata;
17+
use Symfony\Component\Validator\Node\ClassNode;
18+
use Symfony\Component\Validator\Node\ValueNode;
19+
20+
/**
21+
* @since 2.5
22+
* @author Bernhard Schussek <[email protected]>
23+
*/
24+
class ExecutionContextTest extends \PHPUnit_Framework_TestCase
25+
{
26+
const ROOT = '__ROOT__';
27+
28+
const TRANSLATION_DOMAIN = '__TRANSLATION_DOMAIN__';
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $validator;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $groupManager;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $translator;
44+
45+
/**
46+
* @var ExecutionContext
47+
*/
48+
private $context;
49+
50+
protected function setUp()
51+
{
52+
$this->validator = $this->getMock('Symfony\Component\Validator\Validator\ValidatorInterface');
53+
$this->groupManager = $this->getMock('Symfony\Component\Validator\Group\GroupManagerInterface');
54+
$this->translator = $this->getMock('Symfony\Component\Translation\TranslatorInterface');
55+
56+
$this->context = new ExecutionContext(
57+
self::ROOT,
58+
$this->validator,
59+
$this->groupManager,
60+
$this->translator,
61+
self::TRANSLATION_DOMAIN
62+
);
63+
}
64+
65+
public function testPushAndPop()
66+
{
67+
$metadata = $this->getMock('Symfony\Component\Validator\Mapping\MetadataInterface');
68+
$node = new ValueNode('value', $metadata, '', array(), array());
69+
70+
$this->context->pushNode($node);
71+
72+
$this->assertSame('value', $this->context->getValue());
73+
// the other methods are covered in AbstractValidatorTest
74+
75+
$this->assertSame($node, $this->context->popNode());
76+
77+
$this->assertNull($this->context->getValue());
78+
}
79+
80+
public function testPushTwiceAndPop()
81+
{
82+
$metadata1 = $this->getMock('Symfony\Component\Validator\Mapping\MetadataInterface');
83+
$node1 = new ValueNode('value', $metadata1, '', array(), array());
84+
$metadata2 = $this->getMock('Symfony\Component\Validator\Mapping\MetadataInterface');
85+
$node2 = new ValueNode('other value', $metadata2, '', array(), array());
86+
87+
$this->context->pushNode($node1);
88+
$this->context->pushNode($node2);
89+
90+
$this->assertSame($node2, $this->context->popNode());
91+
92+
$this->assertSame('value', $this->context->getValue());
93+
}
94+
95+
public function testPopWithoutPush()
96+
{
97+
$this->assertNull($this->context->popNode());
98+
}
99+
100+
public function testGetGroup()
101+
{
102+
$this->groupManager->expects($this->once())
103+
->method('getCurrentGroup')
104+
->will($this->returnValue('Current Group'));
105+
106+
$this->assertSame('Current Group', $this->context->getGroup());
107+
}
108+
}

0 commit comments

Comments
 (0)