Completed
Push — 2.0 ( 0357a9...3fe951 )
by Peter
08:22 queued 10s
created

PlatformFunctionExecutorRegistrySpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * This file is part of the Happyr Doctrine Specification package.
6
 *
7
 * (c) Tobias Nyholm <[email protected]>
8
 *     Kacper Gunia <[email protected]>
9
 *     Peter Gribanov <[email protected]>
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace tests\Happyr\DoctrineSpecification\Operand\PlatformFunction\Executor;
16
17
use Happyr\DoctrineSpecification\Exception\PlatformFunctionExecutorException;
18
use Happyr\DoctrineSpecification\Operand\PlatformFunction\Executor\PlatformFunctionExecutorRegistry;
19
use PhpSpec\ObjectBehavior;
20
21
/**
22
 * @mixin PlatformFunctionExecutorRegistry
23
 */
24
final class PlatformFunctionExecutorRegistrySpec extends ObjectBehavior
25
{
26
    public function let(): void
27
    {
28
        $this->beConstructedWith([
29
            'abs' => 'abs',
30
        ]);
31
    }
32
33
    public function it_should_register_executor(): void
34
    {
35
        $executor = function (int $x, int $y): int {
36
            return $x + $y;
37
        };
38
39
        $this->register('Sum', $executor);
0 ignored issues
show
Bug introduced by
The method register() does not exist on tests\Happyr\DoctrineSpe...ionExecutorRegistrySpec. Did you maybe mean it_should_register_executor()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
40
        $this->has('sum')->shouldBe(true);
41
        $this->has('SUM')->shouldBe(true);
42
    }
43
44
    public function it_should_throw_exception_on_register_exist_executor(): void
45
    {
46
        $executor = function ($x) {
47
            return $x > 0 ? $x : $x * -1;
48
        };
49
50
        $this->shouldThrow(PlatformFunctionExecutorException::class)->during('register', ['abs', $executor]);
51
    }
52
53
    public function it_should_override_executor(): void
54
    {
55
        $executor = function ($x) {
56
            return $x > 0 ? $x : $x * -1;
57
        };
58
59
        $this->override('Abs', $executor);
0 ignored issues
show
Bug introduced by
The method override() does not exist on tests\Happyr\DoctrineSpe...ionExecutorRegistrySpec. Did you maybe mean it_should_override_executor()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
60
        $this->has('abs')->shouldBe(true);
61
        $this->has('ABS')->shouldBe(true);
62
    }
63
64
    public function it_should_throw_exception_on_override_undefined_executor(): void
65
    {
66
        $executor = function (int $x, int $y): int {
67
            return $x + $y;
68
        };
69
70
        $this->shouldThrow(PlatformFunctionExecutorException::class)->during('override', ['sum', $executor]);
71
    }
72
73
    public function it_should_execute(): void
74
    {
75
        $this->execute('abs', -5)->shouldBe(5);
76
        $this->execute('abs', 5)->shouldBe(5);
77
    }
78
79
    public function it_should_execute_custom_executor(): void
80
    {
81
        $executor = function (int $x, int $y): int {
82
            return $x + $y;
83
        };
84
85
        $this->register('Sum', $executor);
0 ignored issues
show
Bug introduced by
The method register() does not exist on tests\Happyr\DoctrineSpe...ionExecutorRegistrySpec. Did you maybe mean it_should_register_executor()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
86
        $this->execute('sum', 2, 3)->shouldBe(5);
0 ignored issues
show
Bug introduced by
The method execute() does not exist on tests\Happyr\DoctrineSpe...ionExecutorRegistrySpec. Did you maybe mean it_should_execute()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
87
    }
88
}
89