Welcome to mirror list, hosted at ThFree Co, Russian Federation.

PHPTest.php « Util « tests « phpunit « phpunit « vendor - github.com/CarnetApp/CarnetNextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: feb12252e23d0027e28b995e19597503f00c1497 (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/*
 * This file is part of PHPUnit.
 *
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 * @author     Henrique Moody <henriquemoody@gmail.com>
 * @copyright  Sebastian Bergmann <sebastian@phpunit.de>
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 *
 * @link       http://www.phpunit.de/
 */
class PHPUnit_Util_PHPTest extends PHPUnit_Framework_TestCase
{
    public function testShouldNotUseStderrRedirectionByDefault()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');

        $this->assertFalse($phpMock->useStderrRedirection());
    }

    public function testShouldDefinedIfUseStderrRedirection()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setUseStderrRedirection(true);

        $this->assertTrue($phpMock->useStderrRedirection());
    }

    public function testShouldDefinedIfDoNotUseStderrRedirection()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setUseStderrRedirection(false);

        $this->assertFalse($phpMock->useStderrRedirection());
    }

    /**
     * @expectedException PHPUnit_Framework_Exception
     * @expectedExceptionMessage Argument #1 (No Value) of PHPUnit_Util_PHP::setUseStderrRedirection() must be a boolean
     */
    public function testShouldThrowsExceptionWhenStderrRedirectionVariableIsNotABoolean()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setUseStderrRedirection(null);
    }

    public function testShouldUseGivenSettingsToCreateCommand()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');

        $settings = [
            'allow_url_fopen=1',
            'auto_append_file=',
            'display_errors=1',
        ];

        $expectedCommandFormat  = '%s -d allow_url_fopen=1 -d auto_append_file= -d display_errors=1';
        $actualCommand          = $phpMock->getCommand($settings);

        $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);
    }

    public function testShouldRedirectStderrToStdoutWhenDefined()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setUseStderrRedirection(true);

        $expectedCommandFormat  = '%s 2>&1';
        $actualCommand          = $phpMock->getCommand([]);

        $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);
    }

    public function testShouldUseArgsToCreateCommand()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setArgs('foo=bar');

        $expectedCommandFormat  = '%s -- foo=bar';
        $actualCommand          = $phpMock->getCommand([]);

        $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);
    }

    public function testShouldHaveFileToCreateCommand()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');

        $expectedCommandFormat  = '%s -%c \'file.php\'';
        $actualCommand          = $phpMock->getCommand([], 'file.php');

        $this->assertStringMatchesFormat($expectedCommandFormat, $actualCommand);
    }

    public function testStdinGetterAndSetter()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setStdin('foo');

        $this->assertEquals('foo', $phpMock->getStdin());
    }

    public function testArgsGetterAndSetter()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setArgs('foo=bar');

        $this->assertEquals('foo=bar', $phpMock->getArgs());
    }

    public function testEnvGetterAndSetter()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setEnv(['foo' => 'bar']);

        $this->assertEquals(['foo' => 'bar'], $phpMock->getEnv());
    }

    public function testTimeoutGetterAndSetter()
    {
        $phpMock = $this->getMockForAbstractClass('PHPUnit_Util_PHP');
        $phpMock->setTimeout(30);

        $this->assertEquals(30, $phpMock->getTimeout());
    }
}