atoum / atoum

The modern, simple and intuitive PHP unit testing framework.
http://atoum.org
Other
1.44k stars 147 forks source link

Mock generator fail with custom classloader #183

Closed pgoergler closed 11 years ago

pgoergler commented 11 years ago

I used composer.phar and here my composer.json:

{
    "require": {
        "atoum/atoum": "dev-master",
        "sunra/php-simple-html-dom-parser": "dev-master",
    }
}

I try:

<?php

namespace
{

    class Bar
    {

    }

    class Test
    {

    }
}

namespace tests\units
{

    $loader = require __DIR__ . '/../../vendor/autoload.php';

    class Foo
    {

        public function bar(\Bar $b)
        {
            return $b;
        }

        public function dom(\simple_html_dom $dom)
        {

        }

    }

    class Test extends \mageekguy\atoum\test
    {

        public function test1()
        {
            $mocked = new \mock\tests\units\Foo();
        }

    }
}
?>

And i got:

> There is 1 exception:
=> tests\units\Test::test1():
==> Exception throwed in file /Users/[...]/tests/units/Test.php on line 42:
==> exception 'ReflectionException' with message 'Class simple_html_dom does not exist' in /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php:411
==> Stack trace:
==> #0 /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php(411): ReflectionParameter->getClass()
==> #1 /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php(430): mageekguy\atoum\mock\generator::getParameterType(Object(ReflectionParameter))
==> #2 /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php(266): mageekguy\atoum\mock\generator->getParameters(Object(ReflectionMethod), false)
==> #3 /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php(386): mageekguy\atoum\mock\generator->generateClassMethodCode(Object(ReflectionClass))
==> #4 /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php(187): mageekguy\atoum\mock\generator->generateClassCode(Object(ReflectionClass), '\mock\tests\uni...', 'Foo')
==> #5 /Users/[...]/vendor/atoum/atoum/classes/mock/generator.php(195): mageekguy\atoum\mock\generator->getMockedClassCode('tests\units\Foo', NULL, NULL)
==> #6 /Users/[...]/vendor/atoum/atoum/classes/test.php(783): mageekguy\atoum\mock\generator->generate('tests\units\Foo')
==> #7 [internal function]: mageekguy\atoum\{closure}('mock\tests\unit...')
==> #8 /Users/[...]/tests/units/Test.php(42): spl_autoload_call('mock\tests\unit...')
==> #9 /Users/[...]/vendor/atoum/atoum/classes/test.php(838): tests\units\Test->test1()
==> #10 -(1): mageekguy\atoum\test->runTestMethod('test1')
==> #11 {main}

I guess the problem is in the sunra package but, is there a way to avoid this ?

pgoergler commented 11 years ago

If i add :

include __DIR__ . '/../../vendor/sunra/php-simple-html-dom-parser/Src/Sunra/PhpSimple/simplehtmldom_1_5/simple_html_dom.php';

It seems to work ...