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)]);
 }
Example #2
0
 private function calculateRoute()
 {
     $referenceStart = array_search($this->route->getStart()->gate, Gate::listGates($this->route->getWay()));
     $referenceEnd = array_search($this->route->getEnd()->gate, Gate::listGates($this->route->getWay()));
     $dataCalculated = ['time' => 0, 'timeReference' => 0, 'kms' => 0];
     if ($referenceStart >= $referenceEnd) {
         while ($referenceStart < count(Gate::listGates($this->route->getWay()))) {
             $section = $this->sectionCollection->getItems($this->route->getWay(), $referenceStart);
             $this->route->setSection($section);
             $dataCalculated = $this->incrementValues($dataCalculated, $section->getData());
             $referenceStart++;
         }
         //and restart
         $cursor = 0;
         while ($cursor < $referenceEnd) {
             $section = $this->sectionCollection->getItems($this->route->getWay(), $cursor);
             $this->route->setSection($section);
             foreach ($section->getData() as $field => $number) {
                 $dataCalculated[$field] += (int) $number;
             }
             $cursor++;
         }
     } else {
         while ($referenceStart < $referenceEnd) {
             $section = $this->sectionCollection->getItems($this->route->getWay(), $referenceStart);
             $this->route->setSection($section);
             $dataCalculated = $this->incrementValues($dataCalculated, $section->getData());
             $referenceStart++;
         }
     }
     foreach ($dataCalculated as $field => $value) {
         $this->route->{'set' . ucwords($field)}($value);
     }
 }