mageekguy\atoum\test::getTestedClassNameFromTestClass PHP Method

getTestedClassNameFromTestClass() public static method

public static getTestedClassNameFromTestClass ( $fullyQualifiedClassName, $testNamespace = null, mageekguy\atoum\tools\variable\analyzer $analyzer = null )
$analyzer mageekguy\atoum\tools\variable\analyzer
    public static function getTestedClassNameFromTestClass($fullyQualifiedClassName, $testNamespace = null, analyzer $analyzer = null)
    {
        $analyzer = $analyzer ?: new analyzer();
        if ($testNamespace === null) {
            $testNamespace = self::getNamespace();
        }
        if ($analyzer->isRegex($testNamespace) === true) {
            if (preg_match($testNamespace, $fullyQualifiedClassName) === 0) {
                throw new exceptions\runtime('Test class \'' . $fullyQualifiedClassName . '\' is not in a namespace which match pattern \'' . $testNamespace . '\'');
            }
            $testedClassName = preg_replace($testNamespace, '\\', $fullyQualifiedClassName);
        } else {
            $position = strpos($fullyQualifiedClassName, $testNamespace);
            if ($position === false) {
                throw new exceptions\runtime('Test class \'' . $fullyQualifiedClassName . '\' is not in a namespace which contains \'' . $testNamespace . '\'');
            }
            $testedClassName = substr($fullyQualifiedClassName, 0, $position) . substr($fullyQualifiedClassName, $position + 1 + strlen($testNamespace));
        }
        return trim($testedClassName, '\\');
    }

Usage Example

示例#1
0
文件: test.php 项目: atoum/atoum
 public function testGetTestedClassNameFromTestClass()
 {
     $this->string(atoum\test::getTestedClassNameFromTestClass(__CLASS__))->isEqualTo('mageekguy\\atoum\\test')->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\tests\\units\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->if(atoum\test::setNamespace('test\\unit'))->then->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\test\\unit\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->if(atoum\test::setNamespace('\\test\\unit\\'))->then->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\test\\unit\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->if(atoum\test::setNamespace('test\\unit\\'))->then->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\test\\unit\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->if(atoum\test::setNamespace('\\test\\unit'))->then->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\test\\unit\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->exception(function () {
         atoum\test::getTestedClassNameFromTestClass('foo\\bar\\aaa\\bbb\\testedClass');
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Test class \'foo\\bar\\aaa\\bbb\\testedClass\' is not in a namespace which contains \'' . atoum\test::getNamespace() . '\'')->if(atoum\test::setNamespace('#(?:^|\\\\)xxxs?\\\\yyys?\\\\#i'))->then->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\xxx\\yyy\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\xxxs\\yyy\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\xxxs\\yyys\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\xxx\\yyys\\testedClass'))->isEqualTo('foo\\bar\\testedClass')->exception(function () {
         atoum\test::getTestedClassNameFromTestClass('foo\\bar\\aaa\\bbb\\testedClass');
     })->isInstanceOf('mageekguy\\atoum\\exceptions\\runtime')->hasMessage('Test class \'foo\\bar\\aaa\\bbb\\testedClass\' is not in a namespace which match pattern \'' . atoum\test::getNamespace() . '\'')->string(atoum\test::getTestedClassNameFromTestClass('foo\\bar\\aaa\\bbb\\testedClass', '#(?:^|\\\\)aaas?\\\\bbbs?\\\\#i'))->isEqualTo('foo\\bar\\testedClass');
 }
test