Skip to content

fix: set primary key as string #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Models/City.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class City extends Model
{
protected $primaryKey = 'code';

protected $keyType = 'string';

public $incrementing = false;

protected $fillable = [
'code', 'province_code', 'name', 'latitude', 'longitude',
];
Expand Down
4 changes: 4 additions & 0 deletions src/Models/District.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class District extends Model
{
protected $primaryKey = 'code';

protected $keyType = 'string';

public $incrementing = false;

protected $fillable = [
'code', 'city_code', 'name', 'latitude', 'longitude',
];
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Province.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Province extends Model

protected $primaryKey = 'code';

protected $keyType = 'string';

public $incrementing = false;

protected $fillable = [
'code', 'name', 'latitude', 'longitude',
];
Expand Down
4 changes: 4 additions & 0 deletions src/Models/Village.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ class Village extends Model

protected $primaryKey = 'code';

protected $keyType = 'string';

public $incrementing = false;

protected $fillable = [
'code', 'district_code', 'name', 'latitude', 'longitude', 'postal_code',
];
Expand Down
54 changes: 27 additions & 27 deletions tests/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
expect(Province::first())->not->toBeEmpty();

$province = Province::find(33);
expect($province->code)->toBe(33);
expect($province->code)->toBe('33');
expect($province->name)->toBe('JAWA TENGAH');
expect($province->latitude)->toBe('-7.150975');
expect($province->longitude)->toBe('110.1402594');
Expand All @@ -49,33 +49,33 @@
$cities = Province::find(33)->cities;
expect($cities)->toBeInstanceOf(Collection::class);
expect($cities->count())->toBe(35);
expect($cities->first()->code)->toBe(3301);
expect($cities->first()->code)->toBe('3301');
expect($cities->first()->name)->toBe('KABUPATEN CILACAP');
expect($cities->last()->code)->toBe(3376);
expect($cities->last()->code)->toBe('3376');
expect($cities->last()->name)->toBe('KOTA TEGAL');

$districts = Province::find(33)->districts;
expect($districts)->toBeInstanceOf(Collection::class);
expect($districts->count())->toBe(576);
expect($districts->first()->code)->toBe(330101);
expect($districts->first()->code)->toBe('330101');
expect($districts->first()->name)->toBe('KEDUNGREJA');
expect($districts->last()->code)->toBe(337604);
expect($districts->last()->code)->toBe('337604');
expect($districts->last()->name)->toBe('MARGADANA');

$villlages = Province::find(33)->villages;
expect($villlages)->toBeInstanceOf(Collection::class);
expect($villlages->count())->toBe(8562);
expect($villlages->first()->code)->toBe(3301012001);
expect($villlages->first()->code)->toBe('3301012001');
expect($villlages->first()->name)->toBe('TAMBAKREJA');
expect($villlages->last()->code)->toBe(3376041007);
expect($villlages->last()->code)->toBe('3376041007');
expect($villlages->last()->name)->toBe('PESURUNGAN LOR');
});

