Re: Revisiting Anonymous Classes
| From: | Frédéric Hardy | Date: | Sat, 28 Jun 2014 18:40:11 +0000 |
| Subject: | Re: Revisiting Anonymous Classes | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-75125@lists.php.net to get a copy of this message | ||
Hello @internals,
Le 28 juin 2014 à 15:36, Sebastian Bergmann <sebastian@php.net> a écrit :
> The question remains, though, where to put this code. Obviously
> it belongs with the test suite. But how to name the test double
> classes? Unique names are required to be able to have multiple
> (differently configured) test doubles for the same original
> class. Mocking tools (such as PHPUnit_MockObject, for instance)
> use random names for their test double classes.
Atoum[1] use the \mock namespace to name stub and mock class.
So, if you want to create a mock of \vendor\project\bar, atoum generate the class
\mock\vendor\project\bar.
Moreover, to create a mock, just do $mock = new \mock\vendor\project\bar() in a test method and
atoum generate automatically the corresponding mock class code, thanks to its autoloader.
And an another namespace than \mock can be defined in the configuration file or in the test class.
But sure that anonymous class may be interesting…
[1] http://atoum.org/atoum
Best regards,
Fred
--
========================================================================
Frédéric Hardy : Directeur technique et fonctionnel agile
CV : http://blog.mageekbox.net/public/cv.frederic.hardy.pdf
Blog : http://blog.mageekbox.net
Twitter : http://twitter.com/mageekguy
========================================================================