Skip to content

Commit

Permalink
Add tests for implicit objects in iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
rtheunissen committed Apr 24, 2017
1 parent 59193bb commit fd4f9ad
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 8 deletions.
37 changes: 35 additions & 2 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
namespace Ds\Tests;

use Ds\Collection;
use PHPUnit_Framework_TestCase;

abstract class CollectionTest extends \PHPUnit_Framework_TestCase
abstract class CollectionTest extends PHPUnit_Framework_TestCase
{
/**
* Sample sizes.
Expand Down Expand Up @@ -166,7 +167,7 @@ public function assertInstanceDump(array $expected, $instance)

}

public function assertSerialized(array $expected, $instance, $use_keys)
public function assertSerialized(array $expected, $instance)
{
$unserialized = unserialize(serialize($instance));

Expand All @@ -186,6 +187,18 @@ public function assertForEach(array $expected, $instance)
}

$this->assertEquals($expected, $data);

/**
* @see https://github.com/php-ds/extension/issues/82
*/
$producer = new Producer($this);
$iterated = [];

foreach ($producer->getInstance($expected) as $key => $value) {
$iterated[$key] = $value;
}

$this->assertEquals($expected, $iterated);
}

public function assertForEachByReferenceThrowsException($instance)
Expand All @@ -207,3 +220,23 @@ protected function cleanVarDump($expression)
ini_set('xdebug.overload_var_dump', $overload_var_dump);
}
}

/**
* @internal
* @see assertForEach
* @see https://github.com/php-ds/extension/issues/82
*/
class Producer {

private $test;

public function __construct($test) {
$this->test = $test;
}

public function getInstance(array $values = null)
{
return $this->test->getInstance($values);
}
}

2 changes: 1 addition & 1 deletion tests/DequeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class DequeTest extends CollectionTest
use Sequence\toArray;
use Sequence\unshift;

protected function getInstance(array $values = [])
public function getInstance(array $values = [])
{
return new \Ds\Deque($values);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/MapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MapTest extends CollectionTest
use Map\values;
use Map\xor_;

protected function getInstance(array $values = [])
public function getInstance(array $values = [])
{
return new \Ds\Map($values);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class QueueTest extends CollectionTest
use Queue\push;
use Queue\toArray;

protected function getInstance(array $values = [])
public function getInstance(array $values = [])
{
return new \Ds\Queue($values);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SetTest extends CollectionTest
use Set\union;
use Set\xor_;

protected function getInstance(array $values = [])
public function getInstance(array $values = [])
{
return new \Ds\Set($values);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/StackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class StackTest extends CollectionTest
use Stack\push;
use Stack\toArray;

protected function getInstance(array $values = [])
public function getInstance(array $values = [])
{
return new \Ds\Stack($values);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/VectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class VectorTest extends CollectionTest
use Sequence\toArray;
use Sequence\unshift;

protected function getInstance(array $values = [])
public function getInstance(array $values = [])
{
return new \Ds\Vector($values);
}
Expand Down

0 comments on commit fd4f9ad

Please sign in to comment.