PageRenderTime 42ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/simpletest/expectation.php

https://github.com/quarkness/piwik
PHP | 898 lines | 333 code | 78 blank | 487 comment | 32 complexity | 051ba423d3afa7e0cb0041255ba3b6cf MD5 | raw file
  1. <?php
  2. /**
  3. * base include file for SimpleTest
  4. * @package SimpleTest
  5. * @subpackage UnitTester
  6. * @version $Id: expectation.php 1723 2008-04-08 00:34:10Z lastcraft $
  7. */
  8. /**#@+
  9. * include other SimpleTest class files
  10. */
  11. require_once(dirname(__FILE__) . '/dumper.php');
  12. require_once(dirname(__FILE__) . '/compatibility.php');
  13. /**#@-*/
  14. /**
  15. * Assertion that can display failure information.
  16. * Also includes various helper methods.
  17. * @package SimpleTest
  18. * @subpackage UnitTester
  19. * @abstract
  20. */
  21. class SimpleExpectation {
  22. var $_dumper = false;
  23. var $_message;
  24. /**
  25. * Creates a dumper for displaying values and sets
  26. * the test message.
  27. * @param string $message Customised message on failure.
  28. */
  29. function SimpleExpectation($message = '%s') {
  30. $this->_message = $message;
  31. }
  32. /**
  33. * Tests the expectation. True if correct.
  34. * @param mixed $compare Comparison value.
  35. * @return boolean True if correct.
  36. * @access public
  37. * @abstract
  38. */
  39. function test($compare) {
  40. }
  41. /**
  42. * Returns a human readable test message.
  43. * @param mixed $compare Comparison value.
  44. * @return string Description of success
  45. * or failure.
  46. * @access public
  47. * @abstract
  48. */
  49. function testMessage($compare) {
  50. }
  51. /**
  52. * Overlays the generated message onto the stored user
  53. * message. An additional message can be interjected.
  54. * @param mixed $compare Comparison value.
  55. * @param SimpleDumper $dumper For formatting the results.
  56. * @return string Description of success
  57. * or failure.
  58. * @access public
  59. */
  60. function overlayMessage($compare, $dumper) {
  61. $this->_dumper = $dumper;
  62. return sprintf($this->_message, $this->testMessage($compare));
  63. }
  64. /**
  65. * Accessor for the dumper.
  66. * @return SimpleDumper Current value dumper.
  67. * @access protected
  68. */
  69. function &_getDumper() {
  70. if (! $this->_dumper) {
  71. $dumper = new SimpleDumper();
  72. return $dumper;
  73. }
  74. return $this->_dumper;
  75. }
  76. /**
  77. * Test to see if a value is an expectation object.
  78. * A useful utility method.
  79. * @param mixed $expectation Hopefully an Epectation
  80. * class.
  81. * @return boolean True if descended from
  82. * this class.
  83. * @access public
  84. * @static
  85. */
  86. function isExpectation($expectation) {
  87. return is_object($expectation) &&
  88. SimpleTestCompatibility::isA($expectation, 'SimpleExpectation');
  89. }
  90. }
  91. /**
  92. * A wildcard expectation always matches.
  93. * @package SimpleTest
  94. * @subpackage MockObjects
  95. */
  96. class AnythingExpectation extends SimpleExpectation {
  97. /**
  98. * Tests the expectation. Always true.
  99. * @param mixed $compare Ignored.
  100. * @return boolean True.
  101. * @access public
  102. */
  103. function test($compare) {
  104. return true;
  105. }
  106. /**
  107. * Returns a human readable test message.
  108. * @param mixed $compare Comparison value.
  109. * @return string Description of success
  110. * or failure.
  111. * @access public
  112. */
  113. function testMessage($compare) {
  114. $dumper = &$this->_getDumper();
  115. return 'Anything always matches [' . $dumper->describeValue($compare) . ']';
  116. }
  117. }
  118. /**
  119. * An expectation that never matches.
  120. * @package SimpleTest
  121. * @subpackage MockObjects
  122. */
  123. class FailedExpectation extends SimpleExpectation {
  124. /**
  125. * Tests the expectation. Always false.
  126. * @param mixed $compare Ignored.
  127. * @return boolean True.
  128. * @access public
  129. */
  130. function test($compare) {
  131. return false;
  132. }
  133. /**
  134. * Returns a human readable test message.
  135. * @param mixed $compare Comparison value.
  136. * @return string Description of failure.
  137. * @access public
  138. */
  139. function testMessage($compare) {
  140. $dumper = &$this->_getDumper();
  141. return 'Failed expectation never matches [' . $dumper->describeValue($compare) . ']';
  142. }
  143. }
  144. /**
  145. * An expectation that passes on boolean true.
  146. * @package SimpleTest
  147. * @subpackage MockObjects
  148. */
  149. class TrueExpectation extends SimpleExpectation {
  150. /**
  151. * Tests the expectation.
  152. * @param mixed $compare Should be true.
  153. * @return boolean True on match.
  154. * @access public
  155. */
  156. function test($compare) {
  157. return (boolean)$compare;
  158. }
  159. /**
  160. * Returns a human readable test message.
  161. * @param mixed $compare Comparison value.
  162. * @return string Description of success
  163. * or failure.
  164. * @access public
  165. */
  166. function testMessage($compare) {
  167. $dumper = &$this->_getDumper();
  168. return 'Expected true, got [' . $dumper->describeValue($compare) . ']';
  169. }
  170. }
  171. /**
  172. * An expectation that passes on boolean false.
  173. * @package SimpleTest
  174. * @subpackage MockObjects
  175. */
  176. class FalseExpectation extends SimpleExpectation {
  177. /**
  178. * Tests the expectation.
  179. * @param mixed $compare Should be false.
  180. * @return boolean True on match.
  181. * @access public
  182. */
  183. function test($compare) {
  184. return ! (boolean)$compare;
  185. }
  186. /**
  187. * Returns a human readable test message.
  188. * @param mixed $compare Comparison value.
  189. * @return string Description of success
  190. * or failure.
  191. * @access public
  192. */
  193. function testMessage($compare) {
  194. $dumper = &$this->_getDumper();
  195. return 'Expected false, got [' . $dumper->describeValue($compare) . ']';
  196. }
  197. }
  198. /**
  199. * Test for equality.
  200. * @package SimpleTest
  201. * @subpackage UnitTester
  202. */
  203. class EqualExpectation extends SimpleExpectation {
  204. var $_value;
  205. /**
  206. * Sets the value to compare against.
  207. * @param mixed $value Test value to match.
  208. * @param string $message Customised message on failure.
  209. * @access public
  210. */
  211. function EqualExpectation($value, $message = '%s') {
  212. $this->SimpleExpectation($message);
  213. $this->_value = $value;
  214. }
  215. /**
  216. * Tests the expectation. True if it matches the
  217. * held value.
  218. * @param mixed $compare Comparison value.
  219. * @return boolean True if correct.
  220. * @access public
  221. */
  222. function test($compare) {
  223. return (($this->_value == $compare) && ($compare == $this->_value));
  224. }
  225. /**
  226. * Returns a human readable test message.
  227. * @param mixed $compare Comparison value.
  228. * @return string Description of success
  229. * or failure.
  230. * @access public
  231. */
  232. function testMessage($compare) {
  233. if ($this->test($compare)) {
  234. return "Equal expectation [" . $this->_dumper->describeValue($this->_value) . "]";
  235. } else {
  236. return "Equal expectation fails " .
  237. $this->_dumper->describeDifference($this->_value, $compare);
  238. }
  239. }
  240. /**
  241. * Accessor for comparison value.
  242. * @return mixed Held value to compare with.
  243. * @access protected
  244. */
  245. function _getValue() {
  246. return $this->_value;
  247. }
  248. }
  249. /**
  250. * Test for inequality.
  251. * @package SimpleTest
  252. * @subpackage UnitTester
  253. */
  254. class NotEqualExpectation extends EqualExpectation {
  255. /**
  256. * Sets the value to compare against.
  257. * @param mixed $value Test value to match.
  258. * @param string $message Customised message on failure.
  259. * @access public
  260. */
  261. function NotEqualExpectation($value, $message = '%s') {
  262. $this->EqualExpectation($value, $message);
  263. }
  264. /**
  265. * Tests the expectation. True if it differs from the
  266. * held value.
  267. * @param mixed $compare Comparison value.
  268. * @return boolean True if correct.
  269. * @access public
  270. */
  271. function test($compare) {
  272. return ! parent::test($compare);
  273. }
  274. /**
  275. * Returns a human readable test message.
  276. * @param mixed $compare Comparison value.
  277. * @return string Description of success
  278. * or failure.
  279. * @access public
  280. */
  281. function testMessage($compare) {
  282. $dumper = &$this->_getDumper();
  283. if ($this->test($compare)) {
  284. return "Not equal expectation passes " .
  285. $dumper->describeDifference($this->_getValue(), $compare);
  286. } else {
  287. return "Not equal expectation fails [" .
  288. $dumper->describeValue($this->_getValue()) .
  289. "] matches";
  290. }
  291. }
  292. }
  293. /**
  294. * Test for being within a range.
  295. * @package SimpleTest
  296. * @subpackage UnitTester
  297. */
  298. class WithinMarginExpectation extends SimpleExpectation {
  299. var $_upper;
  300. var $_lower;
  301. /**
  302. * Sets the value to compare against and the fuzziness of
  303. * the match. Used for comparing floating point values.
  304. * @param mixed $value Test value to match.
  305. * @param mixed $margin Fuzziness of match.
  306. * @param string $message Customised message on failure.
  307. * @access public
  308. */
  309. function WithinMarginExpectation($value, $margin, $message = '%s') {
  310. $this->SimpleExpectation($message);
  311. $this->_upper = $value + $margin;
  312. $this->_lower = $value - $margin;
  313. }
  314. /**
  315. * Tests the expectation. True if it matches the
  316. * held value.
  317. * @param mixed $compare Comparison value.
  318. * @return boolean True if correct.
  319. * @access public
  320. */
  321. function test($compare) {
  322. return (($compare <= $this->_upper) && ($compare >= $this->_lower));
  323. }
  324. /**
  325. * Returns a human readable test message.
  326. * @param mixed $compare Comparison value.
  327. * @return string Description of success
  328. * or failure.
  329. * @access public
  330. */
  331. function testMessage($compare) {
  332. if ($this->test($compare)) {
  333. return $this->_withinMessage($compare);
  334. } else {
  335. return $this->_outsideMessage($compare);
  336. }
  337. }
  338. /**
  339. * Creates a the message for being within the range.
  340. * @param mixed $compare Value being tested.
  341. * @access private
  342. */
  343. function _withinMessage($compare) {
  344. return "Within expectation [" . $this->_dumper->describeValue($this->_lower) . "] and [" .
  345. $this->_dumper->describeValue($this->_upper) . "]";
  346. }
  347. /**
  348. * Creates a the message for being within the range.
  349. * @param mixed $compare Value being tested.
  350. * @access private
  351. */
  352. function _outsideMessage($compare) {
  353. if ($compare > $this->_upper) {
  354. return "Outside expectation " .
  355. $this->_dumper->describeDifference($compare, $this->_upper);
  356. } else {
  357. return "Outside expectation " .
  358. $this->_dumper->describeDifference($compare, $this->_lower);
  359. }
  360. }
  361. }
  362. /**
  363. * Test for being outside of a range.
  364. * @package SimpleTest
  365. * @subpackage UnitTester
  366. */
  367. class OutsideMarginExpectation extends WithinMarginExpectation {
  368. /**
  369. * Sets the value to compare against and the fuzziness of
  370. * the match. Used for comparing floating point values.
  371. * @param mixed $value Test value to not match.
  372. * @param mixed $margin Fuzziness of match.
  373. * @param string $message Customised message on failure.
  374. * @access public
  375. */
  376. function OutsideMarginExpectation($value, $margin, $message = '%s') {
  377. $this->WithinMarginExpectation($value, $margin, $message);
  378. }
  379. /**
  380. * Tests the expectation. True if it matches the
  381. * held value.
  382. * @param mixed $compare Comparison value.
  383. * @return boolean True if correct.
  384. * @access public
  385. */
  386. function test($compare) {
  387. return ! parent::test($compare);
  388. }
  389. /**
  390. * Returns a human readable test message.
  391. * @param mixed $compare Comparison value.
  392. * @return string Description of success
  393. * or failure.
  394. * @access public
  395. */
  396. function testMessage($compare) {
  397. if (! $this->test($compare)) {
  398. return $this->_withinMessage($compare);
  399. } else {
  400. return $this->_outsideMessage($compare);
  401. }
  402. }
  403. }
  404. // test() method is incompatible with SimpleExpectation (php 5.3.1)
  405. if(0){
  406. /**
  407. * Test for reference.
  408. * @package SimpleTest
  409. * @subpackage UnitTester
  410. */
  411. class ReferenceExpectation extends SimpleExpectation {
  412. var $_value;
  413. /**
  414. * Sets the reference value to compare against.
  415. * @param mixed $value Test reference to match.
  416. * @param string $message Customised message on failure.
  417. * @access public
  418. */
  419. function ReferenceExpectation(&$value, $message = '%s') {
  420. $this->SimpleExpectation($message);
  421. $this->_value =& $value;
  422. }
  423. /**
  424. * Tests the expectation. True if it exactly
  425. * references the held value.
  426. * @param mixed $compare Comparison reference.
  427. * @return boolean True if correct.
  428. * @access public
  429. */
  430. function test(&$compare) {
  431. return SimpleTestCompatibility::isReference($this->_value, $compare);
  432. }
  433. /**
  434. * Returns a human readable test message.
  435. * @param mixed $compare Comparison value.
  436. * @return string Description of success
  437. * or failure.
  438. * @access public
  439. */
  440. function testMessage($compare) {
  441. if ($this->test($compare)) {
  442. return "Reference expectation [" . $this->_dumper->describeValue($this->_value) . "]";
  443. } else {
  444. return "Reference expectation fails " .
  445. $this->_dumper->describeDifference($this->_value, $compare);
  446. }
  447. }
  448. function _getValue() {
  449. return $this->_value;
  450. }
  451. }
  452. }
  453. /**
  454. * Test for identity.
  455. * @package SimpleTest
  456. * @subpackage UnitTester
  457. */
  458. class IdenticalExpectation extends EqualExpectation {
  459. /**
  460. * Sets the value to compare against.
  461. * @param mixed $value Test value to match.
  462. * @param string $message Customised message on failure.
  463. * @access public
  464. */
  465. function IdenticalExpectation($value, $message = '%s') {
  466. $this->EqualExpectation($value, $message);
  467. }
  468. /**
  469. * Tests the expectation. True if it exactly
  470. * matches the held value.
  471. * @param mixed $compare Comparison value.
  472. * @return boolean True if correct.
  473. * @access public
  474. */
  475. function test($compare) {
  476. return SimpleTestCompatibility::isIdentical($this->_getValue(), $compare);
  477. }
  478. /**
  479. * Returns a human readable test message.
  480. * @param mixed $compare Comparison value.
  481. * @return string Description of success
  482. * or failure.
  483. * @access public
  484. */
  485. function testMessage($compare) {
  486. $dumper = &$this->_getDumper();
  487. if ($this->test($compare)) {
  488. return "Identical expectation [" . $dumper->describeValue($this->_getValue()) . "]";
  489. } else {
  490. return "Identical expectation [" . $dumper->describeValue($this->_getValue()) .
  491. "] fails with [" .
  492. $dumper->describeValue($compare) . "] " .
  493. $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS);
  494. }
  495. }
  496. }
  497. /**
  498. * Test for non-identity.
  499. * @package SimpleTest
  500. * @subpackage UnitTester
  501. */
  502. class NotIdenticalExpectation extends IdenticalExpectation {
  503. /**
  504. * Sets the value to compare against.
  505. * @param mixed $value Test value to match.
  506. * @param string $message Customised message on failure.
  507. * @access public
  508. */
  509. function NotIdenticalExpectation($value, $message = '%s') {
  510. $this->IdenticalExpectation($value, $message);
  511. }
  512. /**
  513. * Tests the expectation. True if it differs from the
  514. * held value.
  515. * @param mixed $compare Comparison value.
  516. * @return boolean True if correct.
  517. * @access public
  518. */
  519. function test($compare) {
  520. return ! parent::test($compare);
  521. }
  522. /**
  523. * Returns a human readable test message.
  524. * @param mixed $compare Comparison value.
  525. * @return string Description of success
  526. * or failure.
  527. * @access public
  528. */
  529. function testMessage($compare) {
  530. $dumper = &$this->_getDumper();
  531. if ($this->test($compare)) {
  532. return "Not identical expectation passes " .
  533. $dumper->describeDifference($this->_getValue(), $compare, TYPE_MATTERS);
  534. } else {
  535. return "Not identical expectation [" . $dumper->describeValue($this->_getValue()) . "] matches";
  536. }
  537. }
  538. }
  539. /**
  540. * Test for a pattern using Perl regex rules.
  541. * @package SimpleTest
  542. * @subpackage UnitTester
  543. */
  544. class PatternExpectation extends SimpleExpectation {
  545. var $_pattern;
  546. /**
  547. * Sets the value to compare against.
  548. * @param string $pattern Pattern to search for.
  549. * @param string $message Customised message on failure.
  550. * @access public
  551. */
  552. function PatternExpectation($pattern, $message = '%s') {
  553. $this->SimpleExpectation($message);
  554. $this->_pattern = $pattern;
  555. }
  556. /**
  557. * Accessor for the pattern.
  558. * @return string Perl regex as string.
  559. * @access protected
  560. */
  561. function _getPattern() {
  562. return $this->_pattern;
  563. }
  564. /**
  565. * Tests the expectation. True if the Perl regex
  566. * matches the comparison value.
  567. * @param string $compare Comparison value.
  568. * @return boolean True if correct.
  569. * @access public
  570. */
  571. function test($compare) {
  572. return (boolean)preg_match($this->_getPattern(), $compare);
  573. }
  574. /**
  575. * Returns a human readable test message.
  576. * @param mixed $compare Comparison value.
  577. * @return string Description of success
  578. * or failure.
  579. * @access public
  580. */
  581. function testMessage($compare) {
  582. if ($this->test($compare)) {
  583. return $this->_describePatternMatch($this->_getPattern(), $compare);
  584. } else {
  585. $dumper = &$this->_getDumper();
  586. return "Pattern [" . $this->_getPattern() .
  587. "] not detected in [" .
  588. $dumper->describeValue($compare) . "]";
  589. }
  590. }
  591. /**
  592. * Describes a pattern match including the string
  593. * found and it's position.
  594. * @param string $pattern Regex to match against.
  595. * @param string $subject Subject to search.
  596. * @access protected
  597. */
  598. function _describePatternMatch($pattern, $subject) {
  599. preg_match($pattern, $subject, $matches);
  600. $position = strpos($subject, $matches[0]);
  601. $dumper = $this->_getDumper();
  602. return "Pattern [$pattern] detected at character [$position] in [" .
  603. $dumper->describeValue($subject) . "] as [" .
  604. $matches[0] . "] in region [" .
  605. $dumper->clipString($subject, 100, $position) . "]";
  606. }
  607. }
  608. /**
  609. * @package SimpleTest
  610. * @subpackage UnitTester
  611. * @deprecated
  612. */
  613. class WantedPatternExpectation extends PatternExpectation {
  614. }
  615. /**
  616. * Fail if a pattern is detected within the
  617. * comparison.
  618. * @package SimpleTest
  619. * @subpackage UnitTester
  620. */
  621. class NoPatternExpectation extends PatternExpectation {
  622. /**
  623. * Sets the reject pattern
  624. * @param string $pattern Pattern to search for.
  625. * @param string $message Customised message on failure.
  626. * @access public
  627. */
  628. function NoPatternExpectation($pattern, $message = '%s') {
  629. $this->PatternExpectation($pattern, $message);
  630. }
  631. /**
  632. * Tests the expectation. False if the Perl regex
  633. * matches the comparison value.
  634. * @param string $compare Comparison value.
  635. * @return boolean True if correct.
  636. * @access public
  637. */
  638. function test($compare) {
  639. return ! parent::test($compare);
  640. }
  641. /**
  642. * Returns a human readable test message.
  643. * @param string $compare Comparison value.
  644. * @return string Description of success
  645. * or failure.
  646. * @access public
  647. */
  648. function testMessage($compare) {
  649. if ($this->test($compare)) {
  650. $dumper = &$this->_getDumper();
  651. return "Pattern [" . $this->_getPattern() .
  652. "] not detected in [" .
  653. $dumper->describeValue($compare) . "]";
  654. } else {
  655. return $this->_describePatternMatch($this->_getPattern(), $compare);
  656. }
  657. }
  658. }
  659. /**
  660. * @package SimpleTest
  661. * @subpackage UnitTester
  662. * @deprecated
  663. */
  664. class UnwantedPatternExpectation extends NoPatternExpectation {
  665. }
  666. /**
  667. * Tests either type or class name if it's an object.
  668. * @package SimpleTest
  669. * @subpackage UnitTester
  670. */
  671. class IsAExpectation extends SimpleExpectation {
  672. var $_type;
  673. /**
  674. * Sets the type to compare with.
  675. * @param string $type Type or class name.
  676. * @param string $message Customised message on failure.
  677. * @access public
  678. */
  679. function IsAExpectation($type, $message = '%s') {
  680. $this->SimpleExpectation($message);
  681. $this->_type = $type;
  682. }
  683. /**
  684. * Accessor for type to check against.
  685. * @return string Type or class name.
  686. * @access protected
  687. */
  688. function _getType() {
  689. return $this->_type;
  690. }
  691. /**
  692. * Tests the expectation. True if the type or
  693. * class matches the string value.
  694. * @param string $compare Comparison value.
  695. * @return boolean True if correct.
  696. * @access public
  697. */
  698. function test($compare) {
  699. if (is_object($compare)) {
  700. return SimpleTestCompatibility::isA($compare, $this->_type);
  701. } else {
  702. return (strtolower(gettype($compare)) == $this->_canonicalType($this->_type));
  703. }
  704. }
  705. /**
  706. * Coerces type name into a gettype() match.
  707. * @param string $type User type.
  708. * @return string Simpler type.
  709. * @access private
  710. */
  711. function _canonicalType($type) {
  712. $type = strtolower($type);
  713. $map = array(
  714. 'bool' => 'boolean',
  715. 'float' => 'double',
  716. 'real' => 'double',
  717. 'int' => 'integer');
  718. if (isset($map[$type])) {
  719. $type = $map[$type];
  720. }
  721. return $type;
  722. }
  723. /**
  724. * Returns a human readable test message.
  725. * @param mixed $compare Comparison value.
  726. * @return string Description of success
  727. * or failure.
  728. * @access public
  729. */
  730. function testMessage($compare) {
  731. $dumper = &$this->_getDumper();
  732. return "Value [" . $dumper->describeValue($compare) .
  733. "] should be type [" . $this->_type . "]";
  734. }
  735. }
  736. /**
  737. * Tests either type or class name if it's an object.
  738. * Will succeed if the type does not match.
  739. * @package SimpleTest
  740. * @subpackage UnitTester
  741. */
  742. class NotAExpectation extends IsAExpectation {
  743. var $_type;
  744. /**
  745. * Sets the type to compare with.
  746. * @param string $type Type or class name.
  747. * @param string $message Customised message on failure.
  748. * @access public
  749. */
  750. function NotAExpectation($type, $message = '%s') {
  751. $this->IsAExpectation($type, $message);
  752. }
  753. /**
  754. * Tests the expectation. False if the type or
  755. * class matches the string value.
  756. * @param string $compare Comparison value.
  757. * @return boolean True if different.
  758. * @access public
  759. */
  760. function test($compare) {
  761. return ! parent::test($compare);
  762. }
  763. /**
  764. * Returns a human readable test message.
  765. * @param mixed $compare Comparison value.
  766. * @return string Description of success
  767. * or failure.
  768. * @access public
  769. */
  770. function testMessage($compare) {
  771. $dumper = &$this->_getDumper();
  772. return "Value [" . $dumper->describeValue($compare) .
  773. "] should not be type [" . $this->_getType() . "]";
  774. }
  775. }
  776. /**
  777. * Tests for existance of a method in an object
  778. * @package SimpleTest
  779. * @subpackage UnitTester
  780. */
  781. class MethodExistsExpectation extends SimpleExpectation {
  782. var $_method;
  783. /**
  784. * Sets the value to compare against.
  785. * @param string $method Method to check.
  786. * @param string $message Customised message on failure.
  787. * @access public
  788. * @return void
  789. */
  790. function MethodExistsExpectation($method, $message = '%s') {
  791. $this->SimpleExpectation($message);
  792. $this->_method = &$method;
  793. }
  794. /**
  795. * Tests the expectation. True if the method exists in the test object.
  796. * @param string $compare Comparison method name.
  797. * @return boolean True if correct.
  798. * @access public
  799. */
  800. function test($compare) {
  801. return (boolean)(is_object($compare) && method_exists($compare, $this->_method));
  802. }
  803. /**
  804. * Returns a human readable test message.
  805. * @param mixed $compare Comparison value.
  806. * @return string Description of success
  807. * or failure.
  808. * @access public
  809. */
  810. function testMessage($compare) {
  811. $dumper = &$this->_getDumper();
  812. if (! is_object($compare)) {
  813. return 'No method on non-object [' . $dumper->describeValue($compare) . ']';
  814. }
  815. $method = $this->_method;
  816. return "Object [" . $dumper->describeValue($compare) .
  817. "] should contain method [$method]";
  818. }
  819. }
  820. ?>