MapIteratorTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testMapIterator() 0 5 1
A testInvalidArgument() 0 4 1
A imap() 0 4 1
1
<?php
2
3
namespace itertools;
4
5
use EmptyIterator;
6
use ArrayIterator;
7
use PHPUnit_Framework_TestCase;
8
9
10
class MapIteratorTest extends PHPUnit_Framework_TestCase
11
{
12
	/** @test */
13
	public function testMapIterator()
14
	{
15
		$square = function($n) { return $n * $n; };
16
		$this->assertEquals(array_map($square, array(1, 2, 3)), $this->imap(array(1, 2, 3), $square));
17
	}
18
19
	/**
20
	 * @test
21
	 * @expectedException \InvalidArgumentException
22
	 */
23
	public function testInvalidArgument()
24
	{
25
		new MapIterator(new EmptyIterator(), 1);
26
	}
27
28
	protected function imap($array, $callable)
29
	{
30
		return iterator_to_array(new MapIterator($array, $callable));
31
	}
32
}
33
34