diff options
Diffstat (limited to 'www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Iterators/ChunkedIteratorTest.php')
-rw-r--r-- | www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Iterators/ChunkedIteratorTest.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Iterators/ChunkedIteratorTest.php b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Iterators/ChunkedIteratorTest.php new file mode 100644 index 00000000..449adfdd --- /dev/null +++ b/www/wiki/extensions/SemanticMediaWiki/tests/phpunit/Unit/Iterators/ChunkedIteratorTest.php @@ -0,0 +1,69 @@ +<?php + +namespace SMW\Tests\Iterators; + +use SMW\Iterators\ChunkedIterator; +use SMW\Tests\PHPUnitCompat; + +/** + * @covers \SMW\Iterators\ChunkedIterator + * @group semantic-mediawiki + * + * @license GNU GPL v2+ + * @since 3.0 + * + * @author mwjames + */ +class ChunkedIteratorTest extends \PHPUnit_Framework_TestCase { + + use PHPUnitCompat; + + public function testCanConstruct() { + + $this->assertInstanceOf( + ChunkedIterator::class, + new ChunkedIterator( [] ) + ); + } + + public function testChunkedOnArray() { + + $result = [ + 1, 42, 1001, 9999 + ]; + + $instance = new ChunkedIterator( $result, 2 ); + + foreach ( $instance as $chunk ) { + $this->assertCount( + 2, + $chunk + ); + } + + $chunks = iterator_to_array( $instance, false ); + + $this->assertEquals( + [1, 42], + $chunks[0] + ); + + $this->assertEquals( + [1001, 9999], + $chunks[1] + ); + } + + public function testInvalidConstructorArgumentThrowsException() { + + $this->setExpectedException( 'RuntimeException' ); + $instance = new ChunkedIterator( 2 ); + } + + public function testInvalidChunkSizeArgumentThrowsException() { + + $this->setExpectedException( 'InvalidArgumentException' ); + $instance = new ChunkedIterator( [], -1 ); + } + +} |