PHP, Zend Framework and Other Crazy Stuff
Mockery Terminology: Any Suggestions From The Audience?
Mockery is my Mock Object Framework for PHP 5.3, geared towards replacing existing mock object solutions (like PHPUnit Mock Objects) with a simpler, more flexible and more intuitive alternative with a fuller feature set. All that aside, this blog post is about some of the features Mockery 0.7 will add shortly. When I set out to write Mockery, I did so knowing that I’d need to settle on some new terminology. Here’s what I came up with:
1. Partial Mocks
This is the least debateable term since it’s adopted by other Test Double frameworks. A partial mock is a mock object where only some methods are mocked. The non-mocked methods continue to behave as defined in the class being mocked. It’s mainly useful where you only want to create a mock object which simulates a concrete implementation of an abstract class (in the absence of an existing concrete class).
2. Proxy Mocks
In writing Mockery I was faced with a dilemna when it came to classes and methods marked final. You can’t override such classes so the normal mocking implementation just doesn’t work. To resolve this and force the mocking of final methods, I settled on using the Proxy Pattern, thus the term Proxy Mock. The implementation is straightforward. Since we can’t override final methods/classes – we don’t. We ask the user to instantiate an actual of that type and pass it into Mockery. Mockery then embeds the object into a Proxy class, which can intercept method calls to the real objects and replace those methods with alternative behaviours (i.e. mock expectations). This is a simple way to mock final methods. Of course, it comes with a price – the Proxy won’t carry the real object’s type. And people wonder why I really don’t like the final keyword in PHP…
3. Alias Mocks
An Alias Mock is based on using class_alias() in PHP 5.3. The concept was to allow mocking of static methods by aliasing the class hosting the static methods, the alias being a mock object class. It works best in an autoloading scenario coupled with unit test process isolation. The next term will explain the main reason why aliasing was ceased upon as something worth including.
4. Instance Mocks
The real reason why Alias Mocks were created. An instance mock refers to a mock object class created as an alias to a real class. This basically is a cheap method of intercepting the “new” keyword without resorting to PHP extensions. All attempts to instantiate the real class, will instead provide an instance of the mock object alias. Again, it works best with autoloading (require_once calls would create a fatal error).
If you still don’t understand some facets of these – the Mockery README on github.com is a good place to see the API in action for these.
My question to readers is whether these four terms are acceptable? It’s hard to trust any single individual (i.e. me) to dream up appropriate terms, so feel free to offer suggestions or alternatives in the comments.
Related posts:
| Print article | This entry was posted by padraic on April 4, 2011 at 9:26 pm, and is filed under PHP General. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
-
http://gamemariobros.blogspot.com/ Mariobros
-
http://pulse.yahoo.com/_S2NDDVIDYNRL5JX7UTPRVYSL7Q Rave Monster
-
http://%/Endworld4 Alexander4
-
http://%/zzryspz5 STEVEN
-
http://%/zztebyw5 WALLACE
-
http://%/zznxhvr9 LEWIS
-
http://%/zzxxdth9 TERRENCE
-
http://%/zzvaequ3 JIMMIE
-
http://%/zzyuvln6 EDUARDO
-
http://%/zztlqnr9 PERRY
-
http://%/zzeqrqs2 DUSTIN
-
http://%/zzzyhnb4 BRADLEY
-
http://%/zzaujdy1 GARY
-
http://%/zzqrzco4 FELIX
-
http://%/zznoptq5 BRADLEY
-
http://%/zzhmxxx9 ROLAND
-
http://%/zzamhnd3 BYRON
-
http://%/zzfzhar3 LOUIS
-
http://%/zzgvnbe7 NATHAN
-
http://%/zznvxoz1 BOB
-
http://%/zzsvjkz2 RUBEN
-
http://%/zzamcwm2 ALBERT
-
http://%/zzdclpp6 WILLIAM
-
http://%/zzelhtb1 OLIVER
-
http://%/zzfnlia2 RAY
-
http://%/zzghpud1 SAMUEL
-
http://%/zzmzirn6 VICTOR
-
http://%/zzydumf4 EVERETT
-
http://%/zzcqwrv8 MELVIN
-
http://%/zzbqpoy6 JOEL
-
http://%/zzptgdk4 ALLEN
-
http://%/zzkfvkf8 GLENN
-
http://%/zzymcml3 JOHNNY
-
http://%/zzfucku4 MARION
-
http://%/zzfhpbr8 LEWIS
-
http://%/zzugbox6 MARION
-
http://%/zzxwoib2 WENDELL
-
http://%/zzqpptq7 LEROY
-
http://%/zzhdutd6 RONALD
-
http://%/zzkqmgi4 AARON
-
http://%/zzbroca1 ALLEN
-
http://%/zzzympb9 WENDELL
-
http://%/zznamnf1 BRYAN
-
http://%/zztcuao1 ERIC
-
http://%/zzqrttt2 REX
-
http://%/zznctzl5 BRENT
-
http://%/zzpbwxp4 JOHNNY
-
http://%/zzvbibp3 RONNIE
-
http://%/zzltzcx3 BOB
-
http://%/zzvdvxo9 DUSTIN
-
http://%/zzqlniu2 RALPH
-
http://%/zzeghca1 JESUS
-
http://%/zzxqtbz6 DALE
-
http://%/zzwhyli7 EUGENE
-
http://%/zzfywdc4 DEREK
-
http://%/zzmrkhs4 ALAN
-
http://%/zzsdgdi6 MATT
-
http://%/zzsddch3 EDWIN
-
http://%/zzpldtk6 AUSTIN
-
http://%/zzylqiv4 MILTON
-
http://%/zzaisut1 KIRK
-
http://%/zzsnush3 PEDRO
-
http://%/zzwhjmh8 ZACHARY
-
http://%/zznwsma9 NATHAN
-
http://%/zzjfcvc9 DOUGLAS
-
http://%/zzpwcca2 CALVIN
-
http://%/zznoupg8 KEN
-
http://%/zzlkmfe1 CODY
-
http://%/zzqtgnp9 MELVIN
-
http://%/zzmtgdg4 WALTER
-
http://%/zzeywdc4 ALEX
-
http://%/zzzrhmb2 WALLACE
-
http://%/zzpejyk1 FREDRICK
-
http://%/zzlmlxv4 LOUIS

