Completed
Push — master ( 298e09...565401 )
by Ivannis Suárez
02:36
created

CallablePromisorTests   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 53
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultConstructorArguments() 0 6 1
B testInvoke() 0 37 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche/Async component.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Core\Async\Tests\Units\Promise;
12
13
/**
14
 * Callable Promisor Test class.
15
 *
16
 * @author Karel Osorio Ramírez <[email protected]>
17
 */
18
class CallablePromisorTests extends PromisorInterfaceTestCase
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    protected function defaultConstructorArguments()
24
    {
25
        return array(function () {
26
            return 'foo';
27
        });
28
    }
29
30
    /**
31
     * Test __invoke.
32
     */
33
    public function testInvoke()
34
    {
35
        $this
36
            ->given(
37
                /** @var \Cubiche\Core\Async\Promise\CallablePromisor $promisor */
38
                $promisor = $this->newDefaultTestedInstance(),
39
                $onFulfilled = $this->delegateMock()
40
            )
41
            ->when(function () use ($promisor, $onFulfilled) {
42
                $promisor();
43
                $promisor->promise()->then($onFulfilled);
44
            })
45
            ->then()
46
                ->delegateCall($onFulfilled)
47
                    ->withArguments('foo')
48
                    ->once()
49
        ;
50
51
        $this
52
            ->given(
53
                $reason = new \Exception(),
54
                /** @var \Cubiche\Core\Async\Promise\CallablePromisor $promisor */
55
                $promisor = $this->newTestedInstance(function () use ($reason) {
56
                    throw $reason;
57
                }),
58
                $onRejected = $this->delegateMock()
59
            )
60
            ->when(function () use ($promisor, $onRejected) {
61
                $promisor();
62
                $promisor->promise()->then(null, $onRejected);
63
            })
64
            ->then()
65
                ->delegateCall($onRejected)
66
                    ->withArguments($reason)
67
                    ->once()
68
        ;
69
    }
70
}
71