Наследование: implements collections\CollectionInterface, use trait TypeValidator
 public function testIterator()
 {
     $col = new Collection('TestClassA');
     $iterator = $col->getIterator();
     $class = get_class($iterator);
     $this->assertEquals($class, "ArrayIterator");
 }
Пример #2
0
 public function testReverse()
 {
     $c = new Collection('int', [1, 2, 3]);
     $r = $c->reverse();
     $this->assertEquals([3, 2, 1], $r->toArray());
     $this->assertEquals([1, 2, 3], $c->toArray());
 }
Пример #3
0
 public function test_contains_finds_when_no_match_returns_false()
 {
     $result = $this->col->contains(function (TestClassA $item) {
         return $item->getValue() == 42;
     });
     $this->assertFalse($result);
 }
Пример #4
0
 public function test_find_returns_false_if_no_match()
 {
     $isOverTen = function (TestClassA $item) {
         return $item->getValue() > 10;
     };
     $result = $this->col->find($isOverTen);
     $this->assertFalse($result);
 }
Пример #5
0
 public function test_without_returns_items_that_do_not_match_criteria()
 {
     $col = new Collection('int', [1, 2, 3, 4, 5]);
     $odds = $col->without(function ($item) {
         return $item % 2 == 0;
     });
     $this->assertEquals(new Collection('int', [1, 3, 5]), $odds);
 }
Пример #6
0
 public function test_find_last_index_when_not_found()
 {
     $col = new Collection('int', [1, 2, 3]);
     $index = $col->findLastIndex(function ($x) {
         return $x === 4;
     });
     $this->assertEquals(-1, $index);
 }
Пример #7
0
 public function testToArray()
 {
     $items = array();
     $items[] = new TestClassA(1);
     $items[] = new TestClassA(2);
     $items[] = new TestClassA(3);
     $col = new Collection('TestClassA', $items);
     $this->assertEquals($items, $col->toArray());
 }
Пример #8
0
 public function test_clear_returns_an_empty_collection()
 {
     $col = new Collection('TestClassA', [new TestClassA(1)]);
     //col will have one
     $this->assertEquals(1, $col->count());
     //empty should have no items
     $empty = $col->clear();
     $this->assertEquals(0, $empty->count());
     //col should remain unchanged
     $this->assertEquals(1, $col->count());
 }
Пример #9
0
 public function test_that_tail_gives_you_everything_but_head()
 {
     $col = new Collection('int', [1, 2, 3]);
     $tail = $col->tail();
     $this->assertEquals(2, $tail->count());
     //col shouldn't be changed and should have 3 items
     $this->assertEquals(3, $col->count());
     //check that tail has two and three
     $this->assertEquals(2, $tail->at(0));
     $this->assertEquals(3, $tail->at(1));
 }
Пример #10
0
 public function test_sorts_with_callback()
 {
     $col = new Collection('int', [3, 1, 4, 2]);
     $comparator = function ($a, $b) {
         if ($a == $b) {
             return 0;
         }
         return $a < $b ? -1 : 1;
     };
     $sorted = $col->sort($comparator);
     $this->assertEquals(1, $sorted->at(0));
     $this->assertEquals(2, $sorted->at(1));
     $this->assertEquals(3, $sorted->at(2));
     $this->assertEquals(4, $sorted->at(3));
     //collection is unchanged
     $this->assertEquals([3, 1, 4, 2], $col->toArray());
 }
 protected function launch($element, $arguments, $memoized)
 {
     if ($element instanceof \launchers\launched\Method) {
         if (array_key_exists($element->name(), $this->objects)) {
             $element->init($arguments, $memoized);
             return $element->launch($this->objects[$element->name()]);
         } else {
             $this->exception('Trying to call method on non object', \fException::ERROR, $element->name(), $element->method());
         }
     } else {
         return parent::launch($element, $arguments, $memoized);
     }
 }
Пример #12
0
 /**
  * @expectedException Collections\Exceptions\InvalidArgumentException
  */
 public function test_take_too_many_throws_ex()
 {
     $this->col->take(100);
 }
Пример #13
0
 /**
  * Get a range of items in the collection
  *
  * @param integer $start The starting index of the range
  * @param integer $end The ending index of the range
  * @return {{FooCollection}} A collection of items matching the range
  */
 public function getRange($start, $end)
 {
     return parent::getRange($start, $end);
 }
Пример #14
0
 public function test_non_array_or_col_throws_ex()
 {
     $this->expectException(InvalidArgumentException::class);
     $col = new Collection('TestClassA');
     $col->merge(new TestClassA(1));
 }
Пример #15
0
 public function test_drop_all_gives_empty_collection()
 {
     $col = $this->col->drop(3);
     $this->assertEquals(0, $col->count());
 }
 public function testIndexExitsRejectsNonIntegers()
 {
     $this->setExpectedException("Collections\\Exceptions\\InvalidArgumentException");
     $col = new Collection('TestClassA');
     $col->indexExists("wat");
 }
Пример #17
0
 public function test_index_returns_value()
 {
     $col = new Collection('TestClassA', [new TestClassA(1)]);
     $res = $col->at(0);
     $this->assertEquals(new TestClassA(1), $res);
 }
Пример #18
0
 public function test_dr_all_but_one_leaves_first_item()
 {
     $col = $this->col->dropRight(2);
     $this->assertEquals(1, $col->count());
     $this->assertEquals($this->items[0], $col->at(0));
 }
 /**
  * ProcessingCheckCollection constructor.
  */
 public function __construct()
 {
     parent::__construct(static::OBJECT_CLASS);
 }
 public function testGetObjectName()
 {
     $col = new Collection('TestClassA');
     $this->assertEquals("TestClassA", $col->getType());
 }
Пример #21
0
 /**
  * @expectedException Collections\Exceptions\InvalidArgumentException
  */
 public function test_adding_wrong_class_triggers_error()
 {
     $col = new Collection('TestClassA');
     $col->add(new TestClassB());
 }
Пример #22
0
 public function test_subset_with_only_end()
 {
     $subset = $this->c->slice(9, 9);
     $this->assertEquals(1, $subset->count());
     $this->assertEquals($this->items[9], $subset->at(0));
 }