October 27, 2011

rules

Tags: , , , ,
Filed under: ZenMagick — DerManoMann @ 2:05 am

For a new client project I’ve started looking at the php-rules project again. The project has all the ingredients for building a nice promotion system. However, the code has some shortcomings when it comes to PHP 5.3.

To cut a long(-ish) story short, I’ve forked the code (with the blessing of the author) and it now lives on github.

I’ve made some rather bigger changes to learn more about the code and to add some more structure – I hope it doesn’t affect performance too badly.

Feel free to have a look and give it a try. The tests are based on simpletest which is not included.

October 9, 2008

unit test improvements

Tags: ,
Filed under: ZenMagick — DerManoMann @ 11:39 pm

Despite some odds, I managed to improve the GUI for the ZenMagick unit tests quite a bit. Most importantly, it is now possible to run individual tests (read: methods) of a test case (read: class that extends ZMTestCase).

I have to say that, even though simpletest does allow all sorts of customizations, it’s not very straightforward and logic is not always were I was expecting it. In some cases, it also suffers from the fact that some details (for example line numbers) are not really accessible via the official API. I do hope that this will change in future versions as there is a lot of potential for improvements in that area.

Since the first version of the GUI does not scale well with a third level of dependencies, treeview saved the day!

So, her’s what it looks now:

Unit Tests organized with treeview

Unit Tests organized with treeview

August 28, 2008

ZenMagick unit testing

Tags: ,
Filed under: ZenMagick — DerManoMann @ 1:22 am

With ZenMagick 0.9.2 there is now an easy way to do automated testing.
The new zm_tests plugin comes with a number of tests that make sure that things do not get out of hand and to keep regressions low.

All testing is done in your browser and for those of you using IE, here is a screenshot of what you are missing out on :)

Web based testing

Web based testing

(I will try to improve the layout across browsers, but it’s a very low priority as it is working fine for me ;)

Edit: Actually, fixing the validation errors and generally making the page look a bit cooler helped a lot! This means the current trunk version does look good in IE, too.

Tests are grouped based based on the directory the code is found in (one level only) and it is easy to select and run single tests, a particular group or all.

Looking at the image you can also see the group ‘@other’. Tests in that group do not come with the plugin but are tests written for other plugins.

The way it works, plugins can detect if the testing plugin is installed. If so, they are able to programmatically register new tests. That means everyone can use the testing framework to easily run their own tests.

So far the most important tests are possibly the price calculation tests. Those actually depend on the demo store data being available in the database, as at least attribute prices are compared to static data. I might be able to change that in the future, but that will involve some more digging into zen-cart code.

Unit tests are written using the great SimpleTests library. The main reasons I picked that particular one were:

  • Easy to compress into a single file
  • Web page testing out of the box
  • Comes with a basic HTML report module

To be honest, other unit testing projects might provide the same, but after a few trials simple tests just fitted best into ZenMagick.

Expect more tests coming – I made a point of writing tests for most of the changes for 0.9.2. There will be more, in particular I plan to convert the included JMeter configuration into unit tests. There are a couple advantages in doing that:

  • Single interface for all testing
  • No other software required other than a browser
  • Tests can incorporate brower actions plus database verification at the same time

I apologize if I do not use some of simple test’s unique features like autorun, but it seems a lot nicer this way :)

Finally, a simple example of how to write a new test:

  1. Create a new file with a class extending UnitTestCase:
    class TestSimpleResultList extends UnitTestCase {
    ...
    }
  2. Add a method that starts with ‘test‘:
    public function testSomething() {
    $this->assertTrue(1 == 1);
    }
  3. Drop that new file in zenmagick/plugins/request/zm_tests/tests/misc

To use code to add a test (for another plugin), the following could be used in the plugins init() method::

if (null != ($tests = ZMPlugins::instance()->getPluginForId('zm_tests'))) {
// add class path only now to avoid errors due to missing UnitTestCase
ZMLoader::instance()->addPath($this->getPluginDir().'tests/');
$tests->addTest('TestZMTokens');
}