2017 © Pedro Peláez
 

library phut

A small and simple unit testing framework for PHP 5.3+

image

klei/phut

A small and simple unit testing framework for PHP 5.3+

  • Monday, September 3, 2012
  • by klei
  • Repository
  • 3 Watchers
  • 3 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Phut

Phut is a small unit test framework for PHP 5.3+, inspired by NUnit, (*1)

Build status

What is Phut

Phunit is a PHP Unit Test framework which uses annotations to mimic the behavior of NUnit for .Net., (*2)

Why another unit testing framework?

I was tired searching for a unit testing framework for PHP that:, (*3)

  • Fully supports namespaces
  • Is easy to setup
  • Works on Windows without a hassle

So finally, when I didn't find a single framework that did all of the above, I decided to do it myself., (*4)

Installation

You can install Phut using one of the following methods., (*5)

Using Composer

One simple way to install Phut is to use Composer. First create or modify your composer.json file in the project root to include:, (*6)

{
    "require": {
        "klei/phut": "*"
    },
    "config": {
        "bin-dir": "bin/"
    }
}

Then download composer.phar from http://getcomposer.org/ and run:, (*7)

php composer.phar install

Or using git

You could also clone the Phut repository with:, (*8)

git clone git://github.com/klei-dev/phut.git

Then download composer.phar as above and execute the following:, (*9)

php composer.phar install

Writing your first test

As mentioned above Phut uses annotations to work. The name of the annotations is directly inspired by the NUnit framework for .Net. I.e. a test class must be annotated with @TestFixture and each test with @Test., (*10)

A simple test could therefore look like this:, (*11)

<?php
use Klei\Phut\TestFixture;
use Klei\Phut\Test;
use Klei\Phut\Assert;

/**
 * @TestFixture
 */
class MyFirstTests {
    /**
     * @Test
     */
    public function MultiplyOperator_Multiply2by4_ShouldGive8()
    {
        // Given
        $number1 = 2;
        $number2 = 4;

        // When
        $result = $number1 * $number2;

        // Then
        Assert::areIdentical($result, 8);
    }
}

You can then run your test with the command:, (*12)

bin/phut [<test-folder-name>|<test-file-name>]

If no folder (<test-folder-name>) or file (<test-file-name>) is specified, the runner defaults to the folder tests/., (*13)

The future for Phut

Stuff for future releases:, (*14)

  • More extensive Assert-class
  • @TestCase annotation to write parameterized tests
  • Optional Category parameter for the @Test annotation to be able to categorize tests and run only certain categories

Copyright © 2012, Joakim Bengtson. See LICENSE., (*15)

Questions?

You can find me here at GitHub and via twitter at @joakimbeng., (*16)

The Versions

03/09 2012

dev-develop

dev-develop http://klei.se/phut

A small and simple unit testing framework for PHP 5.3+

  Sources   Download

MIT

The Requires

 

tdd testing unit test

08/08 2012

dev-master

9999999-dev http://klei.se/phut

A small and simple unit testing framework for PHP 5.3+

  Sources   Download

MIT

The Requires

 

tdd testing unit test

19/06 2012

v0.1.0

0.1.0.0 http://klei.se/phut

A small and simple unit testing framework for PHP 5.3+

  Sources   Download

MIT

The Requires

 

tdd testing unit test