public function testIterate_SubObject() { $obj1 = new stdClass(); $obj1->data = "blah"; $obj2 = new stdClass(); $obj2->data = "blip"; $pluck = new \r8\Iterator\KeyPluck("data", new ArrayIterator(array(50 => $obj1, 100 => $obj2))); \r8\Test\Constraint\Iterator::assert(array("blah" => $obj1, "blip" => $obj2), $pluck); }
public function testIterate_Multi_Empty() { $callback = $this->getMock('\\r8\\Curry\\Unbound', array('rawExec', 'exec')); $callback->expects($this->exactly(3))->method("exec"); $iterator = new \r8\Iterator\OnComplete(new EmptyIterator(), $callback, FALSE); \r8\Test\Constraint\Iterator::assert(array(), $iterator); \r8\Test\Constraint\Iterator::assert(array(), $iterator); \r8\Test\Constraint\Iterator::assert(array(), $iterator); }
public function testIterate_Mixed() { $obj1 = new stdClass(); $obj1->wrongName = "blah"; $obj2 = new stdClass(); $obj2->data = "blip"; $pluck = new \r8\Iterator\Pluck("data", new ArrayIterator(array(50 => $obj1, 75 => "not pluckable", 100 => $obj2, 125 => NULL, 150 => array("data" => "bloop"), 180 => array("Wrong field")))); \r8\Test\Constraint\Iterator::assert(array(50 => NULL, 75 => NULL, 100 => "blip", 125 => NULL, 150 => "bloop", 180 => NULL), $pluck); }
public function testInputOutputPaths() { $builder = new \vc\App\Builder(); $result = $builder->build($this->getCLIResult()); $this->assertThat($result, $this->isInstanceOf('\\vc\\App\\Config')); $this->assertThat($result->getOutputDir(), $this->isInstanceOf('\\r8\\FileSys\\Dir')); $this->assertThat($result->getInputPaths(), $this->isInstanceOf('\\vc\\App\\Paths')); \r8\Test\Constraint\Iterator::assertCount(2, $result->getInputPaths()); }
public function testLeadingDelim() { $stream = new \r8\Stream\In\String("\n\nString\nTo\nSplit"); $iter = new \r8\Iterator\Stream\Tokenize($stream, "\n"); \r8\Test\Constraint\Iterator::assert(array("String", "To", "Split"), $iter); $stream = new \r8\Stream\In\String("BRBRString"); $iter = new \r8\Iterator\Stream\Tokenize($stream, "BR"); \r8\Test\Constraint\Iterator::assert(array("String"), $iter); }
public function testIterate() { $data = array(50 => "blah", 100 => "blip", 150 => "bloop"); $iterator = new \r8\Iterator\Debug(new ArrayIterator($data)); ob_start(); \r8\Test\Constraint\Iterator::assert($data, $iterator); \r8\Test\Constraint\Iterator::assert($data, $iterator); \r8\Test\Constraint\Iterator::assert($data, $iterator); $result = ob_end_clean(); $this->assertGreaterThan(0, strlen($result)); }
public function testAddInput_Directories() { $input = new \vc\App\Paths(); $this->assertSame($input, $input->addInput(\r8\FileSys::create($this->dir . '/third'))); $value = \r8\Test\Constraint\Iterator::iteratorToArray(10, $input); $this->assertEquals(5, count($value)); $this->assertEquals(array(0, 1, 2, 3, 4), array_keys($value)); $this->assertSame('third-one', $value[0]->getBaseName()); $this->assertSame('fourth-two', $value[1]->getBaseName()); $this->assertSame('fourth-one', $value[2]->getBaseName()); $this->assertSame('third-two', $value[3]->getBaseName()); $this->assertSame('third-three', $value[4]->getBaseName()); }
public function testIteration_many() { $iterator = new \r8\Iterator\DOMNodeList($this->runTestXPath("/doc/*")); $result = \r8\Test\Constraint\Iterator::iteratorToArray(10, $iterator); $this->assertSame(4, count($result)); $this->assertArrayHasKey(0, $result); $this->assertArrayHasKey(1, $result); $this->assertArrayHasKey(2, $result); $this->assertArrayHasKey(3, $result); $this->assertThat($result[0], $this->isInstanceOf("DOMElement")); $this->assertThat($result[1], $this->isInstanceOf("DOMElement")); $this->assertThat($result[2], $this->isInstanceOf("DOMElement")); $this->assertThat($result[3], $this->isInstanceOf("DOMElement")); $this->assertSame("one", $result[0]->tagName); $this->assertSame("two", $result[1]->tagName); $this->assertSame("three", $result[2]->tagName); $this->assertSame("four", $result[3]->tagName); }
public function testIterate_BadKeys() { \r8\Test\Constraint\Iterator::assert(array(), new \r8\Iterator\Group("field", new \ArrayIterator(array(array("field" => new stdClass()), array("field" => array()), array("field" => NULL))))); }
public function testIterator() { $backtrace = new \r8\Backtrace(); $events = array($this->getMockEvent(), $this->getMockEvent(), $this->getMockEvent()); $backtrace->pushEvent($events[0]); $backtrace->pushEvent($events[1]); $backtrace->pushEvent($events[2]); \r8\Test\Constraint\Iterator::assert($events, $backtrace); }
public function testSleep() { $iterator = new \r8\Iterator\Range(1, 5, 2); \r8\Test\Constraint\Iterator::assert(array(1, 3, 5), unserialize(serialize($iterator))); }
public function testFullIterator() { \r8\Test\Constraint\Iterator::assert(array(0 => 'first', 1 => 'second', 2 => 'third'), new \r8\Iterator\OffsetAsKey(new ArrayIterator(array('one' => 'first', 'two' => 'second', 'three' => 'third')))); }
public function testSleep() { $data = array(50 => "blah", 100 => "blip", 150 => "bloop"); $iterator = new \r8\Iterator\Cache($this->getMockIterator($data)); $serialized = serialize($iterator); // Ensure that the cache is what is serialized, not the internal iterator $this->assertSame('O:17:"r8\\Iterator\\Cache":2:{s:25:"' . "" . 'r8\\Iterator\\Cache' . "" . 'offset";N;s:24:"' . "" . 'r8\\Iterator\\Cache' . "" . 'cache";a:3:{i:0;a:2:{i:0;i:50;i:1;s:4:"blah";}i:1;a:2:{i:0;i:100;i:1;s:4:"blip";}i:2;a:2:{i:0;i:150;i:1;s:5:"bloop";}}}', $serialized); $unserialized = unserialize($serialized); $this->assertThat($unserialized, $this->isInstanceOf('\\r8\\Iterator\\Cache')); \r8\Test\Constraint\Iterator::assert($data, $unserialized); \r8\Test\Constraint\Iterator::assert($data, $unserialized); \r8\Test\Constraint\Iterator::assert($data, $unserialized); }
public function testIterate() { $result = new \r8\DB\Result\Read\AutoFree(new \r8\DB\Result\Read(new \r8\DB\BlackHole\Result(array(1, 2), array(3, 4)), "SELECT 1")); \r8\Test\Constraint\Iterator::assert(array(array(1, 2), array(3, 4)), $result); \r8\Test\Constraint\Iterator::assert(array(), $result); }
public function testIterator() { \r8\Test\Constraint\Iterator::assert(array(1, 2, 4, 8), new \r8\Iterator\Poppable(new \ArrayIterator(array(1, 2, 4, 8)))); }
public function testIterate_FreeAfterIterating() { $result = new \r8\DB\Result\Read(new \r8\DB\BlackHole\Result(array(1, 2), array(3, 4)), "SELECT 1"); \r8\Test\Constraint\Iterator::assert(array(array(1, 2), array(3, 4)), $result); $result->free(); \r8\Test\Constraint\Iterator::assert(array(), $result); }
public function testIteration() { $result = new \r8\Validator\ErrorList(); \r8\Test\Constraint\Iterator::assertCount(0, $result); $result->addError("Test Error"); \r8\Test\Constraint\Iterator::assert(array("Test Error"), $result); $result->addError("Error Two"); \r8\Test\Constraint\Iterator::assert(array("Test Error", "Error Two"), $result); }
public function testSerialize() { $data = array(50 => "blah", 100 => "blip", 150 => "bloop"); $iterator = new \r8\Iterator\Debounce(new ArrayIterator($data)); $serialized = serialize($iterator); // The serialized string should NOT contain these object properties $this->assertNotContains("hasCurrent", $serialized); $this->assertNotContains("current", $serialized); $this->assertNotContains("hasKey", $serialized); $this->assertNotContains("key", $serialized); $this->assertNotContains("valid", $serialized); $iterator = unserialize($serialized); \r8\Test\Constraint\Iterator::assert($data, $iterator); \r8\Test\Constraint\Iterator::assert($data, $iterator); \r8\Test\Constraint\Iterator::assert($data, $iterator); }
public function testSerialization() { $defer = new \r8\Iterator\Defer($this->getTestCallback(array("one", "two", "three"))); \r8\Test\Constraint\Iterator::assert(array("one", "two", "three"), unserialize(serialize($defer))); }
public function testIterate_Unseekable_OutOfBounds() { $offset = new \r8\Iterator\Offset(50, new IteratorIterator(new \ArrayIterator(range("a", "e")))); \r8\Test\Constraint\Iterator::assert(array(), $offset); \r8\Test\Constraint\Iterator::assert(array(), $offset); \r8\Test\Constraint\Iterator::assert(array(), $offset); }