2017 © Pedro Peláez
 

library preview

mocha.js like bdd test framework

image

v2e4lisp/preview

mocha.js like bdd test framework

  • Saturday, January 21, 2017
  • by wenjun.yan
  • Repository
  • 3 Watchers
  • 5 Stars
  • 901 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 5 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

Preview

Stories in Ready Build Status, (*1)

BDD test for php., (*2)

Heavily inspired by mocha.js and Rspec, (*3)

Document

Sample Code

BDD rspec-like syntax

<?php
namespace Preview\DSL\BDD;

require_once 'stack.php';
require_once __DIR__.'/../ok.php';

describe("Stack", function () {
    before_each(function () {
        $this->stack = new \Stack(array(1,2,3));
    });

    describe("#size", function () {
        it("returns the size of stack", function () {
            ok($this->stack->size() == 3);
        });
    });

    describe("#peek", function () {
        it("returns the last element", function () {
            ok($this->stack->peek() == 3);
        });
    });

    describe("#push", function () {
        it("pushes an element to stack", function () {
            $this->stack->push(4);
            ok($this->stack->peek() == 4);
            ok($this->stack->size() == 4);
        });
    });

    describe("#pop", function () {
        it("pops out the last element", function () {
            ok($this->stack->pop() == 3);
            ok($this->stack->size() == 2);
        });
    });
});

TDD is aliases for bdd

<?php
namespace Preview\DSL\TDD;

require_once 'stack.php';
require_once __DIR__.'/../ok.php';

suite("Stack", function () {
    setup(function () {
        $this->stack = new \Stack(array(1,2,3));
    });

    suite("#size", function () {
        test("returns the size of stack", function () {
            ok($this->stack->size() == 3);
        });
    });

    suite("#peek", function () {
        test("returns the last element", function () {
            ok($this->stack->peek() == 3);
        });
    });

    suite("#push", function () {
        test("pushes an element to stack", function () {
            $this->stack->push(4);
            ok($this->stack->peek() == 4);
            ok($this->stack->size() == 4);
        });
    });

    suite("#pop", function () {
        test("pops out the last element", function () {
            ok($this->stack->pop() == 3);
            ok($this->stack->size() == 2);
        });
    });
});

Qunit for simple test

<?php
namespace Preview\DSL\Qunit;

require_once 'stack.php';
require_once __DIR__.'/../ok.php';

suite("Stack");

setup(function () {
    $this->stack = new \Stack(array(1,2,3));
});

test("#size returns the size of stack", function () {
    ok($this->stack->size() == 3);
});

test("#peek eturns the last element", function () {
    ok($this->stack->peek() == 3);
});

test("#push pushes an element to stack", function () {
    $this->stack->push(4);
    ok($this->stack->peek() == 4);
    ok($this->stack->size() == 4);
});

test("#pop pops out the last element", function () {
    ok($this->stack->pop() == 3);
    ok($this->stack->size() == 2);
});

Export an array of tests.

<?php
namespace Preview\DSL\Export;

require_once 'stack.php';
require_once __DIR__.'/../ok.php';

$suite = array(
    "before each" => function () {
        $this->stack = new \Stack(array(1,2,3));
    },

    "#sizereturns the size of stack" => function () {
        ok($this->stack->size() == 3);
    },

    "#peek eturns the last element" => function () {
        ok($this->stack->peek() == 3);
    },

    "#push pushes an element to stack" => function () {
        $this->stack->push(4);
        ok($this->stack->peek() == 4);
        ok($this->stack->size() == 4);
    },

    "#pop pops out the last element" => function () {
        ok($this->stack->pop() == 3);
        ok($this->stack->size() == 2);
    }
);

export("Stack", $suite);

Testify syntax from this repo

<?php
namespace Preview\DSL\Testify;

require_once 'stack.php';
require_once __DIR__.'/../ok.php';

$suite = new Suite("Stack[testify]");

$suite->before_each(function () {
    $this->stack = new \Stack(array(1,2,3));

})->test("#size returns the size of stack", function () {
    ok($this->stack->size() == 3);

})->test("#peek eturns the last element", function () {
    ok($this->stack->peek() == 3);

})->test("#push pushes an element to stack", function () {
    $this->stack->push(4);
    ok($this->stack->peek() == 4);
    ok($this->stack->size() == 4);

})->test("#pop pops out the last element", function () {
    ok($this->stack->pop() == 3);
    ok($this->stack->size() == 2);

})->load();

Contributors

  • Yan Wenjun(@v2e4lisp)
  • Noritaka Horio(@holyshared)

The Versions

21/01 2017

dev-master

9999999-dev https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js

15/03 2014

2.0

2.0.0.0 https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js

24/02 2014

dev-develop

dev-develop https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js

24/02 2014

1.1.2

1.1.2.0 https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js

23/02 2014

1.1.1

1.1.1.0 https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js

25/01 2014

1.1.0

1.1.0.0 https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js

18/01 2014

1.0.0

1.0.0.0 https://github.com/v2e4lisp/preview

mocha.js like bdd test framework

  Sources   Download

MIT

The Requires

 

bdd tdd test rspec mocha.js