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.
14 * @since Class available since Release 2.1.0
16 class PHPUnit_Util_TestDox_NamePrettifier
21 protected $prefix = 'Test';
26 protected $suffix = 'Test';
31 protected $strings = array();
34 * Prettifies the name of a test class.
40 public function prettifyTestClass($name)
44 if ($this->suffix !== null &&
45 $this->suffix == substr($name, -1 * strlen($this->suffix))) {
46 $title = substr($title, 0, strripos($title, $this->suffix));
49 if ($this->prefix !== null &&
50 $this->prefix == substr($name, 0, strlen($this->prefix))) {
51 $title = substr($title, strlen($this->prefix));
54 if (substr($title, 0, 1) == '\\') {
55 $title = substr($title, 1);
62 * Prettifies the name of a test method.
68 public function prettifyTestMethod($name)
72 if (!is_string($name) || strlen($name) == 0) {
76 $string = preg_replace('#\d+$#', '', $name, -1, $count);
78 if (in_array($string, $this->strings)) {
80 } elseif ($count == 0) {
81 $this->strings[] = $string;
84 if (substr($name, 0, 4) == 'test') {
85 $name = substr($name, 4);
88 $name[0] = strtoupper($name[0]);
90 if (strpos($name, '_') !== false) {
91 return trim(str_replace('_', ' ', $name));
97 for ($i = 0; $i < $max; $i++) {
99 ord($name[$i]) >= 65 &&
100 ord($name[$i]) <= 90) {
101 $buffer .= ' ' . strtolower($name[$i]);
103 $isNumeric = is_numeric($name[$i]);
105 if (!$wasNumeric && $isNumeric) {
110 if ($wasNumeric && !$isNumeric) {
114 $buffer .= $name[$i];
122 * Sets the prefix of test names.
124 * @param string $prefix
126 public function setPrefix($prefix)
128 $this->prefix = $prefix;
132 * Sets the suffix of test names.
134 * @param string $suffix
136 public function setSuffix($suffix)
138 $this->suffix = $suffix;