Example #1
0
 /**
  *    Tests to see if the method is a test that should
  *    be run, override default by searching methods that starts with 'it'
  *    is a candidate unless it is the constructor.
  *    @param string $method        Method name to try.
  *    @return boolean              True if test method.
  *    @access protected
  */
 function _isTest($method)
 {
     if (strtolower(substr($method, 0, 2)) == 'it') {
         return !SimpleTestCompatibility::isA($this, strtolower($method));
     }
     return parent::_isTest($method);
 }
Example #2
0
 function testInteraceComparison()
 {
     if (version_compare(phpversion(), '5', '<')) {
         return;
     }
     $object = new ComparisonClassWithInterface();
     $this->assertFalse(SimpleTestCompatibility::isA(new ComparisonClass(), 'ComparisonInterface'));
     $this->assertTrue(SimpleTestCompatibility::isA(new ComparisonClassWithInterface(), 'ComparisonInterface'));
 }
Example #3
0
 function SimpleSocket($host, $port, $timeout, $block_size = 255)
 {
     $this->SimpleStickyError();
     if (!($this->_handle = $this->_openSocket($host, $port, $error_number, $error, $timeout))) {
         $this->_setError("Cannot open [{$host}:{$port}] with [{$error}] within [{$timeout}] seconds");
         return;
     }
     $this->_is_open = true;
     $this->_block_size = $block_size;
     SimpleTestCompatibility::setTimeout($this->_handle, $timeout);
 }
 public function testObjectReferences()
 {
     $object = new ComparisonClass();
     $object_reference = $object;
     $object_copy = new ComparisonClass();
     $object_assignment = $object;
     $this->assertTrue(SimpleTestCompatibility::isReference($object, $object));
     $this->assertTrue(SimpleTestCompatibility::isReference($object, $object_reference));
     $this->assertFalse(SimpleTestCompatibility::isReference($object, $object_copy));
     $this->assertTrue(SimpleTestCompatibility::isReference($object, $object_assignment));
 }
 function testIsA() {
     $this->assertTrue(SimpleTestCompatibility::isA(
             new RandomCompatibilityClass(),
             'RandomCompatibilityClass'));
     $this->assertFalse(SimpleTestCompatibility::isA(
             new RandomCompatibilityClass(),
             'RandomCompatibilitySubclass'));
     $this->assertTrue(SimpleTestCompatibility::isA(
             new RandomCompatibilitySubclass(),
             'RandomCompatibilityClass'));
 }
Example #6
0
 /**
  *    Recursive type test for each element of an array.
  *    @param mixed $first    Test subject.
  *    @param mixed $second   Comparison object.
  *    @return boolean        True if identical.
  *    @access private
  */
 protected static function isArrayOfIdenticalTypes($first, $second)
 {
     if (array_keys($first) != array_keys($second)) {
         return false;
     }
     foreach (array_keys($first) as $key) {
         $is_identical = SimpleTestCompatibility::isIdenticalType($first[$key], $second[$key]);
         if (!$is_identical) {
             return false;
         }
     }
     return true;
 }
Example #7
0
 function testObjectReferences()
 {
     $object = new ComparisonClass();
     $object_reference =& $object;
     $object_copy = new ComparisonClass();
     $object_assignment = $object;
     $this->assertTrue(SimpleTestCompatibility::isReference($object, $object));
     $this->assertTrue(SimpleTestCompatibility::isReference($object, $object_reference));
     $this->assertFalse(SimpleTestCompatibility::isReference($object, $object_copy));
     if (version_compare(phpversion(), '5', '>=')) {
         $this->assertTrue(SimpleTestCompatibility::isReference($object, $object_assignment));
     } else {
         $this->assertFalse(SimpleTestCompatibility::isReference($object, $object_assignment));
     }
 }
 function testAddTwice()
 {
     $parent = $this->generateSection(0);
     $section1 = $this->generateSection(0);
     $fakeSection1 = $this->generateSection(0);
     //will generate with the
     //same data as the section above
     $this->assertFalse(SimpleTestCompatibility::isReference($section1, $fakeSection1));
     //add once
     $parent->add($section1);
     $resultSection =& $parent->get($section1->getId());
     $this->assertNotNull($resultSection);
     $this->assertSectionsEqual($section1, $resultSection);
     //add again
     $result = $parent->add($section1);
     $this->assertTrue(PEAR::isError($result));
     $this->assertNotNull($parent->get($section1->getId()));
     //add other
     $result = $parent->add($fakeSection1);
     $this->assertTrue(PEAR::isError($result));
 }
 function getAssertionLine($format = '%d', $stack = false)
 {
     if ($stack === false) {
         $stack = SimpleTestCompatibility::getStackTrace();
     }
     return SimpleDumper::getFormattedAssertionLine($stack, $format);
 }
