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

DeferredProxyTests   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultConstructorArguments() 0 12 1
A testConstruct() 0 11 1
B testReject() 0 27 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
use Cubiche\Core\Async\Promise\Deferred;
14
15
/**
16
 * Deferred Proxy Tests class.
17
 *
18
 * @author Ivannis Suárez Jerez <[email protected]>
19
 * @author Karel Osorio Ramírez <[email protected]>
20
 */
21
class DeferredProxyTests extends DeferredInterfaceTestCase
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    protected function defaultConstructorArguments()
27
    {
28
        return array(
29
            new Deferred(),
30
            function () {
31
            },
32
            function () {
33
            },
34
            function () {
35
            },
36
        );
37
    }
38
39
    /**
40
     * Test __construct.
41
     */
42
    public function testConstruct()
43
    {
44
        $this
45
            ->exception(function () {
46
                $deferred = new Deferred();
47
                $deferred->resolve();
48
                $this->newTestedInstance($deferred);
49
            })
50
                ->isInstanceOf(\InvalidArgumentException::class)
51
        ;
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function testReject()
58
    {
59
        parent::testReject();
60
61
        $this
62
            ->given(
63
                $reason = new \Exception(),
64
                $onRejected = $this->delegateMock(),
65
                /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */
66
                $deferred = $this->newTestedInstance(
67
                    new Deferred(),
68
                    null,
69
                    function () use ($reason) {
70
                        throw $reason;
71
                    }
72
                )
73
            )
74
            ->when(function () use ($deferred, $onRejected) {
75
                $deferred->promise()->then(null, $onRejected);
76
                $deferred->reject('foo');
77
            })
78
            ->then()
79
                ->delegateCall($onRejected)
80
                    ->withArguments($reason)
81
                    ->once()
82
            ;
83
    }
84
}
85