An open API service indexing awesome lists of open source software.

https://github.com/v2e4lisp/preview

mocha.js and rspec inspired php bdd test framework.
https://github.com/v2e4lisp/preview

Last synced: 8 months ago
JSON representation

mocha.js and rspec inspired php bdd test framework.

Awesome Lists containing this project

README

          

# Preview
[![Stories in Ready](https://badge.waffle.io/v2e4lisp/preview.png?label=ready)](http://waffle.io/v2e4lisp/preview)
[![Build Status](https://travis-ci.org/v2e4lisp/preview.png?branch=master)](https://travis-ci.org/v2e4lisp/preview)

BDD test for php.

Heavily inspired by [mocha.js](http://mochajs.org/)
and [Rspec](https://github.com/rspec)

## [Document](./docs)

## Sample Code
### BDD rspec-like syntax
```php
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
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
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
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](https://github.com/marco-fiset/Testify.php)
```php
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)