it('can get a city', function () {
expect(City::first())->not->toBeEmpty();

$city = City::find(3374);
expect($city->code)->toBe(3374);
expect($city->code)->toBe('3374');
expect($city->name)->toBe('KOTA SEMARANG');
expect($city->latitude)->toBe('-7.0051453');
expect($city->longitude)->toBe('110.4381254');
Expand All @@ -84,31 +84,31 @@
it('can get city model relations', function () {
$province = City::find(3374)->province;
expect($province)->toBeInstanceOf(Province::class);
expect($province->code)->toBe(33);
expect($province->code)->toBe('33');
expect($province->name)->toBe('JAWA TENGAH');

$districts = City::find(3374)->districts;
expect($districts)->toBeInstanceOf(Collection::class);
expect($districts->count())->toBe(16);
expect($districts->first()->code)->toBe(337401);
expect($districts->first()->code)->toBe('337401');
expect($districts->first()->name)->toBe('SEMARANG TENGAH');
expect($districts->last()->code)->toBe(337416);
expect($districts->last()->code)->toBe('337416');
expect($districts->last()->name)->toBe('TUGU');

$cities = City::find(3374)->villages;
expect($cities)->toBeInstanceOf(Collection::class);
expect($cities->count())->toBe(177);
expect($cities->first()->code)->toBe(3374011001);
expect($cities->first()->code)->toBe('3374011001');
expect($cities->first()->name)->toBe('MIROTO');
expect($cities->last()->code)->toBe(3374161007);
expect($cities->last()->code)->toBe('3374161007');
expect($cities->last()->name)->toBe('MANGUNHARJO');
});

it('can get a district', function () {
expect(District::first())->not->toBeEmpty();

$district = District::find(337401);
expect($district->code)->toBe(337401);
expect($district->code)->toBe('337401');
expect($district->name)->toBe('SEMARANG TENGAH');
expect($district->latitude)->toBe('-6.9805495');
expect($district->longitude)->toBe('110.4202505');
Expand All @@ -117,28 +117,28 @@
it('can get district model relations', function () {
$province = District::find(337401)->province;
expect($province)->toBeInstanceOf(Province::class);
expect($province->code)->toBe(33);
expect($province->code)->toBe('33');
expect($province->name)->toBe('JAWA TENGAH');

$city = District::find(337401)->city;
expect($city)->toBeInstanceOf(City::class);
expect($city->code)->toBe(3374);
expect($city->code)->toBe('3374');
expect($city->name)->toBe('KOTA SEMARANG');

$villlages = District::find(337401)->villages;
expect($villlages)->toBeInstanceOf(Collection::class);
expect($villlages->count())->toBe(15);
expect($villlages->first()->code)->toBe(3374011001);
expect($villlages->first()->code)->toBe('3374011001');
expect($villlages->first()->name)->toBe('MIROTO');
expect($villlages->last()->code)->toBe(3374011015);
expect($villlages->last()->code)->toBe('3374011015');
expect($villlages->last()->name)->toBe('PINDRIKAN LOR');
});

it('can get a village', function () {
expect(Village::first())->not->toBeEmpty();

$village = Village::find(3374011001);
expect($village->code)->toBe(3374011001);
expect($village->code)->toBe('3374011001');
expect($village->name)->toBe('MIROTO');
expect($village->latitude)->toBe('-6.9837576');
expect($village->longitude)->toBe('110.4195057');
Expand All @@ -147,51 +147,51 @@
it('can get village model relations', function () {
$province = Village::find(3374011001)->province;
expect($province)->toBeInstanceOf(Province::class);
expect($province->code)->toBe(33);
expect($province->code)->toBe('33');
expect($province->name)->toBe('JAWA TENGAH');

$city = Village::find(3374011001)->city;
expect($city)->toBeInstanceOf(City::class);
expect($city->code)->toBe(3374);
expect($city->code)->toBe('3374');
expect($city->name)->toBe('KOTA SEMARANG');

$district = Village::find(3374011001)->district;
expect($district)->toBeInstanceOf(District::class);
expect($district->code)->toBe(337401);
expect($district->code)->toBe('337401');
expect($district->name)->toBe('SEMARANG TENGAH');
});

it('can get new districts added in v2', function () {
$district = District::find(110115);
expect($district->code)->toBe(110115);
expect($district->code)->toBe('110115');
expect($district->name)->toBe('BAKONGAN TIMUR');
expect($district->latitude)->toBe('NULL');
expect($district->longitude)->toBe('NULL');

$district = District::find(911823);
expect($district->code)->toBe(911823);
expect($district->code)->toBe('911823');
expect($district->name)->toBe('KOROWAY BULUANOP');
expect($district->latitude)->toBe('NULL');
expect($district->longitude)->toBe('NULL');
});

it('can get new villages added in v2', function () {
$village = Village::find(1207212002);
expect($village->code)->toBe(1207212002);
expect($village->code)->toBe('1207212002');
expect($village->name)->toBe('PATUMBAK I');
expect($village->latitude)->toBe('NULL');
expect($village->longitude)->toBe('NULL');

$village = Village::find(9201502009);
expect($village->code)->toBe(9201502009);
expect($village->code)->toBe('9201502009');
expect($village->name)->toBe('MLARON');
expect($village->latitude)->toBe('NULL');
expect($village->longitude)->toBe('NULL');
});

it('can test new data for v2.0.2', function () {
$district = District::find(331710);
expect($district->code)->toBe(331710);
expect($district->code)->toBe('331710');
expect($district->name)->toBe('REMBANG');
expect($district->latitude)->toBe('-6.7147586');
expect($district->longitude)->toBe('111.3281411');
Expand Down