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

DeferredProxyTests::testConstruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
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