Skip to content

Commit

Permalink
Laravel 11 only
Browse files Browse the repository at this point in the history
  • Loading branch information
masterix21 committed Sep 23, 2024
1 parent bdc24d2 commit 614060a
Show file tree
Hide file tree
Showing 29 changed files with 272 additions and 593 deletions.
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":"pest_3.1.0","defects":{"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_return_empty_addresses_collection_when_eloquent_has_no_addresses":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_billing_address_primary_unmarked_event_on_make_primary":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_return_addresses_collection_when_eloquent_has_addresses":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_billing_address_primary_marked_event_on_make_primary":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_address_primary_unmarked_event_on_make_primary":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_shipping_address_primary_unmarked_event_on_make_primary":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_shipping_address_primary_marked_event_on_make_primary":8,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_address_primary_marked_event_on_make_primary":8},"times":{"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_return_addresses_collection_when_eloquent_has_addresses":0.006,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_address_primary_unmarked_event_on_make_primary":0.004,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_shipping_address_primary_unmarked_event_on_make_primary":0.004,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_address_primary_marked_event_on_make_primary":0.044,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_billing_address_primary_marked_event_on_make_primary":0.007,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_billing_address_primary_unmarked_event_on_make_primary":0.005,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_return_empty_addresses_collection_when_eloquent_has_no_addresses":0.019,"P\\Tests\\Feature\\Models\\AddressTest::__pest_evaluable_it_fires_shipping_address_primary_marked_event_on_make_primary":0.004,"P\\Tests\\ArchTest::__pest_evaluable_it_will_not_use_debugging_functions":0.045}}
42 changes: 33 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,19 @@
],
"require": {
"php": "^8.1|^8.2|^8.3",
"illuminate/support": "^10.0|^11.0",
"geo-io/wkb-parser": "^1.0",
"jmikola/geojson": "^1.1"
"illuminate/contracts": "^11.23"
},
"require-dev": {
"orchestra/testbench": "^6.23|^7.0|^8.0",
"phpunit/phpunit": "^10.0|^11.0"
"larastan/larastan": "^2.9",
"laravel/pint": "^1.17",
"orchestra/testbench": "^9.4",
"pestphp/pest": "^3.1",
"pestphp/pest-plugin-arch": "^3.0",
"pestphp/pest-plugin-drift": "3.x-dev",
"pestphp/pest-plugin-laravel": "^3.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-phpunit": "^1.4"
},
"autoload": {
"psr-4": {
Expand All @@ -32,15 +38,33 @@
},
"autoload-dev": {
"psr-4": {
"Masterix21\\Addressable\\Tests\\": "tests"
"Masterix21\\Addressable\\Tests\\": "tests",
"Masterix21\\Addressable\\Database\\Factories\\": "database/factories"
}
},
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
"post-autoload-dump": "@composer run prepare",
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": [
"@composer run prepare",
"@php vendor/bin/testbench workbench:build --ansi"
],
"start": [
"Composer\\Config::disableProcessTimeout",
"@composer run build",
"@php vendor/bin/testbench serve"
],
"analyse": "vendor/bin/phpstan analyse",
"test": "vendor/bin/pest",
"test-coverage": "vendor/bin/pest --coverage",
"format": "vendor/bin/pint"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"pestphp/pest-plugin": true,
"phpstan/extension-installer": true
}
},
"extra": {
"laravel": {
Expand Down
66 changes: 66 additions & 0 deletions database/factories/AddressFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Masterix21\Addressable\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Model;
use Masterix21\Addressable\Models\Address;

class AddressFactory extends Factory
{
protected $model = Address::class;

public function definition(): array
{
return [
'is_primary' => $this->faker->boolean,
'is_billing' => $this->faker->boolean,
'is_shipping' => $this->faker->boolean,
'label' => $this->faker->boolean ? $this->faker->streetName : null,
'street_address1' => $this->faker->streetAddress,
'street_address2' => $this->faker->streetAddress,
'zip' => $this->faker->postcode,
'city' => $this->faker->city,
'state' => $this->faker->state,
'country' => $this->faker->countryCode,
'coordinates' => [$this->faker->latitude, $this->faker->longitude],
];
}

public function addressable(Model $model): Factory
{
return $this->state(function (array $attributes) use ($model) {
return [
'addressable_type' => $model::class,
'addressable_id' => $model->getKey(),
];
});
}

public function primary(): Factory
{
return $this->state(function (array $attributes) {
return [
'is_primary' => true,
];
});
}

public function billing(): Factory
{
return $this->state(function (array $attributes) {
return [
'is_billing' => true,
];
});
}

public function shipping(): Factory
{
return $this->state(function (array $attributes) {
return [
'is_shipping' => true,
];
});
}
}
23 changes: 23 additions & 0 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Masterix21\Addressable\Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Masterix21\Addressable\Tests\TestClasses\User;

class UserFactory extends Factory
{
protected $model = User::class;

public function definition(): array
{
return [
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
}
23 changes: 6 additions & 17 deletions database/migrations/create_addressable_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Masterix21\Addressable\Concerns\UsesAddressableConfig;

class CreateAddressableTable extends Migration
return new class extends Migration
{
use UsesAddressableConfig;

/**
* Run the migrations.
*
* @return void
*/
public function up()
public function up(): void
{
Schema::create($this->addressesDatabaseTable(), function (Blueprint $table) {
$table->id();
Expand All @@ -29,21 +24,15 @@ class CreateAddressableTable extends Migration
$table->string('zip')->nullable();
$table->string('city')->nullable();
$table->string('state')->nullable();
$table->string('country')->nullable();
$table->string('country_code', 2)->nullable();
$table->point('position', config('addressable.srid'))->nullable();
$table->string('country', 4)->nullable();
$table->geography('coordinates', 'point')->nullable();

$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
public function down(): void
{
Schema::dropIfExists($this->addressesDatabaseTable());
}
}
};
Empty file added phpstan-baseline.neon
Empty file.
13 changes: 13 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- phpstan-baseline.neon

parameters:
level: 5
paths:
- src
- config
- database
tmpDir: build/phpstan
checkOctaneCompatibility: true
checkModelProperties: true

43 changes: 23 additions & 20 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<?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">
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
failOnWarning="true"
failOnRisky="true"
failOnEmptyTestSuite="true"
beStrictAboutOutputDuringTests="true"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
>
<testsuites>
<testsuite name="Masterix21 Test Suite">
<testsuite name="VendorName Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="junit" target="build/report.junit.xml"/>
<log type="coverage-html" target="build/coverage"/>
<log type="coverage-text" target="build/coverage.txt"/>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<junit outputFile="build/report.junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
10 changes: 5 additions & 5 deletions src/AddressableServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@

class AddressableServiceProvider extends ServiceProvider
{
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
__DIR__ . '/../config/addressable.php' => config_path('addressable.php'),
__DIR__.'/../config/addressable.php' => config_path('addressable.php'),
], 'config');

if (! class_exists('CreateAddressableTable')) {
$this->publishes([
__DIR__ . '/../database/migrations/create_addressable_table.php.stub' => database_path('migrations/' . date('Y_m_d_His', time()) . '_create_addressable_table.php'),
__DIR__.'/../database/migrations/create_addressable_table.php.stub' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_addressable_table.php'),
], 'migrations');
}
}

$this->loadViewsFrom(__DIR__.'/../resources/views', 'addressable');
}

public function register()
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/addressable.php', 'addressable');
$this->mergeConfigFrom(__DIR__.'/../config/addressable.php', 'addressable');
}
}
4 changes: 2 additions & 2 deletions src/Concerns/UsesAddressableConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

trait UsesAddressableConfig
{
public function addressModel() : string
public function addressModel(): string
{
return config('addressable.models.address');
}

public function addressesDatabaseTable() : string
public function addressesDatabaseTable(): string
{
return config('addressable.tables.addresses');
}
Expand Down
40 changes: 0 additions & 40 deletions src/Geo/Casts/PointCast.php

This file was deleted.

24 changes: 0 additions & 24 deletions src/Geo/Eloquent/Builder.php

This file was deleted.

Loading

0 comments on commit 614060a

Please sign in to comment.