Example #10
0
 /**
  *   Retrieves 'preferred' objects from global pool. Class filter
  *   can be applied in order to retrieve the object of the specific
  *   class
  *   @param array|string $classes       Allowed classes or interfaces.
  *   @static
  *   @access public
  *   @return array|object|null
  *   @see prefer()
  */
 function &preferred($classes)
 {
     if (!is_array($classes)) {
         $classes = array($classes);
     }
     $registry =& SimpleTest::_getRegistry();
     for ($i = count($registry['Preferred']) - 1; $i >= 0; $i--) {
         foreach ($classes as $class) {
             if (SimpleTestCompatibility::isA($registry['Preferred'][$i], $class)) {
                 return $registry['Preferred'][$i];
             }
         }
     }
     return null;
 }
Example #11
0
 /**
  *    Identity test. Drops back to equality for PHP5
  *    objects as the === operator counts as the
  *    stronger reference constraint.
  *    @param mixed $first    Test subject.
  *    @param mixed $second   Comparison object.
  *    @access public
  *    @static
  */
 function isIdentical($first, $second)
 {
     if (version_compare(phpversion(), '5') >= 0) {
         if (gettype($first) != gettype($second)) {
             return false;
         }
         if ($first != $second) {
             return false;
         }
         if (is_object($first) && is_object($second)) {
             return get_class($first) == get_class($second);
         }
         if (is_array($first) && is_array($second)) {
             if (array_keys($first) != array_keys($second)) {
                 return false;
             }
             foreach (array_keys($first) as $key) {
                 if (!SimpleTestCompatibility::isIdentical($first[$key], $second[$key])) {
                     return false;
                 }
             }
         }
         return true;
     }
     return $first === $second;
 }
Example #12
0
 /**
  *    Tests to see if the method is the constructor and
  *    so should be ignored.
  *    @param string $method        Method name to try.
  *    @return boolean              True if constructor.
  *    @access protected
  */
 function _isConstructor($method)
 {
     return SimpleTestCompatibility::isA($this->_test_case, strtolower($method));
 }
Example #13
0
 /**
  *    Tests the expectation. True if the type or
  *    class matches the string value.
  *    @param string $compare        Comparison value.
  *    @return boolean               True if correct.
  *    @access public
  */
 function test($compare)
 {
     if (is_object($compare)) {
         return SimpleTestCompatibility::isA($compare, $this->type);
     } else {
         $function = 'is_' . $this->canonicalType($this->type);
         if (is_callable($function)) {
             return $function($compare);
         }
         return false;
     }
 }
 function testInteraceComparison()
 {
     $object = new ComparisonClassWithInterface();
     $this->assertFalse(SimpleTestCompatibility::isA(new ComparisonClass(), 'ComparisonInterface'));
     $this->assertTrue(SimpleTestCompatibility::isA(new ComparisonClassWithInterface(), 'ComparisonInterface'));
 }
Example #15
0
 /**
  *    Adds a checkbox, making it a group on a repeated name.
  *    @param SimpleCheckboxTag $tag   Incoming form control.
  *    @access private
  */
 function _addCheckbox($tag) {
     if (! isset($this->_widgets[$tag->getName()])) {
         $this->_widgets[$tag->getName()] = &$tag;
     } elseif (! SimpleTestCompatibility::isA($this->_widgets[$tag->getName()], 'SimpleCheckboxGroup')) {
         $previous = &$this->_widgets[$tag->getName()];
         $this->_widgets[$tag->getName()] = &new SimpleCheckboxGroup();
         $this->_widgets[$tag->getName()]->addWidget($previous);
         $this->_widgets[$tag->getName()]->addWidget($tag);
     } else {
         $this->_widgets[$tag->getName()]->addWidget($tag);
     }
 }
