Database-Testing with PHPUnit and sqlite

Today I wanted to test a database-handling class using PHPUnits PHPUnit_Extensions_Database_TestCase and an sqlite in-memory database.

On running the tests I always got the following error-messages:

MyDatabaseTest::testDatabaseConnection with data set #0 ()
PHPUnit_Extensions_Database_Operation_Exception: COMPOSITE[TRUNCATE] operation failed on query:
                DELETE FROM "[tablename]"
             using args: Array
 [SQLSTATE[HY000]: General error: 1 no such table: [tablename]]


After some checking what might help I got different solutions:

  • Use MySQL as test-backend – No, I want to use an sqlite with in-memory storage as it’s fast and doesn’t require too much setup on a CI-Server
  • Use a pre-configured sqlite-file and therefore a file-based sqlite. That might have been possible, but I just wanted to use in-memory….

The solution was rather simple. It seems that PHPUnit deletes the content of the table in question before setting up the table to execute a test. That only works, if the table already exists. Therefore I’ve added a create table xyz statement right after setting up the in-memory-table. So the test-class now looks like that:

class MyDatabaseTest extends PHPUnit_Extensions_Database_TestCase
    protected $pdo = null;

     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
    public function getConnection()
        if (null === $this->pdo) {
            $this->pdo = new PDO('sqlite::memory:');
            $this->pdo->exec('create table [tablename]([table-definition])');
        return $this->createDefaultDBConnection($this->pdo, ':memory:');

     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
    public function getDataSet()
        return $this->createXMLDataSet('[path/to/xml-seed-file]');

    public function testDatabaseConnection()
        $pdo = $this->getConnection()->getConnection();
        // Do your database-tests here using the required pdo-object

Perhaps this can help someone to find a solution earlier 😉

Building a treehouse

About a year ago we decided to build a treehouse into our walnut.

So I kept my eyes open to see how others build their tree-houses. And finally on our last trip I found a way to get it done. I had a look at how the platforms on a high-rope-garden had been build and it seemed rather easy. Take two wooden beams, drill a hole on each side, connect them with threaded rods and tighten. The beams will then clamp around the trees trunk and hold tight. Add that setup right on top of the first one rotated by 90 degrees with longer beams so they can be used to add planks on top. Might sound complicated but it’s rather easy.

Construction of the platforms of the high-rope-garden at edersee
Construction of the platforms of the high-rope-garden at edersee

At least it’s easy when you have a straight, upright tree. At least that’s what I had to find out the hard way. Our walnut is everything but straight and upright. I struggled a while trying to get the beams halfway parallel to the ground. Until I finally gave up and had to think up something else. The idea of clamping the platform for the treehouse onto the tree was great, but it didn’t work out to use that technique to support the platform from below.

So after a week of thinking it through I decided to try a different way. When I can’t support the platform from below, I might be more lucky suspending it!

So I looked for a rather upright part of the tree and clamped two beams onto that and added two more above rotated. And on top of that I took 4 stainless steel-ropes around the tree.
hanging detail

Then I built the supporting base at the foot of the tree from 8x12cm wooden beams with 3,2 m length each. The 2 main beams got each 2 holes drilled right through through which I took the steel-ropes. The I hauled the thing up using some supporting ropes to get it to the final height and secured everything with the steel ropes. Base support hanging!
First steps towards a tree house

And from there on it was just a matter of „just do it“. Adding the remaining beams and putting the flooring onto those with cutouts for the tree was then the fun thing to do.

The next thing will be the walls and a partial roof to make it possible to enjoy some rain out there. But that might then become another story.

More images are available at

Development against the

Reminder to my future self:

Obtaining an authentication token from the using the vagrant-box via curl:

curl --data "{\"grant_type":"password","username":"<username>","password":"<password>","client_id":"web2","client_secret":"web2secret"}" -H "Content-Type: application/json" -H "Accept: application/json"

And then using that token via curl:

curl -H "Authorization: oauth <token>" -H "Content-Type: application/json" -H "Accept: application/json" --data "{}"<endpoint>

wordpress and markup

Markup is a great way to write text. And I wanted to be able to write my blog-posts in markup also. And I also wanted to be able to write code-snippets in markup.

It proved rather easy to integrate Jetbags markup-engine without the overhead of installing the complete jetbag-suite.

Just install and activate the jb_markup plugin. For code-highlighting I use the SyntaxHighlighter Evolved-plugin.

Caveat: The JB_Markup-plugin converts the markup to HTML with wordpress-tags on saving the post. That’s fine, as long as you do not turn on Syntax-Highlighting after saving the post. On saving the post JB_Markup checks whether the Syntax-Highlighter is activated and depending on that convertts code-blocks either to a simple ‚pre‘-tag or uses the \-syntax which enables the Syntax-Highlighter. So when you enable the SyntaxHighlighter after you wrote a post, you’ll have to resave the post!

Displaying Date-Ranges

Recently a new issue popped up on the issue-tracker which called for nicer date-ranges. As I did something like that a few weeks prior I grabbed the issue and starded working.

The output is a small library that enables you to display a date-range like 12. – 13. March 2015 instead of 12. March 2015 – 13. March 2015.

Simple thing.

It also displays March 12th – March 13th 2015 if you want to.

Not that easy any more.

I won’t bother you with the details on how it’s done (it seemed more difficult than it actually was) as you can see that in the source-code if you are interested.

Displaying Date-Ranges weiterlesen