저자: Elliot Levin (elliotlevin@hotmail.com)
상속: extends pinq\ITraversable
예제 #1
0
 /**
  * @dataProvider oneToTen
  */
 public function testThatClearRemovesAllScopedItems(\Pinq\ICollection $collection, array $data)
 {
     $collection->where(function ($i) {
         return $i <= 5;
     })->clear();
     $this->assertMatches($collection, [5 => 6, 6 => 7, 7 => 8, 8 => 9, 9 => 10]);
 }
예제 #2
0
 /**
  * @dataProvider everything
  */
 public function testThatRemoveWhereFalseRemovesNoItems(\Pinq\ICollection $collection, array $data)
 {
     $collection->removeWhere(function () {
         return false;
     });
     $this->assertMatchesValues($collection, $data);
 }
예제 #3
0
 /**
  * @dataProvider oneToTenTwice
  */
 public function testThatRemoveWillRemovesIdenticalValuesFromCollectionAndPreserveKeys(\Pinq\ICollection $collection, array $data)
 {
     $collection->remove(1);
     $collection->remove('2');
     foreach ($data as $key => $value) {
         if ($value === 1 || $value === '2') {
             unset($data[$key]);
         }
     }
     $this->assertMatchesValues($collection, $data);
 }
예제 #4
0
 /**
  * @dataProvider oneToTen
  */
 public function testApplyDoesNotWorkAfterProjection(\Pinq\ICollection $collection, array $data)
 {
     $projectedCollection = $collection->select(function ($i) {
         return $i;
     });
     $projectedCollection->apply(function (&$i) {
         $i *= 10;
     });
     $this->assertMatches($collection, range(1, 10));
     $this->assertMatches($projectedCollection, range(1, 10));
 }
예제 #5
0
 /**
  * @dataProvider everything
  */
 public function testThatSetIndexWithNoKeyAppendsTheValueWithTheNextLargestIntGreaterThanOrEqualToZeroLikeAnArray(\Pinq\ICollection $collection, array $data)
 {
     $collection->clear();
     $collection[-5] = 'foo';
     $collection[] = 'bar';
     $collection[7] = 'baz';
     $collection[] = 'qux';
     $this->assertSame('foo', $collection[-5]);
     $this->assertSame('bar', $collection[0]);
     $this->assertSame('baz', $collection[7]);
     $this->assertSame('qux', $collection[8]);
     unset($collection[8]);
     $this->assertFalse(isset($collection[8]));
     $collection[] = 'qux1';
     $this->assertSame('qux1', $collection[8]);
     unset($collection[8], $collection[7]);
     $collection[] = 'boo';
     $this->assertSame('boo', $collection[1]);
 }
예제 #6
0
 public function visitClear(Operations\Clear $operation)
 {
     $this->collection->clear();
 }
예제 #7
0
 /**
  * @dataProvider oneToTen
  * @expectedException \Pinq\PinqException
  */
 public function testThatInvalidValueThrowsExceptionWhenCallingAddRange(\Pinq\ICollection $collection, array $data)
 {
     $collection->addRange(1);
 }
예제 #8
0
파일: Provider.php 프로젝트: timetoogo/pinq
 public function __construct(ICollection $collection)
 {
     parent::__construct(new Traversable\SourceInfo($collection), new Traversable\Provider($collection));
     $this->scheme = $collection->getIteratorScheme();
     $this->collection = $collection;
 }
예제 #9
0
 /**
  * @dataProvider oneToTen
  */
 public function testGroupJoinApplyToSelfWithInnerIndexBy(\Pinq\ICollection $collection)
 {
     $inner = $collection->indexBy(function ($i) {
         return $i - 1;
     })->select(function ($i) {
         return (int) $i;
     });
     $collection->groupJoin($inner)->on(function ($outer, $inner) {
         return $outer > $inner;
     })->apply(function (&$outer, \Pinq\ITraversable $group) {
         $outer .= ':' . $group->implode(',');
     });
     $this->assertMatches($collection, [0 => '1:', 1 => '2:1', 2 => '3:1,2', 3 => '4:1,2,3', 4 => '5:1,2,3,4', 5 => '6:1,2,3,4,5', 6 => '7:1,2,3,4,5,6', 7 => '8:1,2,3,4,5,6,7', 8 => '9:1,2,3,4,5,6,7,8', 9 => '10:1,2,3,4,5,6,7,8,9']);
 }
예제 #10
0
 /**
  * @dataProvider oneToTen
  */
 public function testThatOnEqualityWillNotMatchNullsAndUseDefault(\Pinq\ICollection $collection, array $data)
 {
     $collection->groupJoin($collection)->onEquality(function ($i) {
         return $i % 2 === 0 ? $i : null;
     }, function ($i) {
         return $i % 2 === 0 ? $i : null;
     })->withDefault('<DEFAULT>')->apply(function (&$outer, \Pinq\ITraversable $innerGroup) {
         $outer .= ':' . $innerGroup->implode('-');
     });
     $this->assertMatches($collection, ['1:<DEFAULT>', '2:2', '3:<DEFAULT>', '4:4', '5:<DEFAULT>', '6:6', '7:<DEFAULT>', '8:8', '9:<DEFAULT>', '10:10']);
 }
예제 #11
0
 public function __construct(ICollection $collection, IJoinIterator $joinIterator, callable $collectionFactory)
 {
     parent::__construct($collection->getIteratorScheme(), $joinIterator, $collectionFactory);
     $this->collection = $collection;
 }
 /**
  * @dataProvider oneToTen
  */
 public function testThatQueryUpdatesWhenSourceCollectionIsMutated(\Pinq\ICollection $collection, array $data)
 {
     $query = $collection->where(function ($i) {
         return $i % 2 === 0;
     })->orderByDescending(function ($i) {
         return $i;
     })->groupJoin(range(1, 10, 2))->on(function ($i, $v) {
         return $v < $i;
     })->to(function ($i, \Pinq\ITraversable $nums) {
         return $i . ':' . $nums->implode(',');
     });
     $this->assertMatchesValues($query, ['10:1,3,5,7,9', '8:1,3,5,7', '6:1,3,5', '4:1,3', '2:1']);
     $collection->removeRange([4, 5]);
     unset($collection[7]);
     $this->assertMatchesValues($query, ['10:1,3,5,7,9', '6:1,3,5', '2:1']);
 }