DoneResolverTests   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 60
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testResolve() 0 10 1
A testReject() 0 10 1
A testNotify() 0 10 1
A innerFailureTest() 0 12 1
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