~ballot/wordpress/openstack-objectstorage-bis

« back to all changes in this revision

Viewing changes to vendor/react/promise/tests/FulfilledPromiseTest.php

  • Committer: Thomas Cuthbert
  • Date: 2020-04-23 05:22:45 UTC
  • Revision ID: thomas.cuthbert@canonical.com-20200423052245-1jxao3mw31w435js
[,r=trivial] bionic composer vendor update

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
namespace React\Promise;
 
4
 
 
5
use React\Promise\PromiseAdapter\CallbackPromiseAdapter;
 
6
 
 
7
class FulfilledPromiseTest extends TestCase
 
8
{
 
9
    use PromiseTest\PromiseSettledTestTrait,
 
10
        PromiseTest\PromiseFulfilledTestTrait;
 
11
 
 
12
    public function getPromiseTestAdapter(callable $canceller = null)
 
13
    {
 
14
        $promise = null;
 
15
 
 
16
        return new CallbackPromiseAdapter([
 
17
            'promise' => function () use (&$promise) {
 
18
                if (!$promise) {
 
19
                    throw new \LogicException('FulfilledPromise must be resolved before obtaining the promise');
 
20
                }
 
21
 
 
22
                return $promise;
 
23
            },
 
24
            'resolve' => function ($value = null) use (&$promise) {
 
25
                if (!$promise) {
 
26
                    $promise = new FulfilledPromise($value);
 
27
                }
 
28
            },
 
29
            'reject' => function () {
 
30
                throw new \LogicException('You cannot call reject() for React\Promise\FulfilledPromise');
 
31
            },
 
32
            'notify' => function () {
 
33
                // no-op
 
34
            },
 
35
            'settle' => function ($value = null) use (&$promise) {
 
36
                if (!$promise) {
 
37
                    $promise = new FulfilledPromise($value);
 
38
                }
 
39
            },
 
40
        ]);
 
41
    }
 
42
 
 
43
    /** @test */
 
44
    public function shouldThrowExceptionIfConstructedWithAPromise()
 
45
    {
 
46
        $this->setExpectedException('\InvalidArgumentException');
 
47
 
 
48
        return new FulfilledPromise(new FulfilledPromise());
 
49
    }
 
50
 
 
51
    /** @test */
 
52
    public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithAlwaysFollowers()
 
53
    {
 
54
        gc_collect_cycles();
 
55
        $promise = new FulfilledPromise(1);
 
56
        $promise->always(function () {
 
57
            throw new \RuntimeException();
 
58
        });
 
59
        unset($promise);
 
60
 
 
61
        $this->assertSame(0, gc_collect_cycles());
 
62
    }
 
63
 
 
64
    /** @test */
 
65
    public function shouldNotLeaveGarbageCyclesWhenRemovingLastReferenceToFulfilledPromiseWithThenFollowers()
 
66
    {
 
67
        gc_collect_cycles();
 
68
        $promise = new FulfilledPromise(1);
 
69
        $promise = $promise->then(function () {
 
70
            throw new \RuntimeException();
 
71
        });
 
72
        unset($promise);
 
73
 
 
74
        $this->assertSame(0, gc_collect_cycles());
 
75
    }
 
76
}