예제 #1
0
 protected function loadStops($file)
 {
     echo 'Loading Stops:';
     $csv = new SplFileObject($file);
     $csv->setFlags(SplFileObject::READ_CSV);
     $counter = 0;
     $first = true;
     foreach ($csv as $row) {
         if (implode('', $row) == '') {
             continue;
         }
         if ($first) {
             $first = false;
             continue;
         }
         $stopcode = $row[1];
         if (!empty($stopcode)) {
             $stopName = explode(',', $row[2]);
             $operator = explode(':', $row[0]);
             $stop = new BusStop();
             $stop->setCode($row[0])->setName(trim($stopName[1]))->setTown(trim($stopName[0]))->setCountry('NL')->setLatitude($row[3])->setLongitude($row[4])->setType($row[5])->setParent($row[6])->setWheelchair($row[8])->setOperator($operator[0]);
             $this->getEntityManager()->persist($stop);
             //echo "codename:" . $row[0];
             echo '.';
             $counter++;
             if ($counter == 2000) {
                 $counter = 0;
                 $this->getEntityManager()->flush();
                 echo '|';
             }
         }
     }
     $this->getEntityManager()->flush();
     echo PHP_EOL;
     echo 'Loading stops complete' . PHP_EOL;
     return true;
 }
예제 #2
0
 /**
  * @covers Application\Controller\BusstopController::pathAction
  */
 public function testPathAction()
 {
     $entityManager = $this->getMock('Doctrine\\ORM\\EntityManager', array(), array(), '', false);
     $entityRepository = $this->getMock('Doctrine\\ORM\\EntityRepository', array(), array(), '', false);
     $busstopRepository = $this->getMock('Doctrine\\ORM\\EntityRepository', array(), array(), '', false);
     $busstopLeft = new BusStop();
     $busstopLeft->setCode("HTM:2719");
     $busstopRight = new BusStop();
     $busstopRight->setCode("HTM:2901");
     $busstopRight->setCountry("NL");
     $busstopRight->setLatitude(5.1245);
     $busstopRight->setLongitude(42.853);
     $busstopRight->setName("testname");
     $busstopRight->setOperator("ARR");
     $busstopRight->setTown("Amsersfoort");
     $busstopRight->setType("type");
     $busstopRight->setWheelchair(1);
     $trackTo = new \Application\Entity\Track();
     $trackTo->setLeftBusStop($busstopLeft);
     $trackTo->setRightBusStop($busstopRight);
     $trackTo->setPto("ARR");
     $trackTo->setDistance(57649);
     $trackReturn = new \Application\Entity\Track();
     $trackReturn->setLeftBusStop($busstopRight);
     $trackReturn->setRightBusStop($busstopLeft);
     $trackReturn->setPto("ARR");
     $trackReturn->setDistance(57649);
     //find busstopfrom and busstopto
     $entityManager->expects($this->at(0))->method('getRepository')->with('Application\\Entity\\BusStop')->will($this->returnValue($entityRepository));
     $entityManager->expects($this->at(1))->method('getRepository')->with('Application\\Entity\\BusStop')->will($this->returnValue($entityRepository));
     $entityRepository->expects($this->any())->method('findOneBy')->will($this->returnValue($busstopLeft));
     //find tracks for busstopfrom and busstopto
     $entityManager->expects($this->at(2))->method('getRepository')->with('Application\\Entity\\Track')->will($this->returnValue($entityRepository));
     $entityRepository->expects($this->at(2))->method('findBy')->will($this->returnValue(array($trackTo)));
     $entityRepository->expects($this->at(3))->method('findBy')->will($this->returnValue(array($trackReturn)));
     $entityManager->expects($this->at(3))->method('getRepository')->with('Application\\Entity\\Track')->will($this->returnValue($entityRepository));
     $entityRepository->expects($this->at(4))->method('findBy')->will($this->returnValue(array($trackReturn)));
     $entityManager->expects($this->at(4))->method('getRepository')->with('Application\\Entity\\BusStop')->will($this->returnValue($entityRepository));
     $this->controller->setEntityManager($entityManager);
     $this->routeMatch->setParam('action', 'path');
     $this->routeMatch->setParam('from', 'HTM:2719');
     $this->routeMatch->setParam('to', 'HTM:2901');
     $result = $this->controller->dispatch($this->request);
     $response = $this->controller->getResponse();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertInstanceOf('Zend\\View\\Model\\ViewModel', $result);
 }