aboutsummaryrefslogtreecommitdiffhomepage
path: root/assets/php/vendor/react/promise-timer/tests/TestCase.php
blob: 9d8d49a7caa26e132d65833eef519b01cd94160a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php

namespace React\Tests\Promise\Timer;

use PHPUnit\Framework\TestCase as BaseTestCase;
use React\EventLoop\Factory;

class TestCase extends BaseTestCase
{
    protected $loop;

    public function setUp()
    {
        $this->loop = Factory::create();
    }

    protected function expectCallableOnce()
    {
        $mock = $this->createCallableMock();

        $mock
            ->expects($this->once())
            ->method('__invoke');

        return $mock;
    }

    protected function expectCallableNever()
    {
        $mock = $this->createCallableMock();

        $mock
            ->expects($this->never())
            ->method('__invoke');

        return $mock;
    }

    /**
     * @link https://github.com/reactphp/react/blob/master/tests/React/Tests/Socket/TestCase.php (taken from reactphp/react)
     */
    protected function createCallableMock()
    {
        return $this->getMockBuilder('React\Tests\Promise\Timer\CallableStub')->getMock();
    }

    protected function expectPromiseRejected($promise)
    {
        return $promise->then($this->expectCallableNever(), $this->expectCallableOnce());
    }

    protected function expectPromiseResolved($promise)
    {
        return $promise->then($this->expectCallableOnce(), $this->expectCallableNever());
    }

    protected function expectPromisePending($promise)
    {
        return $promise->then($this->expectCallableNever(), $this->expectCallableNever());
    }
}