public function testNormalisePostCode()
 {
     $original = '1AA 2BB';
     $expected = strtolower(str_replace(' ', '', $original));
     $this->assertEmpty($this->instance->getPostcode());
     $this->assertEmpty($this->instance->getNormalisedPostcode());
     $this->assertInstanceOf(Authority::class, $this->instance->setPostcode($original));
     $this->assertEquals($original, $this->instance->getPostcode());
     $this->assertEquals($expected, $this->instance->getNormalisedPostcode());
 }
 /**
  * @param ObjectManager $manager
  * @return LoadTestPostCodes
  */
 protected function loadPostCodeInNewcastle(ObjectManager $manager)
 {
     $url = "newcastle.gov.uk";
     $auth = new Authority();
     $dc = new DistrictCouncil('E08000021', 'Newcastle upon Tyne');
     $ew = new ElectoralWard('E05001111', 'Westgate');
     $dc->setWebsite($url);
     $auth->setDistrictCouncil($dc);
     $auth->setCountry('England');
     $auth->setCounty($this->englandGlobalCounty);
     $auth->setElectoralWard($ew);
     $auth->setPostcode("NE1 7RS");
     $manager->persist($auth);
     $manager->flush();
     return $this;
 }
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $file = $input->getArgument('path');
     $counter = 0;
     $handle = $this->checkForAndOpenFile($file, $output);
     if (true === is_resource($handle)) {
         $authService = $this->getAuthorityService();
         while ($row = fgetcsv($handle)) {
             if ($counter > 0) {
                 $data = array_combine($this->headers, $row);
                 $authority = new Authority();
                 $authority->setPostcode($data['pcd']);
                 $authority = $this->addCountyToAuthority($data['oscty'], $authority);
                 $authority = $this->addDistrictCouncilToAuthority($data['oslaua'], $authority);
                 $authority->setCountry(Country::getCountryName($data['ctry']));
                 $authority = $this->addLocalHealthAuthorityToAuthority($data['pct'], $authority);
                 $authority = $this->addElectoralWardToAuthority($data['osward'], $authority);
                 $authority = $this->addParishCouncilToAuthority($data['parish'], $authority);
                 $authority = $authService->saveAuthority($authority);
                 $action = 'Created';
                 if (null !== $authority->getLastUpdated()) {
                     $action = 'Updated';
                 }
                 $output->writeln($action . ' Authority for ' . $authority->getPostcode() . ' with id ' . $authority->getId());
             } else {
                 $this->extractHeaders($row);
             }
             ++$counter;
         }
         fclose($handle);
     }
 }