public function run()
 {
     County::create(['id' => '01', 'name' => 'Østfold']);
     County::create(['id' => '02', 'name' => 'Akershus']);
     County::create(['id' => '03', 'name' => 'Oslo']);
     County::create(['id' => '04', 'name' => 'Hedmark']);
     County::create(['id' => '05', 'name' => 'Oppland']);
     County::create(['id' => '06', 'name' => 'Buskerud']);
     County::create(['id' => '07', 'name' => 'Vestfold']);
     County::create(['id' => '08', 'name' => 'Telemark']);
     County::create(['id' => '09', 'name' => 'Aust-Agder']);
     County::create(['id' => '10', 'name' => 'Vest-Agder']);
     County::create(['id' => '11', 'name' => 'Rogaland']);
     County::create(['id' => '12', 'name' => 'Hordaland']);
     County::create(['id' => '14', 'name' => 'Sogn og Fjordane']);
     County::create(['id' => '15', 'name' => 'Møre og Romsdal']);
     County::create(['id' => '16', 'name' => 'Sør-Trøndelag']);
     County::create(['id' => '17', 'name' => 'Nord-Trøndelag']);
     County::create(['id' => '18', 'name' => 'Nordland']);
     County::create(['id' => '19', 'name' => 'Troms']);
     County::create(['id' => '20', 'name' => 'Finnmark']);
     County::create(['id' => '21', 'name' => 'Svalbard']);
     County::create(['id' => '22', 'name' => 'Jan Mayen']);
     County::create(['id' => '23', 'name' => 'Kontinentalsokkelen']);
 }
 public function testFindMunicipalityArray()
 {
     $county = \NorwegianZipCodes\Models\County::create(['id' => 1, 'name' => 'TestCounty']);
     $county->municipalities()->create(['id' => '0101', 'name' => 'Akershus']);
     $county->municipalities()->create(['id' => '0102', 'name' => 'Østfold']);
     $this->assertCount(2, Municipality::find(['0101', '0102']));
 }
 public function testFindZipCodeArray()
 {
     $county = \NorwegianZipCodes\Models\County::create(['id' => 1, 'name' => 'TestCounty']);
     $municipality = new \NorwegianZipCodes\Models\Municipality(['id' => 101, 'name' => 'Test']);
     $county->municipalities()->save($municipality);
     $municipality->zip_codes()->save(new ZipCode(['id' => '0111', 'name' => 'TestZipCode']));
     $municipality->zip_codes()->save(new ZipCode(['id' => '0112', 'name' => 'TestZipCode']));
     $this->assertCount(2, ZipCode::find(['0111', '0112']));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire(Dispatcher $dispatcher)
 {
     $dispatcher->fire('zip_codes.update.starting');
     $this->counties = County::all();
     $url = $this->getRemoteZipCodeFile();
     $parser = app(RemoteZipCodeFileParser::class);
     $parser->parse($url, function (RemoteZipCodeObject $object) {
         $municipality = $this->updateMunicipality($object->municipality_id, $object->municipality_name);
         $this->updateZipCode($municipality, $object->id, $object->name);
     });
     $dispatcher->fire(new ZipCodesUpdated($this->added, $this->changed));
 }
 public function testOldAreChanged()
 {
     /* @var County $county */
     $county = County::find('04');
     $county->municipalities()->save(new Municipality(['id' => '0403', 'name' => 'Hamar']));
     $county->municipalities()->save(new Municipality(['id' => '0417', 'name' => 'STANGE']));
     $fired = false;
     $event = app(Dispatcher::class);
     $event->listen(ZipCodesUpdated::class, function (ZipCodesUpdated $update) use(&$fired) {
         $fired = true;
         $this->assertEquals(1, $update->changed);
     });
     $cmd = new TestUpdateZipCodesCommand();
     $cmd->fire($event);
     //
     $this->assertTrue($fired);
 }
 public function testFindCountyArray()
 {
     County::create(['id' => 1, 'name' => 'Akershus']);
     County::create(['id' => 2, 'name' => 'Østfold']);
     $this->assertCount(2, County::find([1, 2]));
 }