Solar: Modified Testing Strategy

In the current release of Solar (version 0.10.0) I use the .phpt test format, which is supported very well by Greg BeaverTomas V.V. Cox‘s “pear run-tests” code. The .phpt testing strategy compares the output of a test script to an expected output string, and passes if the outputs match.

I noticed some time ago that Greg has adopted a testing strategy that combines .phpt with techniques found in PHPUnit and SimpleTest. These testing packages use assertions to compare method returns, rather than comparing output at the end of a test script. Greg’s strategy uses assertions within .phpt tests: if there is no output, the test succeeds, but if an assertion fails, it generates unexpected output, which causes the .phpt test to fail.

(Aside: While true testing gurus may not think of this as a robust solution [hi Jason! hi Marcus! hi Sebastian!], I have thus far found it to be a “good-enough” approach that combines simplicity with … well, more simplicity. 🙂

Inspired by Greg’s PEAR_PHPTest class, I’ve developed a bare-bones Solar_Test_Assert class that tests assertions and throws PHP5 exceptions on assertion failures. Add to that a quick hack to run all tests at once recursively through subdirectories (courtesy of the “pear run-tests -r” switch), and you get a convenient all-at-once testing tool for Solar. Thanks, Greg, for producing such useful tools.

I spent one day over the weekend rewriting all the existing Solar tests to use this new strategy, and met with great success. I did run into one problem, though. The class-method tests in the subdirectories use a common prepend file. Normally, you would think that “include ‘../prepend.php'” would work, but because the tests are running at the command line, PHP doesn’t include “..” with respect to the subdirectory; instead, it tries to include “..” with respect to the current directory. This is the proper behavior, but it was causing every test to fail.

Mike Naberezny pointed out a cool trick to work around that behavior; instead of using “..”, you can use “dirname(dirname(__FILE__))” to get to the next-higher directory. After applying this fix, all my tests ran from the main directory using “pear run-tests -r”. Thanks, Mike.

Update: (2006-02-01) Greg pointed out that the “pear run-tests” is from Tomas V.V. Cox, so I update the above link. Thanks, Tomas, for this great testing tool.

Solar 0.10.0 Released

The good news is that I’ve rolled the 0.10.0 release for Solar, the simple object library and application repository for PHP5.

The bad news is that it has a ton of changes, and that the release after this will also have large number of changes. This is “bad” in the sense that none of the current users (inluding me) wants to change existing code to comply with the new Solar stuff, but it’s “good” in that it prepares Solar for wider acceptance among professional developers.

Read on for a very long description of the changes, especially regarding the new MVC architecture.

Continue reading

A Spate of Savant News

Savant is an object-oriented template system for PHP; it provides plugins, output filters, path management, stream support, and lots more. Savant uses PHP itself as the template language, so it is both fast and lightweight. Savant3 is for PHP5 E_STRICT compliance, while Savant2 is E_ALL compliant under both PHP4 and PHP5.

Savant3

Savant3 is marked “stable” as of yesterday, bringing to a close the very long beta period. You can read the change log and download it here. Woohoo!

Cyberlot notes his success using Savant3 and gettext; he wrote up an output filter that translates special tags, then caches the result. Nice work! (Update, 10am: see also his brief writeup via the Savant mailing list archive.)

Antti Holvikari noted some bugs (fixed in yesterday’s release of Savant3) and wrote a proof-of-concept app using Savant3 inside a PHP_Archive .phar file. Pretty cool, Antti!

Savant2

Also as of yesterday, Savant2 series has a 2.4.2 release. You can read the full change log, but the main points are:

  • Fixed a strpos() param order bug in the code for stream support
  • Use of __autoload() under PHP5 is now configurable; it’s off by default, but you can turn it on with setAutoload(true)