|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Cubiche package. |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright (c) Cubiche |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace Cubiche\Core\Selector\Tests\Units; |
|
11
|
|
|
|
|
12
|
|
|
use Cubiche\Core\Selector\Key; |
|
13
|
|
|
use Cubiche\Core\Selector\Property; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Composite Tests Class. |
|
17
|
|
|
* |
|
18
|
|
|
* @author Ivannis Suárez Jerez <[email protected]> |
|
19
|
|
|
*/ |
|
20
|
|
|
class CompositeTests extends SelectorTestCase |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
public function newDefaultTestedInstance() |
|
26
|
|
|
{ |
|
27
|
|
|
return $this->newTestedInstance(new Key('foo'), new Key('bar')); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Test apply. |
|
32
|
|
|
*/ |
|
33
|
|
|
public function testApply() |
|
34
|
|
|
{ |
|
35
|
|
|
$this |
|
36
|
|
|
/* @var \Cubiche\Core\Selector\Composite $composite */ |
|
37
|
|
|
->given($composite = $this->newDefaultTestedInstance()) |
|
38
|
|
|
->then() |
|
39
|
|
|
->string($composite->apply(array('foo' => array('bar' => 'baz')))) |
|
40
|
|
|
->isEqualTo('baz') |
|
41
|
|
|
->variable($composite->apply(null)) |
|
42
|
|
|
->isNull() |
|
43
|
|
|
->variable($composite->apply(array('foo'))) |
|
44
|
|
|
->isNull() |
|
45
|
|
|
; |
|
46
|
|
|
|
|
47
|
|
|
$this |
|
48
|
|
|
->given($composite = $this->newTestedInstance(new Key('foo'), new Property('bar'))) |
|
49
|
|
|
->then() |
|
50
|
|
|
->string($composite->apply(array('foo' => (object) array('bar' => 'baz')))) |
|
51
|
|
|
->isEqualTo('baz') |
|
52
|
|
|
->exception(function () use ($composite) { |
|
53
|
|
|
$composite->apply(array('foo' => null)); |
|
54
|
|
|
})->isInstanceOf(\RuntimeException::class) |
|
55
|
|
|
->exception(function () use ($composite) { |
|
56
|
|
|
$composite->apply(array('foo' => (object) array())); |
|
57
|
|
|
})->isInstanceOf(\RuntimeException::class) |
|
58
|
|
|
; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Test value/apply selector. |
|
63
|
|
|
*/ |
|
64
|
|
|
public function testValueApplySelector() |
|
65
|
|
|
{ |
|
66
|
|
|
$this |
|
67
|
|
|
->given($composite = $this->newDefaultTestedInstance()) |
|
68
|
|
|
->then() |
|
69
|
|
|
->object($composite->valueSelector()) |
|
70
|
|
|
->isInstanceOf(Key::class) |
|
71
|
|
|
->string($composite->valueSelector()->name()) |
|
72
|
|
|
->isEqualTo('foo') |
|
73
|
|
|
->object($composite->applySelector()) |
|
74
|
|
|
->isInstanceOf(Key::class) |
|
75
|
|
|
->string($composite->applySelector()->name()) |
|
76
|
|
|
->isEqualTo('bar') |
|
77
|
|
|
; |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|