6 ms·
Parody – a PHP testing library
- sentiental 14y agoThere are a number of mock object libraries out there (mockery, shmock, phpunit's mock syntax, etc). This just looks like another builder syntax for making mocks / stubs with some fanciness around class extension - what's the benefit? Also, how often is it useful to define a class at test time that is initialized by production code (from the section I Still Have Serious Dependency Issues!). This seems like an unlikely use case.
- mattsah 14y agoI wrote this library for two major reasons: 1) To avoid the complexity of existing frameworks. 2) To be able to quickly and easily test code with various kinds of dependencies. It is predominately designed to test a single class in an extremely isolated context, not in the context of a full blown testing framework. It is designed to be a stupid as possible with the intention of allowing the developer (myself) to define very strict test condition and very fine grain control.
- freework 14y agoI'm confused, what does this have to do with Aaron Swartz?
- stanleydrew 14y agoI assume you are trying to make a joke. But it's not very funny.
- shanelja 14y agoNot funny at all, but in all honesty, I am also keen to get back to the normal flow of things, I have paid my respects and I feel that perhaps 15 articles on the front page may have been enough for now, leave his friends to mourn as they will, if you over do anything people tire of it quickly.
- deleted 14y ago[deleted]
- shanelja 14y agoYou have really taken my comment in entirely the wrong light, I'm not complaining that his death has been treat with respect and reverence but you are right in that I am now mentally filtering the articles with "!(^Aaron$)" - I read the first few to pop up at ridiculous O'clock, and a few more when I woke, then I read a few more after lunch, then a few more before my tea, now I just read another before posting this, I was simply saying what a few others are thinking, that there are simply too many articles related to him - the high quality ones and the truly heart felt ones are being over shadowed by the "I once met Aaron in a coffee shop and he paid with 3 $0.25 coins!!!" type articles. If you were a friend, I apologize for your loss, but please think rationally and don't project your feelings on me.
- Gigablah 14y agoThis library could use Composer support. I suppose I'll make a quick pull request.
- mattsah 14y agoI'm cool with that. Feel free to move the example.php into a separate subdirectory to make it cleaner too, but please fix the includes to point to whatever relative directory need be.
- Gigablah 14y agoIt's done, I didn't touch the file structure since Composer is smart enough to map classes even if the layout isn't PSR compliant.
- 0x0 14y agoNoticing it's licensed under AGPL. I guess that means all projects that happen to include this (or something depending on it) would then be required to post full source code on the webpage, even if the project is for a single install?
- mattsah 14y agoNope. If the project actually uses tests for its function and it is accessible they would be required to provide the source to anyone user who requested it. Much like the regular GPL, AGPL is dependent on distribution. If you create a project that uses it to perform testing on the project, unless your testing is a function of the actual project then you wouldn't have to do anything of the sorts. If you created a testing platform online that used it to render services, then you would, yes.
- 0x0 14y agoOh okay. I haven't really looked much into AGPL, I just assumed it was "infecting" the whole project sorta like the GPL.
- mattsah 14y agoLet me clarify, I don't think anyone's projects that are web facing actually use their testing library to perform the tasks. So for all intents and purposes their projects as they are "distributed" over a network are not linking to it even though it may exist in their source tree. The only exception to this would be if the project is actually for testing, like say an online service that tests your code. Also any private non-distributed use does not require source distribution.
- RyanZAG 14y agoWhy is it AGPL then and not GPL? This seems to just create a minefield in the strange event when some test function needs to be exposed to the public for some reason. While this probably won't occur, if it does, suddenly the whole source needs to be released. There does not seem to be any benefit to making this AGPL as it as the source release on use feature of AGPL is not intended to be used during regular usage. Change it to GPL - it makes no practical difference, yet increases potential usage of the library at no cost.
- parf73 14y agogreat simplistic php testing framework: https://github.com/parf/spartan-test https://github.com/parf/spartan-test
- wvenable 14y agoSince this library requires PHP 5.4, I'm not sure why it bothers with this syntax: Parody\Mime::create('Vendor\Class\Project') -> onCall('method') -> expect('argument one') -> give('response one') -> onCall('method') -> expect('argument two') -> give('response two') -> resolve(); When one could just use anonymous functions to give the same result with less API-as-code. Parody\Mime::create('Vendor\Class\Project') -> onCall('method', function($param) { if ($param == 'argument one') return 'response one'; if ($param == 'argument two') return 'response two'; ) -> resolve(); This is more flexible, less code for the framework, and easier to learn.
- mattsah 14y agoExpectations and responses (provided by give()) are actually held internally. Your syntax is cleaner for very simple responses, however will become increasingly complex, particularly when the response itself is determined by a callback. Adding more params would clutter your example terribly. Also, the mime's are passed to callbacks which provide response so that additional functionality can be added, see this recent use-case: Parody\Mime::create('App\Text') -> onCall('create') -> expect('WTF' . DS . 'Yo') -> give(function($mime) { return $mime -> onCall('underscorize') -> give('wtf' . DS . 'yo') -> resolve(); });
- mattsah 14y agoEww, bad formatting, apologize, as I'm not familiar with hacker news comment system, but you can see the case here: https://github.com/dotink/inKWellToo/blob/master/external/testing/tests/Core.php#L23 https://github.com/dotink/inKWellToo/blob/master/external/te...
- wvenable 14y agoThat seems exceedingly clever -- too clever. I'd make some of that functionality a named function and call it from my callback. It took me way too long to figure out what your code did.
- mattsah 14y ago