首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >像@rebolon说的那样,尝试让atoum在php 5.2中的旧项目中工作

像@rebolon说的那样,尝试让atoum在php 5.2中的旧项目中工作
EN

Stack Overflow用户
提问于 2013-04-29 00:30:01
回答 1查看 135关注 0票数 0

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

atoum/mageekguy.atoum.phar

MyClass52.php

代码语言:javascript
复制
<?php
class MyClass52 {
    public function func1() {
        return  "yop";
    }
}

测试/MyClass52.php

代码语言:javascript
复制
<?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测试/MyClass52.php

对于测试类“Tests\Units\MyClass52_PSR0”,测试类“MyClass52_PSR0”不存在

La méme选择了en模式分类MyClass53.php

代码语言:javascript
复制
<?php
class MyClass53 {
    public function func1() {
        return "yop";
    }
}

测试/MyClass53.php

代码语言:javascript
复制
<?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个void方法,0个跳过方法,2个断言)!

EN

回答 1

Stack Overflow用户

发布于 2013-04-29 04:05:27

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

代码语言:javascript
复制
<?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');
    }
}

瞧,我希望它能帮助你

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16265036

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档