Completed
Push — develop ( 996ea2...dbd153 )
by Jaap
10:32 queued 05:52
created

TemplateContext   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 44
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A gatherContexts() 0 6 1
A beforeScenario() 0 12 1
A cleanup() 0 6 2
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author    Mike van Riel <[email protected]>
9
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
10
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
11
 * @link      http://phpdoc.org
12
 *
13
 *
14
 */
15
16
namespace phpDocumentor\Behat\Contexts\Template;
17
18
use Behat\Behat\Context\Context;
19
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
20
use phpDocumentor\Behat\Contexts\EnvironmentContext;
21
use Symfony\Component\Process\Process;
22
23
final class TemplateContext implements Context
24
{
25
    /** @var EnvironmentContext */
26
    private $environmentContext;
27
28
    /**
29
     * @var Process
30
     */
31
    private $webserver;
32
33
    /** @BeforeScenario         */
34
    public function gatherContexts(BeforeScenarioScope $scope)
35
    {
36
        $environment = $scope->getEnvironment();
37
38
        $this->environmentContext = $environment->getContext('phpDocumentor\Behat\Contexts\EnvironmentContext');
39
    }
40
41
    /**
42
     * @beforeScenario
43
     */
44
    public function beforeScenario()
45
    {
46
        $workingDir = $this->environmentContext->getWorkingDir();
47
48
        $this->webserver = new Process(
49
                sprintf('php -S localhost:8080 -t %s', escapeshellarg($workingDir))
50
        );
51
52
        $this->webserver->start(function () {
53
            echo "Server started";
54
        });
55
    }
56
57
    /**
58
     * @AfterScenario
59
     */
60
    public function cleanup()
61
    {
62
        if ($this->webserver->isStarted()) {
63
            $this->webserver->stop();
64
        }
65
    }
66
}
67