1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
use Behat\Behat\Context\Context; |
4
|
|
|
use Behat\Behat\Context\SnippetAcceptingContext; |
5
|
|
|
|
6
|
|
|
require_once __DIR__ . '/../../vendor/phpunit/phpunit/src/Framework/Assert/Functions.php'; |
7
|
|
|
require_once __DIR__ . '/ApiContext.php'; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Defines application features from the specific context. |
11
|
|
|
*/ |
12
|
|
|
class FeatureContext implements Context, SnippetAcceptingContext |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
use \Commercetools\Core\ApiContext; |
15
|
|
|
|
16
|
|
|
protected static $coverage; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @BeforeSuite |
20
|
|
|
*/ |
21
|
|
|
public static function setup() |
22
|
|
|
{ |
23
|
|
|
if (isset($_SERVER['BEHAT_COVERAGE']) && $_SERVER['BEHAT_COVERAGE'] == true) { |
24
|
|
|
$filter = new \PHP_CodeCoverage_Filter(); |
|
|
|
|
25
|
|
|
$filter->addDirectoryToBlacklist(__DIR__ . '/../vendor'); |
26
|
|
|
$filter->addDirectoryToBlacklist(__DIR__ . '/../tests'); |
27
|
|
|
$filter->addDirectoryToBlacklist(__DIR__ . '/../features'); |
28
|
|
|
$filter->addDirectoryToWhitelist(__DIR__ . '/../src'); |
29
|
|
|
|
30
|
|
|
static::$coverage = new \PHP_CodeCoverage(null, $filter); |
|
|
|
|
31
|
|
|
static::$coverage->start('Behat Test'); |
32
|
|
|
} |
33
|
|
|
date_default_timezone_set('UTC'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @AfterSuite |
39
|
|
|
*/ |
40
|
|
|
public static function teardown() |
41
|
|
|
{ |
42
|
|
|
if (isset($_SERVER['BEHAT_COVERAGE']) && $_SERVER['BEHAT_COVERAGE'] == true) { |
43
|
|
|
static::$coverage->stop(); |
44
|
|
|
|
45
|
|
|
echo 'Generating code coverage report in Clover XML format ... '; |
46
|
|
|
$writer = new \PHP_CodeCoverage_Report_Clover(); |
|
|
|
|
47
|
|
|
$writer->process(static::$coverage, __DIR__ . '/../../build/logs/behat-clover.cov'); |
48
|
|
|
echo 'done' . PHP_EOL; |
49
|
|
|
|
50
|
|
|
// echo 'Generating code coverage report in HTML format ... '; |
51
|
|
|
// $writer = new PHP_CodeCoverage_Report_HTML(); |
52
|
|
|
// $writer->process(static::$coverage, __DIR__ . "/../../build/behat/coverage"); |
53
|
|
|
// echo 'done' . PHP_EOL; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.