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.
- Host: GitHub
- URL: https://github.com/v2e4lisp/preview
- Owner: v2e4lisp
- Created: 2013-11-03T09:24:19.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-01-21T12:46:01.000Z (over 9 years ago)
- Last Synced: 2025-07-23T18:01:41.650Z (11 months ago)
- Language: PHP
- Homepage:
- Size: 609 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Preview
[](http://waffle.io/v2e4lisp/preview)
[](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)