Diff
Property changes:
Name: svk:merge
- d6e91ea2-e33a-0410-98df-1d493bd67c58:/:183
+ d6e91ea2-e33a-0410-98df-1d493bd67c58:/:184
Copied: branches/0.2.0/src/PHPSpec/Matcher/Match.php (from rev 179, branches/0.2.0/src/PHPSpec/Matcher/BeNull.php) (0 => 184)
--- branches/0.2.0/src/PHPSpec/Matcher/Match.php (rev 0)
+++ branches/0.2.0/src/PHPSpec/Matcher/Match.php 2008-01-10 11:38:54 UTC (rev 184)
@@ -0,0 +1,59 @@
+<?php
+/**
+ * PHPSpec
+ *
+ * LICENSE
+ *
+ * This file is subject to the GNU Lesser General Public License Version 3
+ * that is bundled with this package in the file LICENSE.
+ * It is also available through the world-wide-web at this URL:
+ * http://www.gnu.org/licenses/lgpl-3.0.txt
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to lic...@phpspec.org so we can send you a copy immediately.
+ *
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007 P\xE1draic Brady, Travis Swicegood
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+
+/**
+ * @category PHPSpec
+ * @package PHPSpec
+ * @copyright Copyright (c) 2007 P\xE1draic Brady, Travis Swicegood
+ * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public Licence Version 3
+ */
+class PHPSpec_Matcher_Match implements PHPSpec_Matcher_Interface
+{
+
+ protected $_expected = null;
+
+ protected $_actual = null;
+
+ public function __construct($expected)
+ {
+ $this->_expected = $expected;
+ }
+
+ public function matches($actual)
+ {
+ $this->_actual = $actual;
+ return (bool) preg_match($this->_expected, $this->_actual);
+ }
+
+ public function getFailureMessage()
+ {
+ return 'expected match for ' . strval($this->_expected) . ' PCRE regular expression, got ' . strval($this->_actual) . ' (using match())';
+ }
+
+ public function getNegativeFailureMessage()
+ {
+ return 'expected no match for ' . strval($this->_expected) . ' PCRE regular expression, got ' . strval($this->_actual) . ' (using match())';
+ }
+
+ public function getDescription()
+ {
+ return 'match ' . strval($this->_expected) . ' PCRE regular expression';
+ }
+}
\ No newline at end of file
Modified: branches/0.2.0/src/PHPSpec/Specification.php (183 => 184)
--- branches/0.2.0/src/PHPSpec/Specification.php 2008-01-09 20:17:20 UTC (rev 183)
+++ branches/0.2.0/src/PHPSpec/Specification.php 2008-01-10 11:38:54 UTC (rev 184)
@@ -122,7 +122,7 @@
// check for Matcher references
$matchers = array(
- 'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo'
+ 'equal', 'be', 'beEqualTo', 'beAnInstanceOf', 'beGreaterThan', 'beTrue', 'beFalse', 'beEmpty', 'beLessThan', 'beGreaterThanOrEqualTo', 'beLessThanOrEqualTo', 'beSet', 'beNull', 'beOfType', 'beIdenticalTo', 'match'
);
if (in_array($method, $matchers)) {
$this->setExpectedValue(array_shift($args));
Copied: branches/0.2.0/tests/Matcher/Match (from rev 179, branches/0.2.0/tests/Matcher/BeNull)
Modified: branches/0.2.0/tests/Matcher/Match/it-should-return-a-description-with-expected-value.phpt (179 => 184)
--- branches/0.2.0/tests/Matcher/BeNull/it-should-return-a-description-with-expected-value.phpt 2008-01-09 14:36:15 UTC (rev 179)
+++ branches/0.2.0/tests/Matcher/Match/it-should-return-a-description-with-expected-value.phpt 2008-01-10 11:38:54 UTC (rev 184)
@@ -4,10 +4,10 @@
<?php
require_once dirname(__FILE__) . '/../../_setup.inc';
-$null = new PHPSpec_Matcher_BeNull(null);
-$null->matches(null);
-echo $null->getDescription();
+$match = new PHPSpec_Matcher_Match("/bar/");
+$match->matches('bar');
+echo $match->getDescription();
?>
--EXPECT--
-be NULL
\ No newline at end of file
+match /bar/ PCRE regular expression
\ No newline at end of file
Modified: branches/0.2.0/tests/Matcher/Match/it-should-return-a-meaningful-failure-message-if-requested.phpt (179 => 184)
--- branches/0.2.0/tests/Matcher/BeNull/it-should-return-a-meaningful-failure-message-if-requested.phpt 2008-01-09 14:36:15 UTC (rev 179)
+++ branches/0.2.0/tests/Matcher/Match/it-should-return-a-meaningful-failure-message-if-requested.phpt 2008-01-10 11:38:54 UTC (rev 184)
@@ -4,10 +4,10 @@
<?php
require_once dirname(__FILE__) . '/../../_setup.inc';
-$null = new PHPSpec_Matcher_BeNull(null);
-$null->matches(1);
-echo $null->getFailureMessage();
+$match = new PHPSpec_Matcher_Match("/bar/");
+$match->matches('foo');
+echo $match->getFailureMessage();
?>
--EXPECT--
-expected to be NULL, got 1 (using beNull())
\ No newline at end of file
+expected match for /bar/ PCRE regular expression, got foo (using match())
\ No newline at end of file
Modified: branches/0.2.0/tests/Matcher/Match/it-should-return-a-meaningful-negative-failure-message-if-requested.phpt (179 => 184)
--- branches/0.2.0/tests/Matcher/BeNull/it-should-return-a-meaningful-negative-failure-message-if-requested.phpt 2008-01-09 14:36:15 UTC (rev 179)
+++ branches/0.2.0/tests/Matcher/Match/it-should-return-a-meaningful-negative-failure-message-if-requested.phpt 2008-01-10 11:38:54 UTC (rev 184)
@@ -4,11 +4,11 @@
<?php
require_once dirname(__FILE__) . '/../../_setup.inc';
-$null = new PHPSpec_Matcher_BeNull(null);
-$null->matches(1);
+$null = new PHPSpec_Matcher_Match("/bar/");
+$null->matches("bar");
assert('
$null->getNegativeFailureMessage()
- == "expected not to be NULL (using beNull())"
+ == "expected no match for /bar/ PCRE regular expression, got bar (using match())"
');
?>
Modified: branches/0.2.0/tests/Matcher/Match/it-should-return-false-on-mismatch.phpt (179 => 184)
--- branches/0.2.0/tests/Matcher/BeNull/it-should-return-false-on-mismatch.phpt 2008-01-09 14:36:15 UTC (rev 179)
+++ branches/0.2.0/tests/Matcher/Match/it-should-return-false-on-mismatch.phpt 2008-01-10 11:38:54 UTC (rev 184)
@@ -1,11 +1,11 @@
--TEST--
-Should return FALSE if actual value is not a boolean FALSE
+Should return FALSE if actual value does not match given regex
--FILE--
<?php
require_once dirname(__FILE__) . '/../../_setup.inc';
-$null = new PHPSpec_Matcher_BeNull(null);
-assert('!$null->matches(1)');
+$match = new PHPSpec_Matcher_Match("/php/");
+assert('!$match->matches("ruby")');
?>
===DONE===
Modified: branches/0.2.0/tests/Matcher/Match/it-should-return-true-on-match.phpt (179 => 184)
--- branches/0.2.0/tests/Matcher/BeNull/it-should-return-true-on-match.phpt 2008-01-09 14:36:15 UTC (rev 179)
+++ branches/0.2.0/tests/Matcher/Match/it-should-return-true-on-match.phpt 2008-01-10 11:38:54 UTC (rev 184)
@@ -1,11 +1,11 @@
--TEST--
-Should return TRUE if actual value is NULL
+Should return TRUE if actual value matches given regex
--FILE--
<?php
require_once dirname(__FILE__) . '/../../_setup.inc';
-$null = new PHPSpec_Matcher_BeNull(null);
-assert('$null->matches(null)');
+$match = new PHPSpec_Matcher_Match("/^php/i");
+assert('$match->matches("PHP5 On Steroids")');
?>
===DONE===