private function sanitizeContent() { $results = $this->dataFetched; $this->sectionCollection = new SectionCollection(); foreach ($results as $way) { foreach ($way as $wayName => $gate) { //unset 'BP' unset($gate[0]); $gate = array_values($gate); preg_match('/P.(.*)\\(.*\\)=>P.(.*)\\(.*\\)/x', $gate[0], $gates); $section = new Section(new Gate(strtolower($gates[1]), 'start'), new Gate(strtolower($gates[2]), 'end'), ['time' => (int) str_replace('mn', '', $gate[1]), 'timeReference' => (int) str_replace('mn', '', $gate[2]), 'kms' => (int) $gate[3]]); $this->sectionCollection->add($section, $wayName); } } }
public function testAddGateToCollection() { $startGate = new Gate('chapelle', 'start'); $endGate = new Gate('orleans', 'end'); $section = new Section($startGate, $endGate, []); $collection = new SectionCollection(); $collection->add($section, 'interior'); $collection->add($section, 'exterior'); $collection->add($section, 'exterior'); $this->assertArrayHasKey('interior', $collection->getItems()); $this->assertArrayHasKey('exterior', $collection->getItems()); $this->assertCount(1, $collection->getItems('interior')); $this->assertCount(2, $collection->getItems('exterior')); $this->assertCount(2, $collection->getItems()); $this->assertCount(1, [$collection->getItems('interior', 0)]); }