Example #16
0
 /**
  *    In PHP5 the identity test tests for the same
  *    object. This is a reference test in PHP4.
  *    @param $first          First object handle.
  *    @param $second         Hopefully a different handle.
  *    @param $message        Message to display.
  *    @public
  */
 function assertNotSame(&$first, &$second, $message = "%s")
 {
     $dumper =& new SimpleDumper();
     $message = sprintf($message, "[" . $dumper->describeValue($first) . "] and [" . $dumper->describeValue($second) . "] should not be the same object");
     return $this->assert(new falseExpectation(), SimpleTestCompatibility::isReference($first, $second), $message);
 }
 /**
  *    Tests the expectation. True if the type or
  *    class matches the string value.
  *    @param string $compare        Comparison value.
  *    @return boolean               True if correct.
  *    @access public
  */
 function test($compare)
 {
     if (is_object($compare)) {
         return SimpleTestCompatibility::isA($compare, $this->_type);
     } else {
         return strtolower(gettype($compare)) == $this->_canonicalType($this->_type);
     }
 }
Example #18
0
 /**
  *    Tests the expectation. True if it exactly
  *    matches the held value.
  *    @param mixed $compare        Comparison value.
  *    @return boolean              True if correct.
  *    @access public
  */
 public function test($compare)
 {
     return SimpleTestCompatibility::isIdentical($this->getValue(), $compare);
 }
Example #19
0
 /**
  *    Opens a socket for reading and writing.
  *    @param string $host          Hostname to send request to.
  *    @param integer $port         Port on remote machine to open.
  *    @param integer $timeout      Connection timeout in seconds.
  *    @param integer $block_size   Size of chunk to read.
  *    @access public
  */
 function __construct($host, $port, $timeout, $block_size = 255)
 {
     parent::__construct();
     if (!($this->handle = $this->openSocket($host, $port, $error_number, $error, $timeout))) {
         $this->setError("Cannot open [{$host}:{$port}] with [{$error}] within [{$timeout}] seconds");
         return;
     }
     $this->is_open = true;
     $this->block_size = $block_size;
     SimpleTestCompatibility::setTimeout($this->handle, $timeout);
 }
Example #20
0
 /**
  * Inverted identity test.
  *
  * @param $first          First object handle.
  * @param $second         Hopefully a different handle.
  * @param $message        Message to display.
  */
 public function assertNotSame($first, $second, $message = '%s')
 {
     $dumper = new SimpleDumper();
     $message = sprintf($message, '[' . $dumper->describeValue($first) . '] and [' . $dumper->describeValue($second) . '] should not be the same object');
     return $this->assert(new falseExpectation(), SimpleTestCompatibility::isReference($first, $second), $message);
 }
Example #21
0
 /**
  * Tests the expectation. True if it exactly matches the held value.
  *
  * @param mixed $compare Comparison value.
  * @return boolean
  */
 public function test($compare)
 {
     $value = $this->entityToFilteredArray($this->getValue());
     $compare = $this->entityToFilteredArray($compare);
     return SimpleTestCompatibility::isIdentical($value, $compare);
 }
Example #22
0
 /**
  *    Tests to see if the method is a test that should
  *    be run. Currently any method that starts with 'test'
  *    is a candidate unless it is the constructor.
  *    @param string $method        Method name to try.
  *    @return boolean              True if test method.
  *    @access protected
  */
 function _isTest($method) {
     if (strtolower(substr($method, 0, 4)) == 'test') {
         return ! SimpleTestCompatibility::isA($this, strtolower($method));
     }
     return false;
 }
