SelfTestCliCanFork   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 2
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B doTest() 0 35 5
1
<?php
2
3
/**
4
 * This file is part of tenside/core.
5
 *
6
 * (c) Christian Schiffler <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * This project is provided in good faith and hope to be usable by anyone.
12
 *
13
 * @package    tenside/core
14
 * @author     Christian Schiffler <[email protected]>
15
 * @copyright  2015 Christian Schiffler <[email protected]>
16
 * @license    https://github.com/tenside/core/blob/master/LICENSE MIT
17
 * @link       https://github.com/tenside/core
18
 * @filesource
19
 */
20
21
namespace Tenside\Core\SelfTest\Cli;
22
23
/**
24
 * This class tests that the php-cli can fork sub processes.
25
 */
26
class SelfTestCliCanFork extends AbstractSelfTestCli
27
{
28
    /**
29
     * Check that we have a correct CLI executable of PHP.
30
     *
31
     * @return void
32
     */
33
    public function doTest()
34
    {
35
        $this->setMessage('Check if the PHP CLI executable can fork processes.');
36
37
        if (!$this->hasInterpreter()) {
38
            $this->markSkipped('No PHP interpreter detected, can not test - assuming forking is not supported.');
39
            $this->getAutoConfig()->setForkingAvailable(false);
40
            return;
41
        }
42
43
        $output = $this->testCliRuntime('var_export(function_exists("pcntl_fork"));');
44
        if ('true' !== $output) {
45
            $this->markFailed('Function pcntl_fork not available (Output: ' . $output . ').');
46
            $this->getAutoConfig()->setForkingAvailable(false);
47
            return;
48
        }
49
50
        $output = $this->testCliRuntime('var_export(pcntl_fork());');
51
        if (is_numeric($output)) {
52
            if ('-1' === $output) {
53
                $this->markFailed('Function pcntl_fork() returned -1. Forking is not supported.');
54
                $this->getAutoConfig()->setForkingAvailable(false);
55
                return;
56
            }
57
            $this->markSuccess('Forked as pid ' . $output);
58
            $this->getAutoConfig()->setForkingAvailable(true);
59
            return;
60
        }
61
62
        $this->getAutoConfig()->setForkingAvailable(false);
63
64
        $this->markWarning(
65
            'Could not determine if forking is possible, assuming not supported (Output : ' . $output . ').'
66
        );
67
    }
68
}
69