File: MockDisablerTest.php

package info (click to toggle)
php-mock-phpunit 2.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 248 kB
  • sloc: php: 1,066; makefile: 20; xml: 7; sh: 7
file content (54 lines) | stat: -rw-r--r-- 1,302 bytes parent folder | download
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
<?php

namespace phpmock\phpunit;

use phpmock\Deactivatable;
use phpmock\Mock;
use PHPUnit\Framework\TestCase;

/**
 * Tests MockDisabler.
 *
 * @author Markus Malkusch <markus@malkusch.de>
 * @link bitcoin:1335STSwu9hST4vcMRppEPgENMHD2r1REK Donations
 * @license http://www.wtfpl.net/txt/copying/ WTFPL
 * @see MockDisabler
 */
class MockDisablerTest extends TestCase
{

    /**
     * Tests disabling the mock.
     *
     * @test
     */
    public function testEndTest()
    {
        $min = new Mock(__NAMESPACE__, "min", "max");
        $min->enable();
        $this->assertEquals(9, min(1, 9));
        
        $disabler = new MockDisabler($min);
        $disabler->endTest($this, 1);
        
        $this->assertEquals(1, min(1, 9));
    }

    public function testCallback()
    {
        $executed = false;
        $executedWith = null;
        $mock = $this->createMock(Deactivatable::class);
        $disabler = new MockDisabler($mock, static function ($disabler) use (&$executed, &$executedWith) {
            self::assertInstanceOf(MockDisabler::class, $disabler);

            $executed = true;
            $executedWith = $disabler;
        });

        $disabler->endTest($this, 1);

        self::assertTrue($executed);
        self::assertSame($executedWith, $disabler);
    }
}