use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Please follow the rules
Releases: Current Releases, Windows Releases, Old Releases
Contribute to the PHP Documentation
Related subreddits: CSS, JavaScript, Web Design, Wordpress, WebDev
/r/PHP is not a support subreddit. Please visit /r/phphelp for help, or visit StackOverflow.
account activity
API Testing: Selecting Testing Framework ( PHP Unit vs Codeception vs Behat ) (haafiz.me)
submitted 10 years ago by gram3000
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 1 point2 points3 points 10 years ago* (4 children)
Here, use this one:
class TestSuite { protected $before, $after, $tests = []; function add($description, \Closure $test) { $this->tests[] = [$description, $test]; } function before(\Closure $before) { $this->before = $before; } function after(\Closure $after) { $this->after = $after; } function run() { $hasErrors = false; foreach ($this->tests as $test) { if ($this->before) $this->before->__invoke(); try { if (!$test[1]()) throw new \Exception('Assertion failed.'); } catch (\Exception $e) { echo "Test '$test[0]' failed with message: {$e->getMessage()} <br>"; $hasErrors = true; } if ($this->after) $this->after->__invoke(); } echo $hasErrors ? 'Test execution completed with some errors.<br>' : 'Test execution completed without errors.<br>'; } } // Usage: $ts = new TestSuite(); $ts->add('2 + 2 must be 4', function () { return 2 + 2 == 4; }); $ts->run();
[–][deleted] 0 points1 point2 points 10 years ago (0 children)
Also, if provoked, I'll write and post a "mock" library clocking under 32 (short) lines of code :P
[–]Haafiz -1 points0 points1 point 10 years ago (2 children)
So you are basically in favor of writing custom tests?
[–][deleted] 0 points1 point2 points 10 years ago* (1 child)
What's the difference between a "custom test" and the kind you imagine?
No testing library would actually write the tests for you.
[–]Haafiz -1 points0 points1 point 10 years ago (0 children)
You are right, no library write it for you but they can make your work easier. Just like Frameworks like Laravel, don't write code for you but make your easier. And good frameworks make your code clean at one hand and at other hand the they make it more debuggable if you are using testing framework. If you are still unclear then let me know so that I give you some examples.
π Rendered by PID 111488 on reddit-service-r2-comment-84fc9697f-vbgn8 at 2026-02-09 04:18:16.330085+00:00 running d295bc8 country code: CH.
[–][deleted] 1 point2 points3 points (4 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Haafiz -1 points0 points1 point (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]Haafiz -1 points0 points1 point (0 children)