3
* This file is part of PHPUnit.
5
* (c) Sebastian Bergmann <sebastian@phpunit.de>
7
* For the full copyright and license information, please view the LICENSE
8
* file that was distributed with this source code.
12
* Prettifies class and method names for use in TestDox documentation.
15
* @subpackage Util_TestDox
16
* @author Sebastian Bergmann <sebastian@phpunit.de>
17
* @copyright Sebastian Bergmann <sebastian@phpunit.de>
18
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
19
* @link http://www.phpunit.de/
20
* @since Class available since Release 2.1.0
22
class PHPUnit_Util_TestDox_NamePrettifier
27
protected $prefix = 'Test';
32
protected $suffix = 'Test';
37
protected $strings = array();
40
* Prettifies the name of a test class.
45
public function prettifyTestClass($name)
49
if ($this->suffix !== null &&
50
$this->suffix == substr($name, -1 * strlen($this->suffix))) {
51
$title = substr($title, 0, strripos($title, $this->suffix));
54
if ($this->prefix !== null &&
55
$this->prefix == substr($name, 0, strlen($this->prefix))) {
56
$title = substr($title, strlen($this->prefix));
59
if (substr($title, 0, 1) == '\\') {
60
$title = substr($title, 1);
67
* Prettifies the name of a test method.
72
public function prettifyTestMethod($name)
76
if (!is_string($name) || strlen($name) == 0) {
80
$string = preg_replace('#\d+$#', '', $name, -1, $count);
82
if (in_array($string, $this->strings)) {
84
} elseif ($count == 0) {
85
$this->strings[] = $string;
88
if (strpos($name, '_') !== false) {
89
return str_replace('_', ' ', $name);
94
if (substr($name, 0, 4) == 'test') {
98
$name[0] = strtoupper($name[0]);
103
for ($i = $offset; $i < $max; $i++) {
105
ord($name[$i]) >= 65 &&
106
ord($name[$i]) <= 90) {
107
$buffer .= ' ' . strtolower($name[$i]);
109
$isNumeric = is_numeric($name[$i]);
111
if (!$wasNumeric && $isNumeric) {
116
if ($wasNumeric && !$isNumeric) {
120
$buffer .= $name[$i];
128
* Sets the prefix of test names.
130
* @param string $prefix
132
public function setPrefix($prefix)
134
$this->prefix = $prefix;
138
* Sets the suffix of test names.
140
* @param string $suffix
142
public function setSuffix($suffix)
144
$this->suffix = $suffix;