1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* Base class to use when testing methods in the Sniff.php file. |
4
|
|
|
* |
5
|
|
|
* @package PHPCompatibility |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
if (class_exists('BaseSniffTest', true) === false) { |
9
|
|
|
require_once dirname(dirname(__FILE__)) . '/BaseSniffTest.php'; |
10
|
|
|
} |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Set up and Tear down methods for testing methods in the Sniff.php file. |
14
|
|
|
* |
15
|
|
|
* @uses BaseSniffTest |
16
|
|
|
* @package PHPCompatibility |
17
|
|
|
*/ |
18
|
|
|
abstract class AbstractSniffMethodTestFramework extends BaseSniffTest |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
|
21
|
|
|
public $filename; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The PHP_CodeSniffer_File object containing parsed contents of this file. |
25
|
|
|
* |
26
|
|
|
* @var PHP_CodeSniffer_File |
27
|
|
|
*/ |
28
|
|
|
protected $_phpcsFile; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* A wrapper for the abstract PHPCompatibility sniff. |
32
|
|
|
* |
33
|
|
|
* @var PHPCompatibility_Sniff |
34
|
|
|
*/ |
35
|
|
|
protected $helperClass; |
36
|
|
|
|
37
|
|
|
|
38
|
|
|
public static function setUpBeforeClass() |
39
|
|
|
{ |
40
|
|
|
require_once dirname(__FILE__) . '/TestHelperPHPCompatibility.php'; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
protected function setUp() |
44
|
|
|
{ |
45
|
|
|
parent::setUp(); |
46
|
|
|
|
47
|
|
|
$this->helperClass = new TestHelperPHPCompatibility; |
48
|
|
|
|
49
|
|
|
$filename = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR . $this->filename; |
50
|
|
|
$phpcs = new PHP_CodeSniffer(); |
51
|
|
|
|
52
|
|
|
if (version_compare(PHP_CodeSniffer::VERSION, '2.0', '<')) { |
53
|
|
|
$this->_phpcsFile = new PHP_CodeSniffer_File( |
54
|
|
|
$filename, |
55
|
|
|
array(), |
56
|
|
|
array(), |
57
|
|
|
array(), |
|
|
|
|
58
|
|
|
array(), |
|
|
|
|
59
|
|
|
$phpcs |
60
|
|
|
); |
61
|
|
|
} |
62
|
|
|
else { |
63
|
|
|
$this->_phpcsFile = new PHP_CodeSniffer_File( |
64
|
|
|
$filename, |
65
|
|
|
array(), |
66
|
|
|
array(), |
67
|
|
|
$phpcs |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
$contents = file_get_contents($filename); |
72
|
|
|
$this->_phpcsFile->start($contents); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Clean up after finished test. |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function tearDown() |
81
|
|
|
{ |
82
|
|
|
unset($this->_phpcsFile, $this->helperClass); |
83
|
|
|
|
84
|
|
|
}//end tearDown() |
85
|
|
|
|
86
|
|
|
} |
87
|
|
|
|
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.