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

DeferredTests::testCancel()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 22
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
 * Deferred Tests class.
15
 *
16
 * @author Ivannis Suárez Jerez <[email protected]>
17
 * @author Karel Osorio Ramírez <[email protected]>
18
 */
19
class DeferredTests extends DeferredInterfaceTestCase
20
{
21
    /**
22
     * Test cancel.
23
     */
24
    public function testCancel()
25
    {
26
        $this
27
            ->given(
28
                /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */
29
                $deferred = $this->newDefaultTestedInstance()
30
            )
31
            ->when($canceled = $deferred->cancel())
32
            ->then()
33
                ->boolean($canceled)
34
                    ->isTrue()
35
        ;
36
37
        $this
38
            ->given($onRejected = $this->delegateMock())
39
            ->when($deferred->promise()->then(null, $onRejected))
40
            ->then()
41
                ->delegateCall($onRejected)
42
                    ->once()
43
        ;
44
45
        $this
46
            ->given(
47
                /** @var \Cubiche\Core\Async\Promise\DeferredInterface $deferred */
48
                $deferred = $this->newDefaultTestedInstance()
49
            )
50
            ->if($deferred->resolve('foo'))
51
            ->when($canceled = $deferred->cancel())
52
                ->then()
53
                    ->boolean($canceled)
54
                        ->isFalse()
55
            ;
56
    }
57
}
58