function its_normalize_method_throw_exception_when_required_field_name_key_is_not_passed($serializer, Collection $collection) { $collection->getIterator()->willReturn(new \ArrayIterator([4, 8, 15])); $serializer->normalize(4, null, ['foo' => 'bar'])->willReturn('Four'); $serializer->normalize(8, null, ['foo' => 'bar'])->willReturn('Eight'); $serializer->normalize(15, null, ['foo' => 'bar'])->willReturn('Fifteen'); $this->shouldThrow(new InvalidArgumentException('Missing required "field_name" context value, got "foo"'))->duringNormalize($collection, null, ['foo' => 'bar']); }
function it_creates_an_article(Blog $blog, Title $title, Text $teaser, Collection $rawDisplayables, SlugifierInterface $slugifier, Slug $slug) { $slugifier->slugify($title)->shouldBeCalled()->willReturn($slug); $blog->addPost(Argument::that(function ($argument) use($slug) { return $argument instanceof Article && $argument->getSlug() === $slug->getWrappedObject(); }))->shouldBeCalled(); $rawDisplayables->getIterator()->willReturn(new \ArrayIterator([])); $this->create($blog, $title, $teaser, $rawDisplayables)->shouldBeAnInstanceOf(Article::class); }
function it_normalizes_value_with_empty_collection_data(ProductValueInterface $value, AbstractAttribute $attribute, Collection $collection, \Iterator $iterator) { $attribute->getCode()->willReturn('code'); $attribute->isLocalizable()->willReturn(false); $attribute->isScopable()->willReturn(false); $collection->getIterator()->willReturn($iterator); $value->getData()->willReturn($collection); $value->getAttribute()->willReturn($attribute); $this->normalize($value, 'mongodb_json', [])->shouldReturn(null); }
function it_adds_an_address_when_different_than_the_ones_present_on_the_customer(AddressComparatorInterface $addressComparator, CustomerInterface $customer, AddressInterface $customerAddress, AddressInterface $newAddress, Collection $addresses, \Iterator $iterator) { $iterator->rewind()->shouldBeCalled(); $iterator->valid()->willReturn(true); $iterator->current()->willReturn($customerAddress); $iterator->valid()->willReturn(false); $addresses->getIterator()->willReturn($iterator); $customer->getAddresses()->willReturn($addresses); $addressComparator->equal($customerAddress, $newAddress)->willReturn(false); $customer->addAddress($newAddress)->shouldBeCalled(); $this->add($customer, $newAddress); }
/** * @param Collection $worklogs * @return void */ private function initialize(Collection $worklogs) { /** @var \Iterator $iterator */ $iterator = $worklogs->getIterator(); $iterator->rewind(); if ($iterator->valid()) { while ($iterator->valid()) { /** @var Worklog $worklog */ $worklog = $iterator->current(); if (!array_key_exists($worklog->getTask()->getId(), $this->elements)) { $this->elements[$worklog->getTask()->getId()] = new Task($worklog->getTask(), $this->period); } /** @var Task $task */ $task = $this->elements[$worklog->getTask()->getId()]; /** @var \DateTime $date */ $date = clone $worklog->getDateStarted(); $date->setTimezone($this->timezone); $task->addTimeSpent($date, $worklog->getTimeSpent()); $iterator->next(); } } }
/** * {@inheritdoc} */ public function getIterator() { $this->initialize(); return $this->coll->getIterator(); }
/** * (PHP 5 >= 5.0.0)<br/> * Retrieve an external iterator * @link http://php.net/manual/en/iteratoraggregate.getiterator.php * @return Traversable An instance of an object implementing <b>Iterator</b> or * <b>Traversable</b> */ public function getIterator() { $this->initialize(); return new InnerTermIterator($this->collection->getIterator()); }
/** * {@inheritdoc} */ public function getIterator() { return $this->inner->getIterator(); }
/** * Allows to iterate over sub properties. * * @return \ArrayIterator */ public function getIterator() { return $this->properties->getIterator(); }
/** * @param Collection $players * * @return ArrayCollection */ public function sortMembersByBalance(Collection $players) { $iterator = $players->getIterator(); $iterator->uasort(function ($a, $b) { return $b->getBalance() - $a->getBalance(); }); return new ArrayCollection(iterator_to_array($iterator)); }
/** * @dataProvider provideCollection */ public function testIterator(Collection $coll, array $elements) { $iterations = 0; foreach ($coll->getIterator() as $key => $item) { $this->assertSame($elements[$key], $item, "Item {$key} not match"); $iterations++; } $this->assertEquals(count($elements), $iterations, "Number of iterations not match"); }
/** * Sorts a doctrine collection from an array of filters * @param Collection $collection * @param array $filters * @return Collection * @author Yohann Marillet * @deprecated this function is very slow on large sets of data */ public function sort(Collection $collection, array $filters) { if (isset($filters['sort'])) { /** @var \ArrayIterator $it */ $it = $collection->getIterator(); $that = $this; $it->uasort(function ($first, $second) use($filters, $that) { $return = 0; if ($first !== $second) { $sortFilters = $filters['sort']; $cur = reset($sortFilters); while ($return == 0 && false !== $cur) { $k = key($sortFilters); $v1 = $that->getValueFromDQLField($first, $k); $v2 = $that->getValueFromDQLField($second, $k); if ($v1 != $v2) { $return = $v1 > $v2 ? 1 : -1; //var_dump($v1.', '.$v2.' : '.$return); if ($cur == 'DESC') { $return = $return * -1; } } $cur = next($sortFilters); } } return $return; }); } return $collection; }