2017 © Pedro Peláez
 

library phew

BDD-style unit testing framework

image

janvoracek/phew

BDD-style unit testing framework

  • Friday, August 22, 2014
  • by JanVoracek
  • Repository
  • 1 Watchers
  • 0 Stars
  • 2 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Phew

Phew is Jasmine-like testing framework for PHP. For now it's in exploring stage., (*1)

The goal of this project is to write tests as easily as in Jasmine., (*2)

Build Status, (*3)

Code Sample

<?php
describe('Phew', function () {
    it('should be easy to write PHP tests', function () {
        expect('writing PHP tests')->not->toBe('difficult');
    });
});

Installation

It is highly recommended to install Phew using Composer - http://getcomposer.org/., (*4)

Run following commands:, (*5)

$ composer global require janvoracek/phew:dev-master

Try to run phew. If the command is not found, you have to add $HOME/.composer/vendor/bin (Mac) or %APPDATA%/Composer/bin (Win) to your PATH., (*6)

Specs

Phew is designed to be as similar as possible to Jasmine. The biggest differences are caused by differences between PHP and JS:, (*7)

  • Different object operator. JS uses "dot" (.), PHP uses "arrow" (->).
  • The use statement for closures. It makes the tests looking not so good. Deal with it :)

Matchers

There is for now only basic set of matchers:, (*8)

Strict equality matchers

  • toBe
  • toBeNull
  • toBeTrue
  • toBeFalse

Loose equality matchers

  • toEqual
  • toBeEmpty
  • toBeTruthy
  • toBeFalsy

Type matchers

  • toBeA
  • toBeAn (alias of toBeA)
  • toBeInstanceOf (alias of toBeA)
  • toImplement (alias of toBeA)

String matchers

  • toStartsWith
  • toMatch

Custom matchers

It is quiet simple to add custom matcher. Your matcher have to implement the Phew\Matchers\Matcher interface and you have to register it., (*9)

Sample matcher:, (*10)

class GreaterThanMatcher implements Matcher {

    /** @var number */
    private $minimum;
    /** @var number */
    private $actual;

    public function __construct($minimum = null) {
        $this->minimum = $minimum;
    }

    public function matches($actual) {
        $this->actual = $actual;
        return $actual > $this->minimum;
    }

    public function getFailureMessage() {
        return "Expected {$this->actual} to be greater than {$this->minimum}";
    }

    public function getNegativeFailureMessage() {
        return "Expected {$this->actual} not to be greater than {$this->minimum}";
    }
}

Registering:, (*11)

\Phew\Expectations\Expectation::addMatcher('toBeGreaterThan', 'GreaterThanMatcher');

Copyright (c) 2013 Jan Voracek. This software is licensed under the MIT License., (*12)

The Versions

22/08 2014

dev-master

9999999-dev https://github.com/JanVoracek/phew/

BDD-style unit testing framework

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Avatar JanVoracek

bdd test framework unit jasmine phew