dev-master 2014-08-04 01:14 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:20:38 UTC


README

pecs 是一个针对 PHP 5.3 的小型行为驱动开发库,类似于 RSpecJSpec

使用传统示例,它的工作方式如下

require "lib/pecs.php";
require "bowling.php";

describe("Bowling", function() {
  it("should score 0 for a gutter game", function() {
    $bowling = new Bowling();
    for ($i=0; $i < 20; $i++) {
      $bowling->hit(0);
    }
    expect($bowling->score)->to_equal(0);
  });

  it("should get drinks for free just for being here", function() {
    $bowling = new Bowling();
    expect($bowling->score)->to_equal(42);
  });
});

\pecs\run();

输出看起来像这样

$ php test_bowling.php

Bowling
- should score 0 for a gutter game: pass
- should get drinks for free just for being here: fail

FAILURE:
expected 0 to equal 42
  #0 .../lib/pecs.php(32): pecs\Expect->assert('_equal', Array, true)
  #1 [internal function]: pecs\Expect->__call('to_equal', Array)
  #2 .../test_bowling.php(15): pecs\Expect->to_equal(42)
  #3 .../lib/pecs.php(221): {closure}()
  #4 .../lib/pecs.php(192): pecs\Spec->run()
  #5 .../lib/pecs.php(195): pecs\Suite->run()
  #6 .../lib/pecs.php(195): pecs\Suite->run()
  #7 .../lib/pecs.php(262): pecs\Suite->run()
  #8 .../lib/pecs.php(350): pecs\Runner->run(NULL)
  #9 .../test_bowling.php(19): pecs\run()
  #10 {main}

Finished in 0.0017 seconds

Passed: 1 Failed: 1

致谢

pecs 受 JSpec 的无语法语法极大启发,并因此被编写出来,因为我不想在 PHP 和 JSpec 测试之间切换时需要太多转换。

贡献者

待办事项

  • 添加 beforeafter 钩子
  • 需要添加更多匹配器
  • 需要改进失败输出

许可证

(MIT 许可证)

版权所有 ©2009 noonat

在此特此授予任何获得此软件和相关文档副本(“软件”)的人免费使用该软件的权利,不受限制地处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许向软件提供的人按以下条件这样做:

上述版权声明和本许可声明应包含在软件的所有副本或实质性部分的副本中。

本软件按“原样”提供,不提供任何明示或暗示的保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论该索赔、损害或其他责任是基于合同、侵权或其他方式引起的,无论该索赔、损害或其他责任是否与软件或软件的使用或其他方式有关。