Skip to content
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

chore(deps): bump submodules/cahyadsn-wilayah from 251e12c to c85fb78 #74

Merged
Merged
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: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ jobs:
if: ${{ matrix.db == 'pgsql' && ( github.actor != 'dependabot[bot]' || needs.configs.outputs.should-reports == '1' ) }}
env:
COVERAGE_FILE: tests/reports/clover.xml
CODECLIMATE_REPORT: tests/reports/codeclimate.${{ matrix.php }}.json
CODECLIMATE_REPORT: tests/reports/codeclimate.${{ matrix.php }}-L${{ matrix.laravel }}.json
run: |
if [[ -n \"$CC_TEST_REPORTER_URL\" ]]; then
curl -LSs $CC_TEST_REPORTER_URL > ./cc-test-reporter && chmod +x ./cc-test-reporter
Expand All @@ -175,7 +175,7 @@ jobs:
if: ${{ steps.reports.outputs.has-reports == '1' }}
with:
name: cc-reports-${{ matrix.php }}-L${{ matrix.laravel }}
path: tests/reports/codeclimate-${{ matrix.php }}-L${{ matrix.laravel }}.json
path: tests/reports/codeclimate.${{ matrix.php }}-L${{ matrix.laravel }}.json

reports:
name: Report Test Coverages
Expand Down
19 changes: 17 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
{
"name": "creasi/laravel-nusa",
"description": "A Laravel package that aim to provide Indonesia' Administrative Data",
"keywords": ["laravel", "package", "indonesia", "provinsi", "kabupaten", "kota", "kecamatan", "kelurahan", "desa"],
"keywords": [
"laravel",
"package",
"indonesia",
"provinsi",
"kabupaten",
"kota",
"kecamatan",
"kelurahan",
"desa"
],
"license": "MIT",
"type": "library",
"authors": [
Expand Down Expand Up @@ -34,6 +44,10 @@
],
"testbench": [
"testbench"
],
"tinker": [
"Composer\\Config::disableProcessTimeout",
"testbench tinker"
]
},
"autoload": {
Expand All @@ -45,7 +59,8 @@
"psr-4": {
"Creasi\\Scripts\\": "scripts",
"Creasi\\Tests\\": "tests",
"Database\\Seeders\\": "database/seeders/"
"Database\\Seeders\\": "database/seeders/",
"Workbench\\App\\": "workbench/app/"
}
},
"require": {
Expand Down
Binary file modified database/nusa.sqlite
Binary file not shown.
2 changes: 1 addition & 1 deletion resources/static/36/regencies.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
code,province_code,name,latitude,longitude
3601,36,"Kab. Pandeglang",-6.3168554305136,106.11479446982
3602,36,"Kab. Lebak",-6.3607670885178,106.24618699653
3603,36,"Kab. Tangerang",,
3603,36,"Kab. Tangerang",-6.2696304555658,106.48440474071
3604,36,"Kab. Serang",-6.1153025010456,106.15201508304
3671,36,"Kota Tangerang",-6.1643615549521,106.6410711382
3672,36,"Kota Cilegon",-6.009809018827,106.04212868304
Expand Down
4 changes: 2 additions & 2 deletions resources/static/36/regencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"code": 3603,
"province_code": 36,
"name": "Kab. Tangerang",
"latitude": null,
"longitude": null
"latitude": -6.269630455565761,
"longitude": 106.48440474071201
},
{
"code": 3604,
Expand Down
6 changes: 3 additions & 3 deletions resources/static/provinces.csv
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ code,name,latitude,longitude,coordinates
82,"Maluku Utara",0.75585814337694,127.60980236945
91,Papua,-2.5363008644385,140.71502399916
92,"Papua Barat",-0.91835080784201,134.03048752217
93,"Papua Selatan",-8.5086961546655,140.40967635179,
94,"Papua Tengah",-3.3633658641057,135.50389107767,
95,"Papua Pegunungan",-4.0993068017931,138.94314903716,
93,"Papua Selatan",-8.5086961546655,140.40967635179
94,"Papua Tengah",-3.3633658641057,135.50389107767
95,"Papua Pegunungan",-4.0993068017931,138.94314903716
9 changes: 3 additions & 6 deletions resources/static/provinces.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,18 @@
"code": 93,
"name": "Papua Selatan",
"latitude": -8.508696154665504,
"longitude": 140.40967635178788,
"coordinates": null
"longitude": 140.40967635178788
},
{
"code": 94,
"name": "Papua Tengah",
"latitude": -3.363365864105701,
"longitude": 135.50389107766932,
"coordinates": null
"longitude": 135.50389107766932
},
{
"code": 95,
"name": "Papua Pegunungan",
"latitude": -4.099306801793126,
"longitude": 138.94314903715775,
"coordinates": null
"longitude": 138.94314903715775
}
]
4 changes: 2 additions & 2 deletions scripts/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static function import($event): void
{
require_once $event->getComposer()->getConfig()->get('vendor-dir').'/autoload.php';

Dotenv::createImmutable(\dirname(__DIR__))->safeLoad();
Dotenv::createImmutable(\dirname(__DIR__).'/workbench')->safeLoad();

$db = new static(
name: env('DB_NUSA', 'nusantara'),
Expand Down Expand Up @@ -78,7 +78,7 @@ private function fetchAll(): array
SELECT
w.kode, w.nama,
p.kodepos,
l.lat, l.lng, l.elv, l.tz, l.luas, l.penduduk, l.path
l.lat, l.lng, l.elv, l.tz, l.luas, l.penduduk, l.paths path
FROM wilayah w
LEFT JOIN wilayah_level_1_2 l ON w.kode = l.kode
LEFT JOIN kodewilayah2023 p on w.kode = p.kodewilayah
Expand Down
4 changes: 3 additions & 1 deletion src/Models/Concerns/WithAddresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Creasi\Nusa\Models\Concerns;

use Illuminate\Database\Eloquent\Relations\MorphMany;

/**
* @mixin \Creasi\Nusa\Contracts\HasAddresses
*/
Expand All @@ -12,7 +14,7 @@ trait WithAddresses
/**
* @return \Illuminate\Database\Eloquent\Relations\MorphMany|\Creasi\Nusa\Contracts\Address
*/
public function addresses()
public function addresses(): MorphMany
{
return $this->morphMany(\config('creasi.nusa.addressable'), 'addressable');
}
Expand Down
2 changes: 1 addition & 1 deletion submodules/cahyadsn-wilayah
3 changes: 3 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
providers:
- Creasi\Nusa\ServiceProvider
- Workbench\App\Providers\WorkbenchServiceProvider
28 changes: 17 additions & 11 deletions tests/Models/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Creasi\Tests\Fixtures\HasOneAddress;
use Creasi\Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\Test;

Expand All @@ -21,40 +20,47 @@ class AddressTest extends TestCase
{
use WithFaker;

private function createAddress(array $attrs): Address
{
return $this->app->make(AddressContract::class)->create($attrs);
}

#[Test]
public function it_may_accociate_with_address(): AddressContract
public function it_may_accociate_with_address(): void
{
$village = Village::query()->inRandomOrder()->first();
$address = $this->app->make(AddressContract::class)->create([
$address = $this->createAddress([
'line' => $this->faker->streetAddress(),
]);

$address->associateWith($village);

$this->assertSame($village->province, $address->province);
$this->assertNull($address->addressable);

return $address->fresh();
}

#[Test]
#[Depends('it_may_accociate_with_address')]
public function may_has_many_addresses(Address $address): void
public function may_has_many_addresses(): void
{
/** @var HasManyAddresses */
$addressable = HasManyAddresses::create();

$addressable->addresses()->save($address);
$addressable->addresses()->save(
$this->createAddress(['line' => 'Coba Alamat'])
);

$this->assertCount(1, $addressable->addresses);
}

#[Test]
#[Depends('it_may_accociate_with_address')]
public function may_has_one_address(Address $address): void
public function may_has_one_address(): void
{
/** @var HasOneAddress */
$addressable = HasOneAddress::create();

$addressable->address()->save($address);
$addressable->address()->save(
$this->createAddress(['line' => 'Coba Alamat'])
);

$this->assertInstanceOf(AddressContract::class, $addressable->address);
}
Expand Down
46 changes: 3 additions & 43 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,22 @@

namespace Creasi\Tests;

use Creasi\Nusa\ServiceProvider;
use Database\Seeders\DatabaseSeeder;
use Illuminate\Config\Repository;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase as Orchestra;

class TestCase extends Orchestra
{
use DatabaseMigrations;
use WithWorkbench;

private static $shouldMigrate = true;

protected function getPackageProviders($app)
{
return [
ServiceProvider::class,
];
}

protected function defineDatabaseMigrations()
{
$nusa = \config('database.connections.nusa');
$nusa = \config('database.connections.nusa', []);

if (self::$shouldMigrate) {
$this->recreateDatabase($nusa['database']);
Expand All @@ -45,40 +39,6 @@ protected function defineDatabaseSeeders()
}
}

/**
* @param \Illuminate\Foundation\Application $app
*/
protected function getEnvironmentSetUp($app): void
{
tap($app->make('config'), function (Repository $config) {
$config->set('app.locale', 'id');
$config->set('app.faker_locale', 'id_ID');

// $conn = env('DB_CONNECTION', 'sqlite');

// $conn = $config->get('database.default');

// if ($conn === 'sqlite') {
// // $database = __DIR__.'/test.sqlite';

// // if (self::$shouldMigrate) {
// // $this->recreateDatabase($database);
// // }

// $this->mergeConfig($config, 'database.connections.sqlite', [
// 'database' => ':memory:',
// 'foreign_key_constraints' => true,
// ]);
// } else {
// $this->mergeConfig($config, 'database.connections.'.$conn, [
// 'database' => env('DB_DATABASE', 'creasi_test'),
// 'username' => env('DB_USERNAME', 'creasico'),
// 'password' => env('DB_PASSWORD', 'secret'),
// ]);
// }
});
}

private function recreateDatabase(string $path)
{
if (\file_exists($path)) {
Expand Down
File renamed without changes.
57 changes: 57 additions & 0 deletions workbench/app/Providers/WorkbenchServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Workbench\App\Providers;

use Illuminate\Config\Repository;
use Illuminate\Support\ServiceProvider;

use function Orchestra\Testbench\workbench_path;

class WorkbenchServiceProvider extends ServiceProvider
{
/**
* Register services.
*/
public function register(): void
{
//
}

/**
* Bootstrap services.
*/
public function boot(): void
{
$this->loadMigrationsFrom(
workbench_path('database/migrations')
);

tap(app()->make('config'), function (Repository $config) {
$config->set('app.locale', 'id');
$config->set('app.faker_locale', 'id_ID');

$conn = env('DB_CONNECTION', 'sqlite');

// $conn = $config->get('database.default');

// if ($conn === 'sqlite') {
// // $database = __DIR__.'/test.sqlite';

// // if (self::$shouldMigrate) {
// // $this->recreateDatabase($database);
// // }

// $this->mergeConfig($config, 'database.connections.sqlite', [
// 'database' => ':memory:',
// 'foreign_key_constraints' => true,
// ]);
// } else {
// $this->mergeConfig($config, 'database.connections.'.$conn, [
// 'database' => env('DB_DATABASE', 'creasi_test'),
// 'username' => env('DB_USERNAME', 'creasico'),
// 'password' => env('DB_PASSWORD', 'secret'),
// ]);
// }
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public function down(): void
{
Schema::dropIfExists('has_many_addresses');
Schema::dropIfExists('has_one_addresses');
Schema::dropIfExists('address');
Schema::dropIfExists('addresses');
}
};