Completed
Push — master ( 83fca8...0d9c6e )
by Andrii
10:43
created

tests/unit/Endpoints/EndpointBuilderTest.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace hiapi\tests\unit\Endpoints;
4
5
use Closure;
6
use hiapi\endpoints\EndpointBuilderInterface;
7
use hiapi\endpoints\EndpointConfiguration;
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 testBuilderCanProduceEndpoint()
34
    {
35
        $builder = $this->builder
36
            ->take(InputStub::class)
37
            ->return(ReturnStub::class);
38
39
        $endpoint = $builder->build();
40
41
        $this->assertSame(InputStub::class, $endpoint->getConfig()['take']);
42
        $this->assertSame(ReturnStub::class, $endpoint->getConfig()['return']);
43
    }
44
}
45
46
/**
47
 * Class TestABC
48
 *
49
 * @author Dmytro Naumenko <[email protected]>
50
 */
51
class FakeEndpointBuilder implements
52
    EndpointBuilderInterface,
53
    ExamplesAwareBuilderInterface,
54
    InOutControlBuilderInterface
55
{
56
    use ExamplesAwareBuilderTrait;
57
    use InOutControlBuilderTrait {
58
        buildInOutParameters as buildInOutControl;
59
    }
60
61
    /**
62
     * @return Closure[]
63
     */
64
    protected function getBuildersList(): array
65
    {
66
        return [
67
            Closure::fromCallable([$this, 'buildExamples']),
68
            Closure::fromCallable([$this, 'buildInOutControl']),
69
        ];
70
    }
71
72
    /**
73
     * @inheritDoc
74
     */
75 View Code Duplication
    public function build()
0 ignored issues
show
This method seems to be duplicated in your project.

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.

Loading history...
76
    {
77
        $builders = $this->getBuildersList();
78
79
        $config = new EndpointConfiguration();
80
        foreach ($builders as $builder) {
81
            $builder($config);
82
        }
83
84
        return FakeEndpoint::fromConfig($config);
85
    }
86
};
87