/** * @test */ public function testIterator() { $rules = [BaseAdapter::RULE_TYPE_TO_DATA => ['id']]; $adapter = new BaseAdapter(); $adapter->setEntityClass(self::OS_CLASS_NAME); $adapter->setRules($rules); $fixture = $this->getFixtureEntity(); $adapter->setInnerIterator(new \ArrayIterator([$fixture, $this->getFixtureEntity()])); $i = 0; foreach ($adapter as $data) { $this->assertEquals(['id' => $fixture->id], (array) $data); $i++; } $this->assertEquals(2, $i); }
/** * {@inheritdoc} * @see BaseAdapter::toData() */ public function toData($entity) { $result = parent::toData($entity); $converterRules = $this->getRules(); if (!empty($converterRules[static::RULE_TYPE_SETTINGS])) { $collection = $this->getSettingsCollection($entity); foreach ($converterRules[static::RULE_TYPE_SETTINGS] as $key => $property) { //Some properties only for writing we can't include them in the response if ($property[0] == '!') { continue; } //This is necessary when result data key does not match the property name of the entity $key = is_int($key) ? $property : $key; $result->{$property} = $collection[$key]; } } return $result; }
/** * @test * @param string $filedType * @param mixed $value Value what we have to convert * @dataProvider providerConvertInputValue() * @expectedException \UnexpectedValueException */ public function testConvertInputValue($filedType, $value) { BaseAdapter::convertInputValue($filedType, $value); }