Subversion Repositories Applications.framework

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5 aurelien 1
<?php
2
/**
3
 * A test class for testing all sniffs for installed standards.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  PHP
8
 * @package   PHP_CodeSniffer
9
 * @author    Greg Sherwood <gsherwood@squiz.net>
10
 * @author    Marc McIntyre <mmcintyre@squiz.net>
11
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
12
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
13
 * @version   CVS: $Id: AllSniffs.php,v 1.7 2007/08/15 01:26:09 squiz Exp $
14
 * @link      http://pear.php.net/package/PHP_CodeSniffer
15
 */
16
 
17
// Require this here so that the unit tests don't have to try and find the
18
// abstract class once it is installed into the PEAR tests directory.
19
require_once dirname(__FILE__).'/AbstractSniffUnitTest.php';
20
 
21
/**
22
 * A test class for testing all sniffs for installed standards.
23
 *
24
 * Usage: phpunit AllSniffs.php
25
 *
26
 * This test class loads all unit tests for all installed standards into a
27
 * single test suite and runs them. Errors are reported on the command line.
28
 *
29
 * @category  PHP
30
 * @package   PHP_CodeSniffer
31
 * @author    Greg Sherwood <gsherwood@squiz.net>
32
 * @author    Marc McIntyre <mmcintyre@squiz.net>
33
 * @copyright 2006 Squiz Pty Ltd (ABN 77 084 670 600)
34
 * @license   http://matrix.squiz.net/developer/tools/php_cs/licence BSD Licence
35
 * @version   Release: 1.2.0RC1
36
 * @link      http://pear.php.net/package/PHP_CodeSniffer
37
 */
38
class PHP_CodeSniffer_Standards_AllSniffs
39
{
40
 
41
 
42
    /**
43
     * Prepare the test runner.
44
     *
45
     * @return void
46
     */
47
    public static function main()
48
    {
49
        PHPUnit_TextUI_TestRunner::run(self::suite());
50
 
51
    }//end main()
52
 
53
 
54
    /**
55
     * Add all sniff unit tests into a test suite.
56
     *
57
     * Sniff unit tests are found by recursing through the 'Tests' directory
58
     * of each installed coding standard.
59
     *
60
     * @return PHPUnit_Framework_TestSuite
61
     */
62
    public static function suite()
63
    {
64
        $suite = new PHPUnit_Framework_TestSuite('PHP CodeSniffer Standards');
65
 
66
        $isInstalled = !is_file(dirname(__FILE__).'/../../CodeSniffer.php');
67
 
68
        if ($isInstalled === false) {
69
            // We have not been installed.
70
            $standardsDir = realpath(dirname(__FILE__).'/../../CodeSniffer/Standards');
71
        } else {
72
            $standardsDir = '';
73
        }
74
 
75
        $standards = PHP_CodeSniffer::getInstalledStandards(true, $standardsDir);
76
 
77
        foreach ($standards as $standard) {
78
            if ($isInstalled === false) {
79
                $standardDir = realpath($standardsDir.'/'.$standard.'/Tests/');
80
            } else {
81
                $standardDir = dirname(__FILE__).'/'.$standard.'/Tests/';
82
            }
83
 
84
            if (is_dir($standardDir) === false) {
85
                // No tests for this standard.
86
                continue;
87
            }
88
 
89
            $di = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($standardDir));
90
 
91
            foreach ($di as $file) {
92
                // Skip hidden files.
93
                if (substr($file->getFilename(), 0, 1) === '.') {
94
                    continue;
95
                }
96
 
97
                // Tests must have the extention 'php'.
98
                $parts = explode('.', $file);
99
                $ext   = array_pop($parts);
100
                if ($ext !== 'php') {
101
                    continue;
102
                }
103
 
104
                $filePath = realpath($file->getPathname());
105
 
106
                if ($isInstalled === false) {
107
                    $className = str_replace($standardDir.DIRECTORY_SEPARATOR, '', $filePath);
108
                } else {
109
                    $className = str_replace(dirname(__FILE__).DIRECTORY_SEPARATOR, '', $filePath);
110
                }
111
 
112
                $className = substr($className, 0, -4);
113
                $className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
114
 
115
                if ($isInstalled === false) {
116
                    $className = $standard.'_Tests_'.$className;
117
                }
118
 
119
                $niceName  = substr($className, (strrpos($className, '_') + 1), -8);
120
 
121
                include_once $filePath;
122
                $class = new $className($niceName);
123
                $suite->addTest($class);
124
            }//end foreach
125
        }//end foreach
126
 
127
        return $suite;
128
 
129
    }//end suite()
130
 
131
 
132
}//end class
133
 
134
?>