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

TemplateContext::beforeScenario()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
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