Skip to content

Commit

Permalink
Исправление инициализации ArrayMap. Реализация тестов
Browse files Browse the repository at this point in the history
  • Loading branch information
petrgrishin committed Jun 26, 2014
1 parent 124a3fd commit a5d91d6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/ArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function remove($path) {
}

public function getMap() {
if ($this->map) {
if (!$this->map) {
$this->map = ArrayMap::create($this);
}
return $this->map;
Expand Down
76 changes: 27 additions & 49 deletions tests/unit/ArrayAccessTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
use \PetrGrishin\ArrayAccess\ArrayAccess;
use PetrGrishin\ArrayMap\ArrayMap;

/**
* @author Petr Grishin <[email protected]>
Expand Down Expand Up @@ -158,53 +159,30 @@ public function testRemoveElementByNotExistKeyInPath() {
$instance->remove('notExistKye1.notExistKye2');
}

// public function testSimpleMapping() {
// $original = array(1, 2, 3);
// $instance = ArrayAccess::create($original);
// $instance->map(function ($value) {
// return $value * 2;
// });
// $this->assertEquals(array(2, 4, 6), $instance->getArray());
// }
//
// public function testKeyMapping() {
// $original = array(1 => 1, 2 => 2, 3 => 3);
// $instance = ArrayAccess::create($original);
// $instance->map(function ($value, $key) {
// return array(($key - 1) => $value * 2);
// });
// $this->assertEquals(array(0 => 2, 1 => 4, 2 => 6), $instance->getArray());
// }
//
// public function testMergeWith() {
// $original = array(1, 2, 3);
// $instance = ArrayAccess::create($original);
// $instance->mergeWith(array(4, 5, 6), false);
// $this->assertEquals(array(1, 2, 3, 4, 5, 6), $instance->getArray());
// }
//
// public function testRecursiveMergeWith() {
// $original = array('a' => array(1), 'b', 'c');
// $instance = ArrayAccess::create($original);
// $instance->mergeWith(array('a' => array(2), 'd', 'e'));
// $this->assertEquals(array('a' => array(1, 2), 'b', 'c', 'd', 'e'), $instance->getArray());
// }
//
// public function testFiltering() {
// $original = array('a' => 1, 'b' => 2, 'c' => 3);
// $instance = ArrayAccess::create($original);
// $instance->filter(function ($value) {
// return $value > 2;
// });
// $this->assertEquals(array('c' => 3), $instance->getArray());
// }
//
// public function testFilteringUseKeys() {
// $original = array('a' => 1, 'b' => 2, 'c' => 3);
// $instance = ArrayAccess::create($original);
// $instance->filter(function ($value, $key) {
// return $key === 'c';
// });
// $this->assertEquals(array('c' => 3), $instance->getArray());
// }
public function testMap() {
$instance = new ArrayAccess();
$this->assertInstanceOf(ArrayMap::className(), $instance->getMap());
}

public function testSimpleMapping() {
$original = array(1, 2, 3);
$instance = ArrayAccess::create($original);
$instance->getMap()->map(function ($value) {
return $value * 2;
});
$this->assertEquals(array(2, 4, 6), $instance->getArray());
$instance->getMap()->map(function ($value) {
return $value * 2;
});
$this->assertEquals(array(4, 8, 12), $instance->getArray());
}

public function testKeyMapping() {
$original = array(1 => 1, 2 => 2, 3 => 3);
$instance = ArrayAccess::create($original);
$instance->getMap()->map(function ($value, $key) {
return array(($key - 1) => $value * 2);
});
$this->assertEquals(array(0 => 2, 1 => 4, 2 => 6), $instance->getArray());
}
}

0 comments on commit a5d91d6

Please sign in to comment.