Skip to content

Commit 5e5e2c4

Browse files
committed
2 parents 879ad8b + d82c9c9 commit 5e5e2c4

9 files changed

+66
-17
lines changed

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
custom: ["https://rave.flutterwave.com/pay/trojantjkf"]

_config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
theme: jekyll-theme-cayman

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
convertNoticesToExceptions="true"
99
convertWarningsToExceptions="true"
1010
processIsolation="false"
11-
stopOnFailure="false">
11+
stopOnFailure="true">
1212
<testsuites>
1313
<testsuite name="Laravel Location Test Suite">
1414
<directory>tests</directory>

src/database/seeds/CitiesTableSeeder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
32
namespace Ichtrojan\Location\Seeds;
43

54
use Illuminate\Database\Seeder;
65
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
77

88
class CitiesTableSeeder extends Seeder
99
{
@@ -15,6 +15,10 @@ class CitiesTableSeeder extends Seeder
1515
public function run()
1616
{
1717
$citiesTable = config('location.cities_table', 'cities');
18+
19+
Schema::disableForeignKeyConstraints();
20+
DB::table($citiesTable)->truncate();
21+
Schema::enableForeignKeyConstraints();
1822

1923
$cities = array(
2024
array('name' => "Bombuflat",'state_id' => 1),

src/database/seeds/CountriesTableSeeder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
32
namespace Ichtrojan\Location\Seeds;
43

54
use Illuminate\Database\Seeder;
65
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
77

88
class CountriesTableSeeder extends Seeder
99
{
@@ -264,6 +264,10 @@ public function run()
264264
array('id' => 246,'code' => 'ZW','name' => "Zimbabwe",'phonecode' => 263),
265265
);
266266

267+
// Fix for issue #29 https://github.com/ichtrojan/laravel-location/issues/29
268+
Schema::disableForeignKeyConstraints();
269+
DB::table($countriesTable)->truncate();
270+
Schema::enableForeignKeyConstraints();
267271
DB::table($countriesTable)->insert($countries);
268272
}
269273
}

src/database/seeds/StateCityCountrySeeder.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<?php
2-
32
namespace Ichtrojan\Location\Seeds;
43

54
use Illuminate\Database\Seeder;

src/database/seeds/StatesTableSeeder.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
32
namespace Ichtrojan\Location\Seeds;
43

54
use Illuminate\Database\Seeder;
65
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
77

88
class StatesTableSeeder extends Seeder
99
{
@@ -4139,7 +4139,9 @@ public function run()
41394139
array('name' => "Matabeleland South",'country_id' => 246),
41404140
array('name' => "Midlands",'country_id' => 246)
41414141
);
4142-
4142+
Schema::disableForeignKeyConstraints();
4143+
DB::table($statesTable)->truncate();
4144+
Schema::enableForeignKeyConstraints();
41434145
DB::table($statesTable)->insert($states);
41444146
}
41454147
}

tests/LocationRouteTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Ichtrojan\Location\Test;
44

5+
use Ichtrojan\Location\Models\City;
6+
use Ichtrojan\Location\Models\State;
7+
58
class LocationRouteTest extends TestCase
69
{
710

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

129+
/** @test */
130+
public function test_all_states_have_country_id()
131+
{
132+
$count = State::query()
133+
->whereNull('country_id')
134+
->count();
135+
136+
$this->assertEquals(0, $count);
137+
}
138+
139+
/** @test */
140+
public function test_all_cities_have_country_id()
141+
{
142+
$count = City::query()
143+
->whereNull('country_id')
144+
->count();
145+
146+
$this->assertEquals(0, $count);
147+
}
148+
149+
/** @test */
150+
public function test_all_cities_have_state_id()
151+
{
152+
$count = City::query()
153+
->whereNull('state_id')
154+
->count();
155+
156+
$this->assertEquals(0, $count);
157+
}
158+
126159
}
127160

tests/TestCase.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
namespace Ichtrojan\Location\Test;
44

55
use Ichtrojan\Location\LocationServiceProvider;
6-
use Illuminate\Support\Facades\DB;
7-
use Illuminate\Support\Facades\Schema;
8-
use Illuminate\Database\Schema\Blueprint;
6+
use Ichtrojan\Location\Seeds\CountriesTableSeeder;
7+
use Ichtrojan\Location\Seeds\StatesTableSeeder;
8+
use Ichtrojan\Location\Seeds\CitiesTableSeeder;
9+
use Ichtrojan\Location\Seeds\StateCityCountrySeeder;
910
use Illuminate\Encryption\Encrypter;
1011
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
1112
use Orchestra\Testbench\Concerns\CreatesApplication;
@@ -51,6 +52,12 @@ protected function getEnvironmentSetUp($app)
5152
$app['config']->set('app.key', 'base64:' . base64_encode(
5253
Encrypter::generateKey($app['config']['app.cipher'])
5354
));
55+
56+
$app['config']->set('location.states_table', 'states');
57+
$app['config']->set('location.cities_table', 'cities');
58+
$app['config']->set('location.countries_table', 'countries');
59+
$app['config']->set('location.routes.prefix', 'location');
60+
$app['config']->set('location.routes.middleware', 'web');
5461
}
5562

5663
/**
@@ -96,26 +103,22 @@ protected function addCountryColumnToCitiesTable()
96103

97104
protected function seedCountriesTable()
98105
{
99-
include_once __DIR__ . '/../publishable/database/seeds/CountriesTableSeeder.php';
100-
(new \CountriesTableSeeder())->run();
106+
(new CountriesTableSeeder())->run();
101107
}
102108

103109
protected function seedStatesTable()
104110
{
105-
include_once __DIR__ . '/../publishable/database/seeds/StatesTableSeeder.php';
106-
(new \StatesTableSeeder())->run();
111+
(new StatesTableSeeder())->run();
107112
}
108113

109114
protected function seedCitiesTable()
110115
{
111-
include_once __DIR__ . '/../publishable/database/seeds/CitiesTableSeeder.php';
112-
(new \CitiesTableSeeder())->run();
116+
(new CitiesTableSeeder())->run();
113117
}
114118

115119
protected function updateCitiesTable()
116120
{
117-
include_once __DIR__ . '/../publishable/database/seeds/StateCityCountrySeeder.php';
118-
(new \StateCityCountrySeeder())->run();
121+
(new StateCityCountrySeeder())->run();
119122
}
120123

121124
}

0 commit comments

Comments
 (0)