atoum / atoum

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

Chaining multiple hasConstant assertions fails #388

Closed jubianchi closed 9 years ago

jubianchi commented 9 years ago

Example:

<?php

namespace atoum\shou\tests\units;

use atoum;

class runner extends atoum
{
    public function testClass()
    {
        $this
            ->testedClass
                ->hasConstant('runStart')->isEqualTo('runnerStart')
                ->hasConstant('runStop')->isEqualTo('runnerStop')

                ->extends('atoum\shou\observable')
                ->implements('atoum\shou\observer')
        ;
    }
} 

This produces the following error:

 There is 1 error:
=> atoum\shou\tests\units\runner::testClass():
==> Error E_USER_ERROR in /Users/julien.bianchi/repositories/atoum/shou/tests/units/classes/runner.php on line 14, generated by file /Users/julien.bianchi/repositories/atoum/shou/tests/units/classes/runner.php on line 14:
Asserter 'hasConstant' does not exist

If I comment the second hasConstant assertion, I get the following error:

> There is 1 error:
=> atoum\shou\tests\units\runner::testClass():
==> Error E_USER_ERROR in /Users/julien.bianchi/repositories/atoum/shou/tests/units/classes/runner.php on line 16, generated by file /Users/julien.bianchi/repositories/atoum/shou/tests/units/classes/runner.php on line 16:
Asserter 'extends' does not exist

BTW, there is a workaround:

<?php

namespace atoum\shou\tests\units;

use atoum;

class runner extends atoum
{
    public function testClass()
    {
        $this
            ->testedClass
                ->hasConstant('runStart')->isEqualTo('runnerStart')
            ->testedClass
                ->hasConstant('runStop')->isEqualTo('runnerStop')
            ->testedClass
                ->extends('atoum\shou\observable')
                ->implements('atoum\shou\observer')
        ;
    }
} 
Hywan commented 9 years ago

Is it a bug? What about other asserters of the same group/family?

jubianchi commented 9 years ago

@Hywan as we discussed on IRC, this is a bug but we won't fix it because:

This is a won't fix... I think

mageekguy commented 9 years ago

It's not a bug, it's a feature… More seriously, this behavior is the wanted behavior, because any other implementation/solution is too complex regards to value added.

Hywan commented 9 years ago

Did other asserters behave like this also?

jubianchi commented 9 years ago

@Hywan some asserters are chainable, some other (like hasConstant) are not.

Hywan commented 9 years ago

Is it a lack of consistency?

jubianchi commented 9 years ago

@Hywan nop, it's a choice made to KISS see https://github.com/atoum/atoum/issues/388#issuecomment-66607966 and https://github.com/atoum/atoum/issues/388#issuecomment-66611281

Hywan commented 9 years ago

Thanks :-).