|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* test for constraint builder calling |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace Graviton\SchemaBundle\Tests\ConstraintBuilder; |
|
7
|
|
|
|
|
8
|
|
|
use Graviton\SchemaBundle\Constraint\ConstraintBuilder; |
|
9
|
|
|
use Graviton\SchemaBundle\Document\Schema; |
|
10
|
|
|
use Graviton\SchemaBundle\Tests\ConstraintBuilder\Builder\DummyBuilderA; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
|
14
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
|
15
|
|
|
* @link http://swisscom.ch |
|
16
|
|
|
*/ |
|
17
|
|
|
class ConstraintBuilderTest extends \PHPUnit_Framework_TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* test the builder handling |
|
22
|
|
|
* |
|
23
|
|
|
* @return void |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testBuilderHandling() |
|
26
|
|
|
{ |
|
27
|
|
|
$sut = new ConstraintBuilder(); |
|
28
|
|
|
$dummyBuilder = new DummyBuilderA(); |
|
29
|
|
|
$sut->addConstraintBuilder($dummyBuilder); |
|
30
|
|
|
|
|
31
|
|
|
$constraints = []; |
|
32
|
|
|
$constraints[0] = new \stdClass(); |
|
33
|
|
|
$constraints[0]->name = 'DummyA'; |
|
34
|
|
|
$constraints[0]->options = []; |
|
35
|
|
|
$constraints[0]->options[0] = new \stdClass(); |
|
36
|
|
|
$constraints[0]->options[0]->name = 'someOption'; |
|
37
|
|
|
$constraints[0]->options[0]->value = 'someValue'; |
|
38
|
|
|
|
|
39
|
|
|
$property = new Schema(); |
|
40
|
|
|
$modelMock = $this->getMockBuilder('Graviton\RestBundle\Model\DocumentModel') |
|
41
|
|
|
->disableOriginalConstructor() |
|
42
|
|
|
->getMock(); |
|
43
|
|
|
$modelMock |
|
44
|
|
|
->expects($this->once()) |
|
45
|
|
|
->method('getConstraints') |
|
46
|
|
|
->with($this->equalTo('hans')) |
|
47
|
|
|
->will($this->returnValue($constraints)); |
|
48
|
|
|
|
|
49
|
|
|
$changedProperty = $sut->addConstraints('hans', $property, $modelMock); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertEquals('THIS WAS SET BY DUMMY-A', $changedProperty->getTitle()); |
|
52
|
|
|
$this->assertEquals($constraints[0]->options, $dummyBuilder->options); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|