Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/*
* This file is part of the ONGR package.
*
* (c) NFQ Technologies UAB <info@nfq.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ONGR\ElasticsearchBundle\Tests\Unit\DSL;
use ONGR\ElasticsearchBundle\DSL\FriendlyBuilderBag;
use ONGR\ElasticsearchBundle\DSL\FriendlyBuilderInterface;
class FriendlyBuilderBagTest extends \PHPUnit_Framework_TestCase
{
/**
* Tests if bag knows if he has a builder.
*/
public function testHas()
{
$bag = new FriendlyBuilderBag(
[
$this->getBuilder('foo'),
]
);
$this->assertTrue($bag->has('foo'));
}
/**
* Tests if bag can remove a builder.
*/
public function testRemove()
{
$bag = new FriendlyBuilderBag(
[
$this->getBuilder('foo'),
$this->getBuilder('baz'),
]
);
$bag->remove('foo');
$this->assertFalse($bag->has('foo'), 'Foo builder should not exist anymore.');
$this->assertTrue($bag->has('baz'), 'Baz builder should exist.');
}
/**
* Tests if bag can clear it's builders.
*/
public function testClear()
{
$bag = new FriendlyBuilderBag(
[
$this->getBuilder('foo'),
$this->getBuilder('baz'),
]
);
$bag->clear();
$this->assertEmpty($bag->all());
}
/**
* Tests if bag can get a builder.
*/
public function testGet()
{
$bag = new FriendlyBuilderBag(
[
$this->getBuilder('baz'),
]
);
$this->assertNotEmpty($bag->get('baz'));
}
/**
* Returns builder.
*
* @param string $name
*
* @return \PHPUnit_Framework_MockObject_MockObject|FriendlyBuilderInterface
*/
private function getBuilder($name)
{
$friendlyBuilderMock = $this->getMock('ONGR\ElasticsearchBundle\DSL\FriendlyBuilderInterface');
$friendlyBuilderMock
->expects($this->once())
->method('getName')
->will($this->returnValue($name));
$friendlyBuilderMock
->expects($this->any())
->method('toArray')
->will($this->returnValue([]));
return $friendlyBuilderMock;
}
}