1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hiapi\tests\unit\Endpoints; |
4
|
|
|
|
5
|
|
|
use Closure; |
6
|
|
|
use hiapi\endpoints\EndpointBuilderInterface; |
7
|
|
|
use hiapi\endpoints\EndpointConfig; |
8
|
|
|
use hiapi\endpoints\Module\Builder\OrderedBuildersCallTrait; |
9
|
|
|
use hiapi\endpoints\Module\Builder\ReflectionBasedEndpointBuilderTrait; |
10
|
|
|
use hiapi\endpoints\Module\InOutControl\ExamplesAwareBuilderInterface; |
11
|
|
|
use hiapi\endpoints\Module\InOutControl\ExamplesAwareBuilderTrait; |
12
|
|
|
use hiapi\endpoints\Module\InOutControl\InOutControlBuilderInterface; |
13
|
|
|
use hiapi\endpoints\Module\InOutControl\InOutControlBuilderTrait; |
14
|
|
|
use hiapi\tests\unit\Endpoints\support\FakeEndpoint; |
15
|
|
|
use hiapi\tests\unit\Endpoints\support\InputStub; |
16
|
|
|
use hiapi\tests\unit\Endpoints\support\ReturnStub; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @group endpoints |
21
|
|
|
*/ |
22
|
|
|
class EndpointBuilderTest extends TestCase |
23
|
|
|
{ |
24
|
|
|
protected $builder; |
25
|
|
|
|
26
|
|
|
protected function setUp() |
27
|
|
|
{ |
28
|
|
|
parent::setUp(); |
29
|
|
|
|
30
|
|
|
$this->builder = new FakeEndpointBuilder(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testBuilderProducesEndpoints() |
34
|
|
|
{ |
35
|
|
|
$builder = $this->builder |
36
|
|
|
->take(InputStub::class) |
37
|
|
|
->return(ReturnStub::class); |
38
|
|
|
|
39
|
|
|
$endpoint = $builder->build(); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Class TestABC |
45
|
|
|
* |
46
|
|
|
* @author Dmytro Naumenko <[email protected]> |
47
|
|
|
*/ |
48
|
|
|
class FakeEndpointBuilder implements |
49
|
|
|
EndpointBuilderInterface, |
50
|
|
|
ExamplesAwareBuilderInterface, |
51
|
|
|
InOutControlBuilderInterface |
52
|
|
|
{ |
53
|
|
|
use ExamplesAwareBuilderTrait; |
54
|
|
|
use InOutControlBuilderTrait { |
55
|
|
|
buildInOutParameters as buildInOutControl; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return Closure[] |
60
|
|
|
*/ |
61
|
|
|
protected function getBuildersList(): array |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
Closure::fromCallable([$this, 'buildExamples']), |
65
|
|
|
Closure::fromCallable([$this, 'buildInOutControl']), |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @inheritDoc |
71
|
|
|
*/ |
72
|
|
|
public function build() |
73
|
|
|
{ |
74
|
|
|
$builders = $this->getBuildersList(); |
75
|
|
|
|
76
|
|
|
$config = new EndpointConfig(); |
77
|
|
|
foreach ($builders as $builder) { |
78
|
|
|
$builder($config); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return FakeEndpoint::fromConfig($config); |
82
|
|
|
} |
83
|
|
|
}; |
84
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.