Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ichtrojan committed Mar 29, 2020
2 parents 879ad8b + d82c9c9 commit 5e5e2c4
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

custom: ["https://rave.flutterwave.com/pay/trojantjkf"]
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-cayman
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
stopOnFailure="true">
<testsuites>
<testsuite name="Laravel Location Test Suite">
<directory>tests</directory>
Expand Down
6 changes: 5 additions & 1 deletion src/database/seeds/CitiesTableSeeder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Ichtrojan\Location\Seeds;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CitiesTableSeeder extends Seeder
{
Expand All @@ -15,6 +15,10 @@ class CitiesTableSeeder extends Seeder
public function run()
{
$citiesTable = config('location.cities_table', 'cities');

Schema::disableForeignKeyConstraints();
DB::table($citiesTable)->truncate();
Schema::enableForeignKeyConstraints();

$cities = array(
array('name' => "Bombuflat",'state_id' => 1),
Expand Down
6 changes: 5 additions & 1 deletion src/database/seeds/CountriesTableSeeder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Ichtrojan\Location\Seeds;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class CountriesTableSeeder extends Seeder
{
Expand Down Expand Up @@ -264,6 +264,10 @@ public function run()
array('id' => 246,'code' => 'ZW','name' => "Zimbabwe",'phonecode' => 263),
);

// Fix for issue #29 https://github.com/ichtrojan/laravel-location/issues/29
Schema::disableForeignKeyConstraints();
DB::table($countriesTable)->truncate();
Schema::enableForeignKeyConstraints();
DB::table($countriesTable)->insert($countries);
}
}
1 change: 0 additions & 1 deletion src/database/seeds/StateCityCountrySeeder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace Ichtrojan\Location\Seeds;

use Illuminate\Database\Seeder;
Expand Down
6 changes: 4 additions & 2 deletions src/database/seeds/StatesTableSeeder.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

namespace Ichtrojan\Location\Seeds;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

class StatesTableSeeder extends Seeder
{
Expand Down Expand Up @@ -4139,7 +4139,9 @@ public function run()
array('name' => "Matabeleland South",'country_id' => 246),
array('name' => "Midlands",'country_id' => 246)
);

Schema::disableForeignKeyConstraints();
DB::table($statesTable)->truncate();
Schema::enableForeignKeyConstraints();
DB::table($statesTable)->insert($states);
}
}
33 changes: 33 additions & 0 deletions tests/LocationRouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Ichtrojan\Location\Test;

use Ichtrojan\Location\Models\City;
use Ichtrojan\Location\Models\State;

class LocationRouteTest extends TestCase
{

Expand Down Expand Up @@ -123,5 +126,35 @@ public function it_can_access_cities_by_country()
$this->assertEquals($firstCity, $responseData[0]);
}

/** @test */
public function test_all_states_have_country_id()
{
$count = State::query()
->whereNull('country_id')
->count();

$this->assertEquals(0, $count);
}

/** @test */
public function test_all_cities_have_country_id()
{
$count = City::query()
->whereNull('country_id')
->count();

$this->assertEquals(0, $count);
}

/** @test */
public function test_all_cities_have_state_id()
{
$count = City::query()
->whereNull('state_id')
->count();

$this->assertEquals(0, $count);
}

}

25 changes: 14 additions & 11 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Ichtrojan\Location\Test;

use Ichtrojan\Location\LocationServiceProvider;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Ichtrojan\Location\Seeds\CountriesTableSeeder;
use Ichtrojan\Location\Seeds\StatesTableSeeder;
use Ichtrojan\Location\Seeds\CitiesTableSeeder;
use Ichtrojan\Location\Seeds\StateCityCountrySeeder;
use Illuminate\Encryption\Encrypter;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Orchestra\Testbench\Concerns\CreatesApplication;
Expand Down Expand Up @@ -51,6 +52,12 @@ protected function getEnvironmentSetUp($app)
$app['config']->set('app.key', 'base64:' . base64_encode(
Encrypter::generateKey($app['config']['app.cipher'])
));

$app['config']->set('location.states_table', 'states');
$app['config']->set('location.cities_table', 'cities');
$app['config']->set('location.countries_table', 'countries');
$app['config']->set('location.routes.prefix', 'location');
$app['config']->set('location.routes.middleware', 'web');
}

/**
Expand Down Expand Up @@ -96,26 +103,22 @@ protected function addCountryColumnToCitiesTable()

protected function seedCountriesTable()
{
include_once __DIR__ . '/../publishable/database/seeds/CountriesTableSeeder.php';
(new \CountriesTableSeeder())->run();
(new CountriesTableSeeder())->run();
}

protected function seedStatesTable()
{
include_once __DIR__ . '/../publishable/database/seeds/StatesTableSeeder.php';
(new \StatesTableSeeder())->run();
(new StatesTableSeeder())->run();
}

protected function seedCitiesTable()
{
include_once __DIR__ . '/../publishable/database/seeds/CitiesTableSeeder.php';
(new \CitiesTableSeeder())->run();
(new CitiesTableSeeder())->run();
}

protected function updateCitiesTable()
{
include_once __DIR__ . '/../publishable/database/seeds/StateCityCountrySeeder.php';
(new \StateCityCountrySeeder())->run();
(new StateCityCountrySeeder())->run();
}

}

0 comments on commit 5e5e2c4

Please sign in to comment.