diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5f848e4..8035e05 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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 @@ -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 diff --git a/composer.json b/composer.json index 62c9510..1fe47a7 100644 --- a/composer.json +++ b/composer.json @@ -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": [ @@ -34,6 +44,10 @@ ], "testbench": [ "testbench" + ], + "tinker": [ + "Composer\\Config::disableProcessTimeout", + "testbench tinker" ] }, "autoload": { @@ -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": { diff --git a/database/nusa.sqlite b/database/nusa.sqlite index 1fda9e8..19bb227 100644 Binary files a/database/nusa.sqlite and b/database/nusa.sqlite differ diff --git a/resources/static/36/regencies.csv b/resources/static/36/regencies.csv index 2549cd1..cb0e0c7 100644 --- a/resources/static/36/regencies.csv +++ b/resources/static/36/regencies.csv @@ -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 diff --git a/resources/static/36/regencies.json b/resources/static/36/regencies.json index 695b0b9..ac0979f 100644 --- a/resources/static/36/regencies.json +++ b/resources/static/36/regencies.json @@ -17,8 +17,8 @@ "code": 3603, "province_code": 36, "name": "Kab. Tangerang", - "latitude": null, - "longitude": null + "latitude": -6.269630455565761, + "longitude": 106.48440474071201 }, { "code": 3604, diff --git a/resources/static/provinces.csv b/resources/static/provinces.csv index eee770d..d657235 100644 --- a/resources/static/provinces.csv +++ b/resources/static/provinces.csv @@ -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 diff --git a/resources/static/provinces.json b/resources/static/provinces.json index 0be9644..1d2c36c 100644 --- a/resources/static/provinces.json +++ b/resources/static/provinces.json @@ -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 } ] \ No newline at end of file diff --git a/scripts/Database.php b/scripts/Database.php index ec1257e..b5529d9 100644 --- a/scripts/Database.php +++ b/scripts/Database.php @@ -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'), @@ -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 diff --git a/src/Models/Concerns/WithAddresses.php b/src/Models/Concerns/WithAddresses.php index 03e8559..a0cf2a9 100644 --- a/src/Models/Concerns/WithAddresses.php +++ b/src/Models/Concerns/WithAddresses.php @@ -4,6 +4,8 @@ namespace Creasi\Nusa\Models\Concerns; +use Illuminate\Database\Eloquent\Relations\MorphMany; + /** * @mixin \Creasi\Nusa\Contracts\HasAddresses */ @@ -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'); } diff --git a/submodules/cahyadsn-wilayah b/submodules/cahyadsn-wilayah index 251e12c..c85fb78 160000 --- a/submodules/cahyadsn-wilayah +++ b/submodules/cahyadsn-wilayah @@ -1 +1 @@ -Subproject commit 251e12c0dc1689f84a03ad302da791217cc12be4 +Subproject commit c85fb78f1dbf501a0316e2fc340bed45b0c562e2 diff --git a/testbench.yaml b/testbench.yaml new file mode 100644 index 0000000..65b7cd4 --- /dev/null +++ b/testbench.yaml @@ -0,0 +1,3 @@ +providers: + - Creasi\Nusa\ServiceProvider + - Workbench\App\Providers\WorkbenchServiceProvider diff --git a/tests/Models/AddressTest.php b/tests/Models/AddressTest.php index 66b9e9f..247ac47 100644 --- a/tests/Models/AddressTest.php +++ b/tests/Models/AddressTest.php @@ -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; @@ -21,11 +20,16 @@ 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(), ]); @@ -33,28 +37,30 @@ public function it_may_accociate_with_address(): AddressContract $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); } diff --git a/tests/TestCase.php b/tests/TestCase.php index 3f82054..ee5d283 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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']); @@ -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)) { diff --git a/.env.example b/workbench/.env.example similarity index 100% rename from .env.example rename to workbench/.env.example diff --git a/workbench/app/Providers/WorkbenchServiceProvider.php b/workbench/app/Providers/WorkbenchServiceProvider.php new file mode 100644 index 0000000..3b7a4aa --- /dev/null +++ b/workbench/app/Providers/WorkbenchServiceProvider.php @@ -0,0 +1,57 @@ +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'), + // ]); + // } + }); + } +} diff --git a/database/migrations/0000_00_00_000001_create_testing_tables.php b/workbench/database/migrations/0000_00_00_000001_create_testing_tables.php similarity index 96% rename from database/migrations/0000_00_00_000001_create_testing_tables.php rename to workbench/database/migrations/0000_00_00_000001_create_testing_tables.php index a1c02e6..03487a7 100644 --- a/database/migrations/0000_00_00_000001_create_testing_tables.php +++ b/workbench/database/migrations/0000_00_00_000001_create_testing_tables.php @@ -40,6 +40,6 @@ public function down(): void { Schema::dropIfExists('has_many_addresses'); Schema::dropIfExists('has_one_addresses'); - Schema::dropIfExists('address'); + Schema::dropIfExists('addresses'); } };