Code Monkey home page Code Monkey logo

phut's Introduction

Phut

Phut is a small unit test framework for PHP 5.3+, inspired by NUnit

Build status

What is Phut

Phunit is a PHP Unit Test framework which uses annotations to mimic the behavior of NUnit for .Net.

Why another unit testing framework?

I was tired searching for a unit testing framework for PHP that:

  • 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.

Installation

You can install Phut using one of the following methods.

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:

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

Then download composer.phar from http://getcomposer.org/ and run:

php composer.phar install

Or using git

You could also clone the Phut repository with:

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

Then download composer.phar as above and execute the following:

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.

A simple test could therefore look like this:

<?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:

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/.

The future for Phut

Stuff for future releases:

  • 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

Copyright © 2012, Joakim Bengtson. See LICENSE.

Questions?

You can find me here at GitHub and via twitter at @joakimbeng.

phut's People

Contributors

joakimbeng avatar jeichorn avatar

Stargazers

Peter avatar  avatar

Watchers

James Cloos avatar Peter avatar Jean-Philippe Ricard avatar  avatar

Forkers

jeichorn

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.