not constraint
This commit is contained in:
parent
f829192408
commit
bcb701eee5
@ -10,8 +10,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
public static function equals($expected, $actual, $message = '') {
|
||||
self::evaluate(new EqualsConstraint($expected, $actual), $message);
|
||||
protected static function negate(Constraint $constraint) {
|
||||
return new NotConstraint($constraint);
|
||||
}
|
||||
|
||||
public static function equal($expected, $actual, $message = '') {
|
||||
self::evaluate(new EqualConstraint($expected, $actual), $message);
|
||||
}
|
||||
|
||||
public static function notEqual($expected, $actual, $message = '') {
|
||||
self::evaluate(self::negate(new EqualConstraint($expected, $actual)), $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,28 +1,12 @@
|
||||
<?php
|
||||
|
||||
abstract class Constraint {
|
||||
interface Constraint {
|
||||
|
||||
protected $expected;
|
||||
protected $actual;
|
||||
public function fail($message = '');
|
||||
|
||||
public function __construct($expected, $actual) {
|
||||
$this->expected = $expected;
|
||||
$this->actual = $actual;
|
||||
}
|
||||
public function toString($message);
|
||||
|
||||
public function fail($message = '') {
|
||||
throw new FailedTest($this->toString($message));
|
||||
}
|
||||
|
||||
public final function toString($message) {
|
||||
$message = !empty($message) ? $message . "\n" : '';
|
||||
$message .= "Failed asserting that\n" . $this->getFailureMessage();
|
||||
return $message;
|
||||
}
|
||||
|
||||
public abstract function evaluate();
|
||||
|
||||
protected abstract function getFailureMessage();
|
||||
public function evaluate();
|
||||
|
||||
}
|
||||
|
||||
|
27
src/TUnit/framework/constraints/DefaultConstraint.php
Normal file
27
src/TUnit/framework/constraints/DefaultConstraint.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
abstract class DefaultConstraint implements Constraint {
|
||||
|
||||
protected $expected;
|
||||
protected $actual;
|
||||
|
||||
public function __construct($expected, $actual) {
|
||||
$this->expected = $expected;
|
||||
$this->actual = $actual;
|
||||
}
|
||||
|
||||
public function fail($message = '') {
|
||||
throw new FailedTest($this->toString($message));
|
||||
}
|
||||
|
||||
public function toString($message) {
|
||||
$message = !empty($message) ? $message . "\n" : '';
|
||||
$message .= "Failed asserting that\n" . $this->getFailureMessage();
|
||||
return $message;
|
||||
}
|
||||
|
||||
protected abstract function getFailureMessage();
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class EqualsConstraint extends Constraint {
|
||||
class EqualConstraint extends DefaultConstraint {
|
||||
|
||||
public function evaluate() {
|
||||
return $this->expected == $this->actual;
|
37
src/TUnit/framework/constraints/NotConstraint.php
Normal file
37
src/TUnit/framework/constraints/NotConstraint.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class NotConstraint implements Constraint {
|
||||
|
||||
protected $constraint;
|
||||
|
||||
public function __construct(Constraint $constraint) {
|
||||
$this->constraint = $constraint;
|
||||
}
|
||||
|
||||
public function fail($message = '') {
|
||||
throw new FailedTest($this->toString($message));
|
||||
}
|
||||
|
||||
public function evaluate() {
|
||||
return !$this->constraint->evaluate();
|
||||
}
|
||||
|
||||
public function toString($message) {
|
||||
return $this->negateString($constraint->toString($message));
|
||||
}
|
||||
|
||||
protected function negateString($string) {
|
||||
return str_replace(
|
||||
array(
|
||||
' is '
|
||||
),
|
||||
array(
|
||||
' is not '
|
||||
),
|
||||
$string
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* Autoload manifest
|
||||
*
|
||||
* Autogenerated by manifester.php on 2009-06-13 17:17:25
|
||||
* Autogenerated by manifester.php on 2009-06-13 17:44:11
|
||||
*
|
||||
* @package TUnit
|
||||
* @version 0.1.0
|
||||
@ -19,13 +19,15 @@
|
||||
'CombinedTestResult' => 'TUnit/framework/result/CombinedTestResult.php',
|
||||
'ConsoleListener' => 'TUnit/framework/listeners/ConsoleListener.php',
|
||||
'Constraint' => 'TUnit/framework/constraints/Constraint.php',
|
||||
'EqualsConstraint' => 'TUnit/framework/constraints/EqualsConstraint.php',
|
||||
'DefaultConstraint' => 'TUnit/framework/constraints/DefaultConstraint.php',
|
||||
'EqualConstraint' => 'TUnit/framework/constraints/EqualConstraint.php',
|
||||
'ErredTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'ErredTestResult' => 'TUnit/framework/result/ErredTestResult.php',
|
||||
'FailedTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'FailedTestResult' => 'TUnit/framework/result/FailedTestResult.php',
|
||||
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
|
||||
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
|
||||
'NotConstraint' => 'TUnit/framework/constraints/NotConstraint.php',
|
||||
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
|
||||
'Product' => 'TUnit/util/Product.php',
|
||||
'RecursiveTestIterator' => 'TUnit/util/RecursiveTestIterator.php',
|
||||
|
@ -4,7 +4,6 @@
|
||||
require_once dirname(dirname(__FILE__)) . '/bootstrap.php';
|
||||
|
||||
$switches = new CliSwitchCollection();
|
||||
//$switches->AddSwitch(new CliSwitch('ini-directive', 'd', false, 'key="value"', 'php.ini directives'))
|
||||
|
||||
array_shift($argv);
|
||||
$args = Cli::parseArgs($argv, $switches);
|
||||
|
Loading…
Reference in New Issue
Block a user