/usr/portage

Done that 3

Christmas this year meant productivity time for me.


Also I’ve played around with Epiphany’s WebKit backend.

Update: The patch for Liferea is now included in the subversion tree. I’m still working on WebKit for Liferea to complete the missing features.

Filed on 28-12-2007, 23:11 under , , , , , , , & three comments & no trackbacks

Testing exception messages 5

Since PHPUnit 3.2.0 the former extension for exception test case (PHPUnit_Extension_ExceptionTest) has been merged back into the default test case. This allows you to use setExpextedException() in a normal test case. A simple exception test looks like that:

<?php
class MyTest extends PHPUnit_Framework_TestCase
{
    public function testException()
    {
        $this->setExpectedException('Exception');
        throw new Exception();
    }
    /**
     * @expectedException Exception
     */
    public function testException2()
    {
        throw new Exception()
    }
}

Often this is not enough. When you use a Zend Framework alike style for exceptions (one base class to rule them all) you often throw the same exception class with different messages. To test wheither the correct exception has been thrown, I discussed with Sebastian Bergmann about introducing an contains assertion for messages and this patch was applied. So in the current PHPUnit trunk you can test exception messages:

<?php
class MyTest extends PHPUnit_Framework_TestCase
{
    public function testException()
    {
        $this->setExpectedException('Exception', 'Exception message');
        throw new Exception('Exception message');
    }
    /**
     * @expectedException Exception Exception message
     */
    public function testException2()
    {
        throw new Exception('Exception message')
    }
}

As internally PHPUnit uses an assertContains for the exception message you can even test for incomplete strings like an exception message containing a random file name.

I proposed to do the same for exception codes but Sebastian did not agree. But let’s see, maybe that will change when Zend Framework is going to use exception codes a lot.

Filed on 23-12-2007, 14:02 under , , & five comments & one trackback

Smarty templates and code coverage 0

PHPUnit provides a filter util to mark a piece of code as test fixture. This makes the template disappear from the coverage report and helps a lot to keep the code coverage report readable and clean. In case of Smarty you just use the builtin php-tag to execute native PHP calls:

{php}PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'TESTS');{/php}

Filed on 23-12-2007, 14:02 under , , , & no comments & no trackbacks

Naive type casting for Zend_Config 1

We have added a feature I call naive type detection/casting to Zend Framework’s Zend_Config. Per default Zend_Config is not aware of types, everything is a string (except the crappy auto-detection parse_ini_file() does, but that’s another – ugly – chapter). Our patch provides an opt-in feature to detect wheither something is an integer, a string, a float or a boolean. It does that when a value is fetched, which should be the fastest way (most of configuration values are fetched one time, during a page load). The related ticket is #2312 and the latest patch is available here.

Filed on 17-12-2007, 08:08 under , , & one comment & no trackbacks