|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the JsonSchema package. |
| 5 | + * |
| 6 | + * For the full copyright and license information, please view the LICENSE |
| 7 | + * file that was distributed with this source code. |
| 8 | + */ |
| 9 | + |
| 10 | +namespace JsonSchema\Tests\Iterators; |
| 11 | + |
| 12 | +use JsonSchema\Iterator\ObjectIterator; |
| 13 | + |
| 14 | +class ObjectIteratorTest extends \PHPUnit_Framework_TestCase |
| 15 | +{ |
| 16 | + protected $testObject; |
| 17 | + |
| 18 | + public function setUp() |
| 19 | + { |
| 20 | + $this->testObject = (object) array( |
| 21 | + 'subOne' => (object) array( |
| 22 | + 'propertyOne' => 'valueOne', |
| 23 | + 'propertyTwo' => 'valueTwo', |
| 24 | + 'propertyThree' => 'valueThree' |
| 25 | + ), |
| 26 | + 'subTwo' => (object) array( |
| 27 | + 'propertyFour' => 'valueFour', |
| 28 | + 'subThree' => (object) array( |
| 29 | + 'propertyFive' => 'valueFive', |
| 30 | + 'propertySix' => 'valueSix' |
| 31 | + ) |
| 32 | + ), |
| 33 | + 'propertySeven' => 'valueSeven' |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + public function testCreate() |
| 38 | + { |
| 39 | + $i = new ObjectIterator($this->testObject); |
| 40 | + |
| 41 | + $this->assertInstanceOf('\JsonSchema\Iterator\ObjectIterator', $i); |
| 42 | + } |
| 43 | + |
| 44 | + public function testInitialState() |
| 45 | + { |
| 46 | + $i = new ObjectIterator($this->testObject); |
| 47 | + |
| 48 | + $this->assertEquals($this->testObject, $i->current()); |
| 49 | + } |
| 50 | + |
| 51 | + public function testCount() |
| 52 | + { |
| 53 | + $i = new ObjectIterator($this->testObject); |
| 54 | + |
| 55 | + $this->assertEquals(4, $i->count()); |
| 56 | + } |
| 57 | + |
| 58 | + public function testKey() |
| 59 | + { |
| 60 | + $i = new ObjectIterator($this->testObject); |
| 61 | + |
| 62 | + while ($i->key() != 2) { |
| 63 | + $i->next(); |
| 64 | + } |
| 65 | + |
| 66 | + $this->assertEquals($this->testObject->subTwo->subThree, $i->current()); |
| 67 | + } |
| 68 | + |
| 69 | + public function testAlwaysObjects() |
| 70 | + { |
| 71 | + $i= new ObjectIterator($this->testObject); |
| 72 | + |
| 73 | + foreach ($i as $item) { |
| 74 | + $this->assertInstanceOf('\StdClass', $item); |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + public function testReachesAllProperties() |
| 79 | + { |
| 80 | + $i = new ObjectIterator($this->testObject); |
| 81 | + |
| 82 | + $count = 0; |
| 83 | + foreach ($i as $item) { |
| 84 | + $count += count(get_object_vars($item)); |
| 85 | + } |
| 86 | + |
| 87 | + $this->assertEquals(10, $count); |
| 88 | + } |
| 89 | +} |
0 commit comments