1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LightSaml\Tests\Builder\Action; |
4
|
|
|
|
5
|
|
|
use LightSaml\Action\ActionInterface; |
6
|
|
|
use LightSaml\Action\CompositeAction; |
7
|
|
|
use LightSaml\Builder\Action\CompositeActionBuilder; |
8
|
|
|
use LightSaml\Context\ContextInterface; |
9
|
|
|
use LightSaml\Tests\BaseTestCase; |
10
|
|
|
use LightSaml\Tests\Mock\Action\FooAction; |
11
|
|
|
|
12
|
|
|
class CompositeActionBuilderTest extends BaseTestCase |
13
|
|
|
{ |
14
|
|
|
public function test__throws_on_priority_true() |
15
|
|
|
{ |
16
|
|
|
$this->expectException(\InvalidArgumentException::class); |
17
|
|
|
$compositeBuilder = new CompositeActionBuilder(); |
18
|
|
|
$compositeBuilder->add(new FooAction(), true); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function test__throws_on_priority_string() |
22
|
|
|
{ |
23
|
|
|
$this->expectException(\InvalidArgumentException::class); |
24
|
|
|
$compositeBuilder = new CompositeActionBuilder(); |
25
|
|
|
$compositeBuilder->add(new FooAction(), "asc"); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
View Code Duplication |
public function test__ranked_as_added_with_out_priority_parameter() |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
$order = 1; |
31
|
|
|
$action1 = $this->getActionMock(1, $order); |
32
|
|
|
$action2 = $this->getActionMock(2, $order); |
33
|
|
|
$action3 = $this->getActionMock(3, $order); |
34
|
|
|
|
35
|
|
|
$compositeBuilder = new CompositeActionBuilder(); |
36
|
|
|
$compositeBuilder->add($action1); |
|
|
|
|
37
|
|
|
$compositeBuilder->add($action2); |
|
|
|
|
38
|
|
|
$compositeBuilder->add($action3); |
|
|
|
|
39
|
|
|
|
40
|
|
|
$compositeAction = $compositeBuilder->build(); |
41
|
|
|
|
42
|
|
|
$this->assertInstanceOf(CompositeAction::class, $compositeAction); |
43
|
|
|
|
44
|
|
|
$compositeAction->execute($this->getMockBuilder(ContextInterface::class)->getMock()); |
|
|
|
|
45
|
|
|
} |
46
|
|
|
|
47
|
|
View Code Duplication |
public function test__ranked_as_given_priority_parameter() |
|
|
|
|
48
|
|
|
{ |
49
|
|
|
$order = 1; |
50
|
|
|
$action1 = $this->getActionMock(3, $order); |
51
|
|
|
$action2 = $this->getActionMock(1, $order); |
52
|
|
|
$action3 = $this->getActionMock(2, $order); |
53
|
|
|
|
54
|
|
|
$compositeBuilder = new CompositeActionBuilder(); |
55
|
|
|
$compositeBuilder->add($action1, 10); |
|
|
|
|
56
|
|
|
$compositeBuilder->add($action2, 2); |
|
|
|
|
57
|
|
|
$compositeBuilder->add($action3, 7); |
|
|
|
|
58
|
|
|
|
59
|
|
|
$compositeAction = $compositeBuilder->build(); |
60
|
|
|
|
61
|
|
|
$this->assertInstanceOf(CompositeAction::class, $compositeAction); |
62
|
|
|
|
63
|
|
|
$compositeAction->execute($this->getMockBuilder(ContextInterface::class)->getMock()); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $expectedOrder |
68
|
|
|
* @param int $order |
69
|
|
|
* |
70
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|ActionInterface |
71
|
|
|
*/ |
72
|
|
|
private function getActionMock($expectedOrder, &$order) |
73
|
|
|
{ |
74
|
|
|
$action = $this->getMockBuilder(ActionInterface::class)->getMock(); |
75
|
|
|
$action->expects($this->once()) |
76
|
|
|
->method('execute') |
77
|
|
|
->willReturnCallback(function () use ($expectedOrder, &$order) { |
78
|
|
|
$this->assertEquals($expectedOrder, $order); |
79
|
|
|
$order++; |
80
|
|
|
}) |
81
|
|
|
; |
82
|
|
|
|
83
|
|
|
return $action; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.