8000 [Validator] Completed test coverage and documentation of the Node cla… · symfony/symfony@2c65a28 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2c65a28

Browse files
committed
[Validator] Completed test coverage and documentation of the Node classes
1 parent 9c9e715 commit 2c65a28

File tree

5 files changed

+130
-9
lines changed

5 files changed

+130
-9
lines changed

src/Symfony/Component/Validator/Node/ClassNode.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
namespace Symfony\Component\Validator\Node;
1313

14+
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1415
use Symfony\Component\Validator\Mapping\ClassMetadataInterface;
1516

1617
/**
17-
* @since %%NextVersion%%
18+
* Represents an object and its class metadata in the validation graph.
19+
*
20+
* @since 2.5
1821
* @author Bernhard Schussek <bschussek@gmail.com>
1922
*/
2023
class ClassNode extends Node
@@ -24,19 +27,34 @@ class ClassNode extends Node
2427
*/
2528
public $metadata;
2629

27-
public function __construct($value, ClassMetadataInterface $metadata, $propertyPath, array $groups, array $cascadedGroups)
30+
/**
31+
* Creates a new class node.
32+
*
33+
* @param object $object The validated object
34+
* @param ClassMetadataInterface $metadata The class metadata of that
35+
* object
36+
* @param string $propertyPath The property path leading
37+
* to this node
38+
* @param string[] $groups The groups in which this
39+
* node should be validated
40+
* @param string[] $cascadedGroups The groups in which
41+
* cascaded objects should be
42+
* validated
43+
*
44+
* @throws UnexpectedTypeException If the given value is not an object
45+
*/
46+
public function __construct($object, ClassMetadataInterface $metadata, $propertyPath, array $groups, array $cascadedGroups)
2847
{
29-
if (!is_object($value)) {
30-
// error
48+
if (!is_object($object)) {
49+
throw new UnexpectedTypeException($object, 'object');
3150
}
3251

3352
parent::__construct(
34-
$value,
53+
$object,
3554
$metadata,
3655
$propertyPath,
3756
$groups,
3857
$cascadedGroups
3958
);
4059
}
41-
4260
}

src/Symfony/Component/Validator/Node/GenericNode.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
namespace Symfony\Component\Validator\Node;
1313

1414
/**
15-
* @since %%NextVersion%%
15+
* Represents a value that has neither class metadata nor property metadata
16+
* attached to it.
17+
*
18+
* Together with {@link \Symfony\Component\Validator\Mapping\GenericMetadata},
19+
* this node type can be used to validate a value against some given
20+
* constraints.
21+
*
22+
* @since 2.5
1623
* @author Bernhard Schussek <bschussek@gmail.com>
1724
*/
1825
class GenericNode extends Node

src/Symfony/Component/Validator/Node/Node.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,60 @@
1414
use Symfony\Component\Validator\Mapping\MetadataInterface;
1515

1616
/**
17-
* @since %%NextVersion%%
17+
* A node in the validated graph.
18+
*
19+
* @since 2.5
1820
* @author Bernhard Schussek <bschussek@gmail.com>
1921
*/
2022
abstract class Node
2123
{
24+
/**
25+
* The validated value.
26+
*
27+
* @var mixed
28+
*/
2229
public $value;
2330

31+
/**
32+
* The metadata specifying how the value should be validated.
33+
*
34+
* @var MetadataInterface
35+
*/
2436
public $metadata;
2537

38+
/**
39+
* The property path leading to this node.
40+
*
41+
* @var string
42+
*/
2643
public $propertyPath;
2744

45+
/**
46+
* The groups in which the value should be validated.
47+
*
48+
* @var string[]
49+
*/
2850
public $groups;
2951

52+
/**
53+
* The groups in which cascaded values should be validated.
54+
*
55+
* @var string[]
56+
*/
3057
public $cascadedGroups;
3158

59+
/**
60+
* Creates a new property node.
61+
*
62+
* @param mixed $value The property value
63+
* @param MetadataInterface $metadata The property's metadata
64+
* @param string $propertyPath The property path leading to
65+
* this node
66+
* @param string[] $groups The groups in which this node
67+
* should be validated
68+
* @param string[] $cascadedGroups The groups in which cascaded
69+
* objects should be validated
70+
*/
3271
public function __construct($value, MetadataInterface $metadata, $propertyPath, array $groups, array $cascadedGroups)
3372
{
3473
$this->value = $value;

src/Symfony/Component/Validator/Node/PropertyNode.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,20 @@
1414
use Symfony\Component\Validator\Mapping\PropertyMetadataInterface;
1515

1616
/**
17-
* @since %%NextVersion%%
17+
* Represents the value of a property and its associated metadata.
18+
*
19+
* If the property contains an object and should be cascaded, a new
20+
* {@link ClassNode} instance will be created for that object.
21+
*
22+
* Example:
23+
*
24+
* (Article:ClassNode)
25+
* \
26+
* (author:PropertyNode)
27+
* \
28+
* (Author:ClassNode)
29+
*
30+
* @since 2.5
1831
* @author Bernhard Schussek <bschussek@gmail.com>
1932
*/
2033
class PropertyNode extends Node
@@ -24,6 +37,19 @@ class PropertyNode extends Node
2437
*/
2538
public $metadata;
2639

40+
/**
41+
* Creates a new property node.
42+
*
43+
* @param mixed $value The property value
44+
* @param PropertyMetadataInterface $metadata The property's metadata
45+
* @param string $propertyPath The property path leading
46+
* to this node
47+
* @param string[] $groups The groups in which this
48+
* node should be validated
49+
* @param string[] $cascadedGroups The groups in which
50+
* cascaded objects should
51+
* be validated
52+
*/
2753
public function __construct($value, PropertyMetadataInterface $metadata, $propertyPath, array $groups, array $cascadedGroups)
2854
{
2955
parent::__construct(
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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\Node;
13+
14+
use Symfony\Component\Validator\Node\ClassNode;
15+
16+
/**
17+
* @since 2.5
18+
* @author Bernhard Schussek <bschussek@gmail.com>
19+
*/
20+
class ClassNodeTest extends \PHPUnit_Framework_TestCase
21+
{
22+
/**
23+
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
24+
*/
25+
public function testConstructorExpectsObject()
26+
{
27+
$metadata = $this->getMock('Symfony\Component\Validator\Mapping\ClassMetadataInterface');
28+
29+
new ClassNode('foobar', $metadata, '', array(), array());
30+
}
31+
}

0 commit comments

Comments
 (0)
0