0

In this article, rebolon reach to make works atoum and old php class http://rebolon.tumblr.com/post/44208304360/atoum-et-une-classe-codee-en-php-5-2 I try to but wuth atoum phar without success

atoum/mageekguy.atoum.phar
MyClass52.php

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

tests/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
Tested class 'MyClass52_PSR0' does not exist for test class 'Tests\Units\MyClass52_PSR0'

La même chose en mode classique MyClass53.php

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

tests/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 tests/MyClass53.php
Success (1 test, 1/1 method, 0 void method, 0 skipped method, 2 assertions) !

ClemB
  • 87
  • 1
  • 11

1 Answers1

0

The old class is for php < 5.3, but when you run the test, you have to be in php > 5.3 Atoum do some introspection and your test class must respect some convention, and in fatc it must have the same name as the tested class. This is the namespace in the test class that will allow php to use both clas at the same time.

<?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');
    }
}

Voilà, i hope it will help you

Rebolon
  • 1,257
  • 11
  • 29