Example #23
0
 /**
  *    Creates an equality expectation if the
  *    object/value is not already some type
  *    of expectation.
  *    @param mixed $expected      Expected value.
  *    @return SimpleExpectation   Expectation object.
  *    @access private
  */
 function _coerceExpectation($expected)
 {
     if ($expected == false) {
         return new TrueExpectation();
     }
     if (SimpleTestCompatibility::isA($expected, 'SimpleExpectation')) {
         return $expected;
     }
     return new EqualExpectation(is_string($expected) ? str_replace('%', '%%', $expected) : $expected);
 }
 /**
  * IsTest method
  *
  * Prevent intensive W3 test, and the build tests (used to generate the testSection tests) unless
  * explicitly specified
  *
  * @param mixed $method
  * @return void
  */
 protected function _isTest($method)
 {
     if (strtolower($method) === 'testaction') {
         return false;
     }
     $buildTests = ['testw3validity', 'testbuildregex', 'testbuildtest'];
     if (in_array(strtolower($method), $buildTests)) {
         return !$this->skipSetupTests;
     }
     if (strtolower(substr($method, 0, 4)) === 'test') {
         if (!$this->skipSetupTests) {
             return false;
         }
         return !SimpleTestCompatibility::isA($this, strtolower($method));
     }
     return false;
 }
Example #25
0
 /**
  *    Closes the most recently opened label.
  *    @access public
  */
 function acceptLabelEnd()
 {
     if (isset($this->_label)) {
         if (isset($this->_last_widget)) {
             $this->_last_widget->setLabel($this->_label->getText());
             unset($this->_last_widget);
         } else {
             $this->_left_over_labels[] = SimpleTestCompatibility::copy($this->_label);
         }
         unset($this->_label);
     }
 }
Example #26
0
 function be_copy_of(&$first, &$second, $message = '%s')
 {
     $dumper = new SimpleDumper();
     $message = sprintf($message, "[" . $dumper->describeValue($first) . "] and [" . $dumper->describeValue($second) . "] should not be the same object");
     return $this->runtime->assert(new FaseExpectation(), SimpleTestCompatibility::isReference($first, $second), $message);
 }
Example #27
0
 /**
  *    Uses a stack trace to find the line of an assertion.
  *    @param array $stack      Stack frames top most first. Only
  *                             needed if not using the PHP
  *                             backtrace function.
  *    @return string           Location of first expect*
  *                             method embedded in format string.
  *    @access public
  *    @static
  */
 function getExpectationLine($stack = false)
 {
     if ($stack === false) {
         $stack = SimpleTestCompatibility::getStackTrace();
     }
     return SimpleDumper::getFormattedAssertionLine($stack);
 }
Example #28
0
 /**
  *    Opens a socket for reading and writing.
  *    @param string $host      Hostname to send request to.
  *    @param integer $port     Port on remote machine to open.
  *    @param integer $timeout  Connection timeout in seconds.
  *    @access public
  */
 function SimpleSocket($host, $port, $timeout)
 {
     $this->StickyError();
     $this->_is_open = false;
     if (!($this->_handle = $this->_openSocket($host, $port, $error_number, $error, $timeout))) {
         $this->_setError("Cannot open [{$host}:{$port}] with [{$error}] within [{$timeout}] seconds");
     } else {
         $this->_is_open = true;
         SimpleTestCompatibility::setTimeout($this->_handle, $timeout);
     }
 }
Example #29
0
 /**
  *    Adds a checkbox, making it a group on a repeated name.
  *    @param SimpleCheckboxTag $tag   Incoming form control.
  *    @access private
  */
 protected function addCheckbox($tag)
 {
     if (!isset($this->checkboxes[$tag->getName()])) {
         $this->widgets[] = $tag;
         $this->checkboxes[$tag->getName()] = count($this->widgets) - 1;
     } else {
         $index = $this->checkboxes[$tag->getName()];
         if (!SimpleTestCompatibility::isA($this->widgets[$index], 'SimpleCheckboxGroup')) {
             $previous = $this->widgets[$index];
             $this->widgets[$index] = new SimpleCheckboxGroup();
             $this->widgets[$index]->addWidget($previous);
         }
         $this->widgets[$index]->addWidget($tag);
     }
 }
Example #30
0
 /**
  *    Creates an equality expectation if the
  *    object/value is not already some type
  *    of expectation.
  *    @param mixed $expected      Expected value.
  *    @return SimpleExpectation   Expectation object.
  *    @access private
  */
 function _coerceToExpectation($expected)
 {
     if (SimpleTestCompatibility::isA($expected, 'SimpleExpectation')) {
         return $expected;
     }
     return new EqualExpectation($expected);
 }