atoum / atoum-documentation

Documentation of atoum, a php unit test framework
http://docs.atoum.org
Other
10 stars 41 forks source link

shuntParentClassCalls documentation #37

Closed b-viguier closed 7 years ago

b-viguier commented 10 years ago

According to the current (french) documentation, it is not clear to know if we have to call shuntParentClassCalls each time we create a mock or not. Here a surprising example for me:

//2 classes to test
class A {
    public function __construct() {
        trigger_error("Error A");
    }
}

class B {
    public function __construct() {
        trigger_error("Error B");
    }
}
...
//Now for the test, we want to mock classes above, but without calling constructor
public function test_shunt() {
        //We need to shunt constructor call
        $this->mockGenerator->shuntParentClassCalls();
        new \mock\A;
        //Don't needed again
        new \mock\A;
        //... but for a new class (I guess?), it is needed again
        $this->mockGenerator->shuntParentClassCalls();
        new \mock\B;
        //don't need...
        new \mock\B;
        //don't need...
        new \mock\A;
}

I guess that the mock generator work differently according to the class to mock, but IMHO it is not clear according to the documentation... or if it is not a feature, it is a bug :)

Thanks for your work!

jubianchi commented 10 years ago

You are right, this could be a bit more clear :)

Just to let you know how the generator works:

b-viguier commented 10 years ago

Ok, thanks for this confirmation :) I let you decide if this ticket has to be closed or not, but I think it could be a good reminder for everyone...

jubianchi commented 10 years ago

The doc has to be improved so I'll let this open as a reminder for what has to be done ;)

Thanks!

bertrandjamin commented 8 years ago

I have encountered the same issue with the orphanize method. It could be interesting to add the same note (https://github.com/atoum/atoum-documentation/compare/master...Grummfy:fix_37#diff-f08c1881f1aaa0bc58353d50958c5068R124) for this part. Or make this note more global for all the mockGenerator part ?

Grummfy commented 8 years ago

a lot need improvements on tis part, I need to finished it with overall clear example (and this is the most difficult part in this one)

@bertrandjamin don't hesitate to clone my repo and try to improve this part in french or english.