Category: Random


Setting up phpDocumentor on Windows with XAMPP

By kristoffer,

phpDocumentor is a tool to generate documentation directly from your ´php´ files. This short post will tell you how to set it up on your Windows machine using XAMPP and pear.

Step one is to install XAMPP. Fire it up, and hit the button “Shell” in the GUI.

In the shell window, type the following commands

channel-discover pear.phpdoc.org
pear install –nocompress phpdoc/phpDocumentor-2.8.1

You are ready to go! Open up a CMD Window and verify that phpdoc command works.

To use, simply type:

 

  Category: Random
  Comments: Comments Off on Setting up phpDocumentor on Windows with XAMPP

Get ready for WordPress Plugin unit testing with XAMPP and PHP Unit (Windows)

By kristoffer,

Test Driven Development is one of the best strategies for building solid WordPress plugins that are easy to maintain and that is bootstrapped to live a long life in the WordPress ecosystem. There are many variations as to how to implement the approach, but they all have a common principle: Define tests first, then code.

So the first step before starting WordPress plugin development is to get a test environment up and running. This article will cover how to get ready for Unit testing on a local XAMPP development server using PHP Unit.

First, a short definition of unit test that I’ve paraphrased from the Wikipedia article on the topic

a software testing method by which individual units of source code, i.e. the smallest testable part of an application, are tested to determine whether they are fit for use.

In plugin development this usually would be methods or functions.

This article will cover

  • Installing XAMPP
  • Installing PHPUnit
  • Setting up unit tests in a WordPress plugin directory

Installing XAMPP and PHPUnit

This is the easiest part of this small tutorial. Head on over to Apache Friends and download a copy of the XAMPP installer. PHPUnit ships with XAMPP, so once installed, you have both installed. Follow the installation Wizard to set it up on your computer. The rest of the article assumes that XAMPP has been installed in c:/xampp. Next, add the XAMPP PHP directory to the path variable. The directory would be c./xampp/php. To verify that phpunit is properly installed, open up the command line and type

phpunit –version

 

The expected result would be

PHPUnit X.Y.Z by Sebastian Bergman

Set up the files needed to run plugin unit test

 

The rest of this article covers how to get and set up the files needed to run WP unit test.

Final directory setup:

  • phpunit.xml
  • tests
    • wordpress-tests-lib
      •  includes
        • <Files from WP unit test>
      • src
        • <Source of wordpress>
      • wp-tests-config.php
    • bootstap.php
    • test-*.php

Create the directory structure needed

All tests and associated files will be located inside the plugin folder. To start with, create a directory within your plugin called tests, and then a subdirectory called wordpress-tests-lib. Tests will be the main folder where all test cases will be located. WordPress-tests-lib will contain the libraries that we depend on to do WordPress unit tests. Lets start with those.

Get the unit test scripts from the WordPress development repository

The first thing needed is the scripts that are used to do WordPress unit tests. These are located in the development repository in the tests folder. To download the files, use the following subversion command.

svn co https://develop.svn.wordpress.org/tags/4.4.2/tests/phpunit/includes/ tests/wordpress-tests-lib

Also, get the config sample file, and store it in tests/wordpress-tests-lib as wp-tests-config.php. Replace the database info at the bottom with your own. Make sure that the database you provide is empty.

Setup PHPUnit to run tests

The first ting you need is the phpunit XML file that tells PHP unit where your tests and your scripts are. I reccomend getting a copy of the config file used by WP-CLI and store it as phpunit.xml in your plugin directory. The file points to a file called tests/bootstrap.php. This is a link to the file that bootstraps your plugin for testing. This file should look something like this.

<?php
require_once 'wordpress-tests-lib/includes/functions.php';
function _manually_load_plugin() {
    require dirname( dirname( __FILE__ ) ) . '/mainpluginfile.php';
}
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );

require_once 'wordpress-tests-lib/includes/bootstrap.php';
?>

Basically, what it does is that it required the WordPress test scripts and plugs the plugin into a hook to make sure it is loaded.

Write a test, and you are ready to go

All tests should be kept in files named test-SOMENAME.php in the tests folder. An example test would look like:

<?php

class SampleTest extends WP_UnitTestCase {

 function test_sample_true() {
 // replace this with some actual testing code
 $this->assertTrue( true );
 }

 function test_sample_false() {
 // replace this with some actual testing code
 $this->assertTrue( false );
 }
}

?>

Run the test by executing running phpunit in your plugin folder.

  Category: Random
  Comments: Comments Off on Get ready for WordPress Plugin unit testing with XAMPP and PHP Unit (Windows)

Inspect the internals of a Google Docs file

By kristoffer,

A few days ago, I released a  web app that I’ve called .gdoc Structure Viewer. The simple app lets you inspect the internals of any Google Docs file. It’s meant to be a tool for developers.

How does it work

The web app is pretty simple it is a tree-viewer of the elements within the Google Docs file. My current project had me converting gdoc to json format, and at some point I got tired of copy-pasting the json data into a tree-viewer. Anyways, I extended the script a bit and wrapped a web-app around it – and out came the .gdoc Structure Viewer. Hope that someone other than me find it useful when working with Docs in Google Apps Script.

Information

Video

 

  Category: Random
  Comments: Comments Off on Inspect the internals of a Google Docs file

There is no turning back now!

By kristoffer,

Hi there!

So, here we go – my site is finally up and running. It has taken some time. The reason why I’m doing this is that I am in the midst of publishing my first Google Docs add-on – Heading Numbering. One of the missing features in Google Docs has been a nice way to number headings. Well, there are add-ons that can do this for you, but I’m not too impressed by them. As soon as the add-on revision process is finished you’ll be able to easily add any custom numbering style to your Google Documents. It’s awesome – I know.

  Category: Random
  Comments: Comments Off on There is no turning back now!