0

在这篇文章中,rebolon 达到了使作品 atoum 和旧 php 类http://rebolon.tumblr.com/post/44208304360/atoum-et-une-classe-codee-en-php-5-2 我尝试但 wuth atoum phar 没有成功

atoum/mageekguy.atoum.phar
MyClass52.php

<?php
class MyClass52 {
    public function func1() {
        return  "yop";
    }
}

测试/MyClass52.php

<?php
namespace Tests\Units;

include 'MyClass52.php';
include_once 'atoum/mageekguy.atoum.phar';
use mageekguy\atoum;

class MyClass52_PSR0 extends atoum\test {
    public function testFunc1() {
        $myObject = new \MyClass52_PSR0;
        // Now you can do your test :
        $this->assert->string($myObject->func1())->isEqualTo('Yo');
    }
}

php -f tests/MyClass52.php
测试类 'Tests\Units\MyClass52_PSR0' 的测试类 'MyClass52_PSR0' 不存在

La meme 选择 en mode classique MyClass53.php

<?php
class MyClass53 {
    public function func1() {
        return "yop";
    }
}

测试/MyClass53.php

<?php
namespace tests\units;

include 'MyClass53.php';
include_once 'atoum/mageekguy.atoum.phar';

use mageekguy\atoum;

class MyClass53 extends atoum\test{
    public function testFunc1(){
        $myObject = new \MyClass53;
        $this->assert->string($myObject->func1())->isEqualTo('yop');
    }
}

php -f 测试/MyClass53.php
成功(1 次测试,1/1 方法,0 无效方法,0 跳过方法,2 断言)!

4

1 回答 1

0

旧的类是针对 php < 5.3 的,但是当你运行测试时,你必须在 php > 5.3 Atoum 做一些自省,你的测试类必须遵守一些约定,并且在 fatc 中它必须与被测试的类同名. 这是测试类中的命名空间,它将允许 php 同时使用这两个类。

<?php
namespace Tests\Units;

include 'MyClass52.php';
include_once 'atoum/mageekguy.atoum.phar';
use mageekguy\atoum;

class MyClass52 extends atoum\test { // The classname of the class to test is MyClass
    public function testFunc1() {
        $myObject = new \MyClass52; // Pay attention here, the class name in the MyClass52.php file is MyClass, so you must not change the name here
        // Now you can do your test :
        $this->assert->string($myObject->func1())->isEqualTo('Yo');
    }
}

瞧,我希望它会帮助你

于 2013-04-28T20:05:27.127 回答