Skip to content

Commit

Permalink
feat: upgrade installation package
Browse files Browse the repository at this point in the history
  • Loading branch information
craigAtCD committed Jul 19, 2022
1 parent 5f0f887 commit 6de72a1
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 69 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_has_provides_method":4,"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_is_a_service_provider":4},"times":{"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_has_provides_method":0.233,"CustomD\\Addressable\\Tests\\Feature\\ServiceProviderTest::it_is_a_service_provider":0.016}}
24 changes: 17 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@
],
"require": {
"php": "^8.0.0",
"illuminate/console": "^9.0.0 || ^10.0.0",
"illuminate/database": "^9.0.0 || ^10.0.0",
"illuminate/support": "^9.0.0 || ^10.0.0",
"illuminate/console": "^9.0.0",
"illuminate/database": "^9.0.0",
"illuminate/support": "^9.0.0",
"jackpopp/geodistance": "^1.2.0",
"rinvex/countries": "^8.0.0"
"rinvex/countries": "^8.0.0",
"spatie/laravel-package-tools": "^1.9.2"
},
"require-dev": {
"codedungeon/phpunit-result-printer": "^0.31.0",
"illuminate/container": "^9.0.0 || ^10.0.0",
"illuminate/container": "^9.0.0",
"nunomaduro/collision": "^6.0",
"nunomaduro/larastan": "^2.0.1",
"orchestra/testbench": "^7.0",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpunit/phpunit": "^9.5.0"
},
"autoload": {
Expand All @@ -59,12 +65,16 @@
}
},
"scripts": {
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/phpunit"
},
"config": {
"sort-packages": true,
"preferred-install": "dist",
"optimize-autoloader": true
"optimize-autoloader": true,
"allow-plugins": {
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAddressesTable extends Migration
return new class extends Migration
{
public function up()
{
Expand Down Expand Up @@ -35,4 +35,4 @@ public function down()
{
Schema::dropIfExists(config('addressable.tables.addresses'));
}
}
};
Empty file added phpstan-baseline.neon
Empty file.
15 changes: 11 additions & 4 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
includes:
- ./vendor/nunomaduro/larastan/extension.neon
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
level: 5
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
16 changes: 2 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="true"
beStrictAboutChangesToGlobalState="true"
beStrictAboutCoversAnnotation="true"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" executionOrder="random" failOnWarning="true" failOnRisky="true" failOnEmptyTestSuite="true" beStrictAboutOutputDuringTests="true" verbose="true">

<testsuites>
<testsuite name="Custom D Addresssable Unit Test Suite">
<directory suffix="Test.php">./tests/Unit</directory>
Expand Down
37 changes: 14 additions & 23 deletions src/AddressesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,27 @@
namespace CustomD\Addressable;

use CustomD\Addressable\Models\Address;
use Illuminate\Support\ServiceProvider;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;

class AddressesServiceProvider extends ServiceProvider
class AddressesServiceProvider extends PackageServiceProvider
{
/**
* {@inheritdoc}
*/
public function register()
public function configurePackage(Package $package): void
{
// Merge config
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'addressable');

$this->app->singleton('addressable.addresss', config('addressable.models.address'));

if(config('addressable.models.address') !== Address::class) {
$this->app->alias('addressable.models.address', Address::class);
}
$package
->name('addressable')
->hasConfigFile()
->hasMigration('create_addresses_table.php');
}

/**
* {@inheritdoc}
*/
public function boot()
public function packageRegistered()
{
$this->publishes([
__DIR__.'/../config/config.php' => config_path('addressable.php')
], 'config');

$this->publishes([
__DIR__.'/../database/migrations/' => database_path('migrations')
], 'migrations');
$this->app->singleton('addressable.addresss', config('addressable.models.address'));

if (config('addressable.models.address') !== Address::class) {
$this->app->alias('addressable.models.address', Address::class);
}
}
}
35 changes: 18 additions & 17 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ class Address extends Model
use SoftDeletes;
use GeoDistanceTrait;

protected $latColumn = 'latitude';

protected $lngColumn = 'longitude';

/**
* {@inheritdoc}
Expand All @@ -98,21 +95,21 @@ class Address extends Model
* {@inheritdoc}
*/
protected $casts = [
'addressable_id' => 'integer',
'addressable_id' => 'integer',
'addressable_type' => 'string',
'label' => 'string',
'given_name' => 'string',
'family_name' => 'string',
'organization' => 'string',
'country_code' => 'string',
'street' => 'string',
'state' => 'string',
'city' => 'string',
'postal_code' => 'string',
'latitude' => 'float',
'longitude' => 'float',
'is_primary' => 'boolean',
'deleted_at' => 'datetime',
'label' => 'string',
'given_name' => 'string',
'family_name' => 'string',
'organization' => 'string',
'country_code' => 'string',
'street' => 'string',
'state' => 'string',
'city' => 'string',
'postal_code' => 'string',
'latitude' => 'float',
'longitude' => 'float',
'is_primary' => 'boolean',
'deleted_at' => 'datetime',
];

/**
Expand All @@ -139,6 +136,10 @@ public function __construct(array $attributes = [])
{
$this->setTable(config('addressable.tables.addresses'));

$this->latColumn = 'latitude';

$this->lngColumn = 'longitude';

parent::__construct($attributes);
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/ServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
namespace CustomD\Addressable\Tests\Feature;

use ReflectionClass;
use PHPUnit\Framework\TestCase;
use Orchestra\Testbench\TestCase;
use Illuminate\Container\Container;
use Illuminate\Support\ServiceProvider;
use CustomD\Addressable\Providers\AddressesServiceProvider;
use CustomD\Addressable\AddressesServiceProvider;

class ServiceProviderTest extends TestCase
{
Expand Down

0 comments on commit 6de72a1

Please sign in to comment.