Completed
Push — master ( 9672ef...b72795 )
by Ivannis Suárez
02:30
created

DoneResolverTests::testNotify()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
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
 * Done Resolver Tests class.
15
 *
16
 * @author Karel Osorio Ramírez <[email protected]>
17
 */
18
class DoneResolverTests extends ObservableResolverTestCase
19
{
20
    /**
21
     * {@inheritdoc}
22
     */
23
    public function testResolve()
24
    {
25
        parent::testResolve();
26
27
        $this->innerFailureTest(function (callable $onFulfilled) {
28
            /** @var \Cubiche\Core\Async\Promise\DoneResolver $resolver */
29
            $resolver = $this->newTestedInstance($onFulfilled);
30
            $resolver->resolve();
31
        });
32
    }
33
34
    /**
35
     * Test reject.
36
     */
37
    public function testReject()
38
    {
39
        parent::testReject();
40
41
        $this->innerFailureTest(function (callable $onRejected) {
42
            /** @var \Cubiche\Core\Async\Promise\DoneResolver $resolver */
43
            $resolver = $this->newTestedInstance(null, $onRejected);
44
            $resolver->reject();
45
        });
46
    }
47
48
    /**
49
     * Test notify.
50
     */
51
    public function testNotify()
52
    {
53
        parent::testNotify();
54
55
        $this->innerFailureTest(function (callable $onNotify) {
56
            /** @var \Cubiche\Core\Async\Promise\DoneResolver $resolver */
57
            $resolver = $this->newTestedInstance(null, null, $onNotify);
58
            $resolver->notify();
59
        });
60
    }
61
62
    /**
63
     * @param callable $when
64
     */
65
    protected function innerFailureTest(callable $when)
66
    {
67
        $this
68
            ->given(
69
                $reason = new \Exception(),
70
                $callback = $this->delegateMockWithException($reason)
71
            )
72
            ->exception(function () use ($when, $callback) {
73
                $when($callback);
74
            })
75
        ;
76
    }
77
}
78