From a99b5c596ce75044d5e612ddeb542bffd9a8bb17 Mon Sep 17 00:00:00 2001 From: KimSpeer Date: Thu, 29 Aug 2024 10:45:45 +0200 Subject: [PATCH] fix some stan errors --- .phpunit.cache/test-results | 1 + packages/flags/composer.json | 29 ++++++++-- packages/flags/resources/svg/flag.svg | 3 ++ packages/flags/tests/CompilesIconsTest.php | 40 +++++++------- packages/flags/workbench/app/Models/.gitkeep | 0 packages/flags/workbench/app/Models/User.php | 44 +++++++++++++++ .../Providers/WorkbenchServiceProvider.php | 24 +++++++++ packages/flags/workbench/bootstrap/.gitkeep | 0 .../workbench/database/factories/.gitkeep | 0 .../database/factories/UserFactory.php | 54 +++++++++++++++++++ .../workbench/database/migrations/.gitkeep | 0 .../database/seeders/DatabaseSeeder.php | 23 ++++++++ .../flags/workbench/resources/views/.gitkeep | 0 packages/flags/workbench/routes/web.php | 7 +++ .../Resources/AreaResource/Pages/ListPage.php | 4 +- packages/press/src/Models/WpBasePost.php | 28 +++++----- packages/press/src/Models/WpMedia.php | 8 +-- packages/press/src/Models/WpUser.php | 7 ++- packages/sync/src/Models/Platform.php | 5 +- packages/sync/src/Models/Sync.php | 9 ++-- 20 files changed, 226 insertions(+), 60 deletions(-) create mode 100644 .phpunit.cache/test-results create mode 100644 packages/flags/resources/svg/flag.svg create mode 100644 packages/flags/workbench/app/Models/.gitkeep create mode 100644 packages/flags/workbench/app/Models/User.php create mode 100644 packages/flags/workbench/app/Providers/WorkbenchServiceProvider.php create mode 100644 packages/flags/workbench/bootstrap/.gitkeep create mode 100644 packages/flags/workbench/database/factories/.gitkeep create mode 100644 packages/flags/workbench/database/factories/UserFactory.php create mode 100644 packages/flags/workbench/database/migrations/.gitkeep create mode 100644 packages/flags/workbench/database/seeders/DatabaseSeeder.php create mode 100644 packages/flags/workbench/resources/views/.gitkeep create mode 100644 packages/flags/workbench/routes/web.php diff --git a/.phpunit.cache/test-results b/.phpunit.cache/test-results new file mode 100644 index 000000000..90d211022 --- /dev/null +++ b/.phpunit.cache/test-results @@ -0,0 +1 @@ +{"version":"pest_2.35.1","defects":[],"times":{"Tests\\Unit\\ExampleTest::testThatTrueIsTrue":0.028,"P\\Packages\\core\\tests\\Unit\\ExampleTest::__pest_evaluable_core_example_unit":0.089,"Tests\\Feature\\LandingPageTest::testHealthyResponse":0.169,"Tests\\Feature\\LandingPageTest::testContainsWelcome":0.008,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_healthy_response":0.008,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_it_redirects_to_login":1.046,"P\\Tests\\Feature\\MooxLoginTest::__pest_evaluable_it_contains_Sign_in":1.141,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_healthy_response":1.077,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_it_redirects_to_login":1.04,"P\\Tests\\Feature\\PressLoginTest::__pest_evaluable_it_contains_Sign_in":1.165,"P\\Packages\\core\\tests\\Feature\\ExampleTest::__pest_evaluable_core_example_feature":0}} \ No newline at end of file diff --git a/packages/flags/composer.json b/packages/flags/composer.json index c4bd0e51a..aee1c8482 100644 --- a/packages/flags/composer.json +++ b/packages/flags/composer.json @@ -33,7 +33,10 @@ }, "autoload-dev": { "psr-4": { - "Tests\\": "tests" + "Tests\\": "tests", + "Workbench\\App\\": "workbench/app/", + "Workbench\\Database\\Factories\\": "workbench/database/factories/", + "Workbench\\Database\\Seeders\\": "workbench/database/seeders/" } }, "extra": { @@ -47,5 +50,25 @@ "sort-packages": true }, "minimum-stability": "dev", - "prefer-stable": true -} + "prefer-stable": true, + "scripts": { + "post-autoload-dump": [ + "@clear", + "@prepare" + ], + "clear": "@php vendor/bin/testbench package:purge-skeleton --ansi", + "prepare": "@php vendor/bin/testbench package:discover --ansi", + "build": "@php vendor/bin/testbench workbench:build --ansi", + "serve": [ + "Composer\\Config::disableProcessTimeout", + "@build", + "@php vendor/bin/testbench serve --ansi" + ], + "lint": [ + "@php vendor/bin/phpstan analyse --verbose --ansi" + ], + "test": [ + "@php vendor/bin/phpunit" + ] + } +} \ No newline at end of file diff --git a/packages/flags/resources/svg/flag.svg b/packages/flags/resources/svg/flag.svg new file mode 100644 index 000000000..b3f1f9225 --- /dev/null +++ b/packages/flags/resources/svg/flag.svg @@ -0,0 +1,3 @@ + + + diff --git a/packages/flags/tests/CompilesIconsTest.php b/packages/flags/tests/CompilesIconsTest.php index 637a5555c..e198fc416 100644 --- a/packages/flags/tests/CompilesIconsTest.php +++ b/packages/flags/tests/CompilesIconsTest.php @@ -4,61 +4,57 @@ namespace Tests; -use BladeUI\Heroicons\BladeHeroiconsServiceProvider; +use Moox\Flags\FlagsServiceProvider; use BladeUI\Icons\BladeIconsServiceProvider; -use Orchestra\Testbench\TestCase; // TODO: Care for Testbench -class CompilesIconsTest extends TestCase +class CompilesIconsTest extends \Orchestra\Testbench\TestCase { /** @test */ public function it_compiles_a_single_anonymous_component() { - $result = svg('heroicon-o-bell')->toHtml(); + $result = svg('flag')->toHtml(); // Note: the empty class here seems to be a Blade components bug. - $expected = <<<'SVG' - + $expected = + ' - - SVG; + '; - $this->assertSame($expected, $result); + $this->assertEquals($expected, $result); } /** @test */ public function it_can_add_classes_to_icons() { - $result = svg('heroicon-o-bell', 'w-6 h-6 text-gray-500')->toHtml(); + $result = svg('flag', 'w-6 h-6 text-gray-500')->toHtml(); - $expected = <<<'SVG' - + $expected = + ' - - SVG; + '; - $this->assertSame($expected, $result); + $this->assertEquals($expected, $result); } /** @test */ public function it_can_add_styles_to_icons() { - $result = svg('heroicon-o-bell', ['style' => 'color: #555'])->toHtml(); + $result = svg('flag', ['style' => 'color: #555'])->toHtml(); - $expected = <<<'SVG' - + $expected = + ' - - SVG; + '; - $this->assertSame($expected, $result); + $this->assertEquals($expected, $result); } protected function getPackageProviders($app) { return [ + FlagsServiceProvider::class, BladeIconsServiceProvider::class, - BladeHeroiconsServiceProvider::class, ]; } } diff --git a/packages/flags/workbench/app/Models/.gitkeep b/packages/flags/workbench/app/Models/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/flags/workbench/app/Models/User.php b/packages/flags/workbench/app/Models/User.php new file mode 100644 index 000000000..accfba6f7 --- /dev/null +++ b/packages/flags/workbench/app/Models/User.php @@ -0,0 +1,44 @@ + + */ + protected $fillable = [ + 'name', + 'email', + 'password', + ]; + + /** + * The attributes that should be hidden for serialization. + * + * @var array + */ + protected $hidden = [ + 'password', + 'remember_token', + ]; + + /** + * The attributes that should be cast. + * + * @var array + */ + protected $casts = [ + 'email_verified_at' => 'datetime', + 'password' => 'hashed', + ]; +} diff --git a/packages/flags/workbench/app/Providers/WorkbenchServiceProvider.php b/packages/flags/workbench/app/Providers/WorkbenchServiceProvider.php new file mode 100644 index 000000000..e8cec9c2a --- /dev/null +++ b/packages/flags/workbench/app/Providers/WorkbenchServiceProvider.php @@ -0,0 +1,24 @@ + + */ +class UserFactory extends Factory +{ + /** + * The current password being used by the factory. + */ + protected static ?string $password; + + /** + * The name of the factory's corresponding model. + * + * @var class-string + */ + protected $model = User::class; + + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->name(), + 'email' => fake()->unique()->safeEmail(), + 'email_verified_at' => now(), + 'password' => static::$password ??= Hash::make('password'), + 'remember_token' => Str::random(10), + ]; + } + + /** + * Indicate that the model's email address should be unverified. + */ + public function unverified(): static + { + return $this->state(fn (array $attributes) => [ + 'email_verified_at' => null, + ]); + } +} diff --git a/packages/flags/workbench/database/migrations/.gitkeep b/packages/flags/workbench/database/migrations/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/flags/workbench/database/seeders/DatabaseSeeder.php b/packages/flags/workbench/database/seeders/DatabaseSeeder.php new file mode 100644 index 000000000..ce9bd1597 --- /dev/null +++ b/packages/flags/workbench/database/seeders/DatabaseSeeder.php @@ -0,0 +1,23 @@ +create(); + + UserFactory::new()->create([ + 'name' => 'Test User', + 'email' => 'test@example.com', + ]); + } +} diff --git a/packages/flags/workbench/resources/views/.gitkeep b/packages/flags/workbench/resources/views/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/packages/flags/workbench/routes/web.php b/packages/flags/workbench/routes/web.php new file mode 100644 index 000000000..86a06c53e --- /dev/null +++ b/packages/flags/workbench/routes/web.php @@ -0,0 +1,7 @@ +using(function (array $data, string $model): Area { + ->using(function (array $data, string $model): static { return $model::create($data); }), ]; diff --git a/packages/press/src/Models/WpBasePost.php b/packages/press/src/Models/WpBasePost.php index 1e9d28378..7f2db90c3 100644 --- a/packages/press/src/Models/WpBasePost.php +++ b/packages/press/src/Models/WpBasePost.php @@ -5,6 +5,9 @@ use Awobaz\Mutator\Mutable; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Str; /** @@ -12,7 +15,6 @@ * @property string $post_title * @property string $post_name * @property string $post_author - * @property WpPostMeta $postMeta */ class WpBasePost extends Model { @@ -64,8 +66,8 @@ public function __construct(array $attributes = []) parent::__construct($attributes); $this->wpPrefix = config('press.wordpress_prefix'); - $this->table = $this->wpPrefix.'posts'; - $this->metatable = $this->wpPrefix.'postmeta'; + $this->table = $this->wpPrefix . 'posts'; + $this->metatable = $this->wpPrefix . 'postmeta'; $this->appends = [ 'verantwortlicher', @@ -178,41 +180,35 @@ protected function isMetaField($key) * Relations * */ - public function postMeta() + public function postMeta(): HasMany { return $this->hasMany(WpPostMeta::class, 'post_id', 'ID'); } - public function author() + public function author(): BelongsTo { return $this->belongsTo(WpUser::class, 'post_author', 'ID'); } - public function taxonomies() + public function taxonomies(): BelongsToMany { - return $this->belongsToMany(WpTermTaxonomy::class, config('press.wordpress_prefix').'term_relationships', 'object_id', 'term_taxonomy_id'); + return $this->belongsToMany(WpTermTaxonomy::class, config('press.wordpress_prefix') . 'term_relationships', 'object_id', 'term_taxonomy_id'); } - public function categories() + public function categories(): BelongsToMany { return $this->taxonomies()->where('taxonomy', 'category'); } - public function tags() + public function tags(): BelongsToMany { return $this->taxonomies()->where('taxonomy', 'post_tag'); } - public function comment() + public function comment(): HasMany { return $this->hasMany(WpComment::class, 'comment_post_ID'); } - - public function meta() - { - return $this->hasMany(WpPostMeta::class, 'post_id', 'ID'); - } - /* * ACF- Fields Getter and Setter */ diff --git a/packages/press/src/Models/WpMedia.php b/packages/press/src/Models/WpMedia.php index 8789499cf..4d55c93c4 100644 --- a/packages/press/src/Models/WpMedia.php +++ b/packages/press/src/Models/WpMedia.php @@ -19,7 +19,7 @@ public function __construct(array $attributes = []) { parent::__construct($attributes); $this->wpPrefix = config('press.wordpress_prefix'); - $this->table = $this->wpPrefix.'posts'; + $this->table = $this->wpPrefix . 'posts'; } public static function boot() @@ -31,10 +31,6 @@ public static function boot() }); } - public function postMeta() - { - return $this->hasMany(WpPostMeta::class, 'post_id', 'ID'); - } public function getImageUrlAttribute() { @@ -51,7 +47,7 @@ public function getAssetAttribute() // TODO: Check if the file is an image // TODO: Read wp-config.php to get the upload path - return $file ? asset($wpslug.'/wp-content/uploads/'.$file) : ''; + return $file ? asset($wpslug . '/wp-content/uploads/' . $file) : ''; } public function getImageSizesAttribute() diff --git a/packages/press/src/Models/WpUser.php b/packages/press/src/Models/WpUser.php index c9d3b3389..953a65fa6 100644 --- a/packages/press/src/Models/WpUser.php +++ b/packages/press/src/Models/WpUser.php @@ -13,6 +13,9 @@ use Moox\Press\QueryBuilder\UserQueryBuilder; use Spatie\Permission\Traits\HasRoles; +/** + * @property string $user_email + */ class WpUser extends Authenticatable implements FilamentUser { use HasFactory, HasRoles, Mutable, Notifiable; @@ -56,8 +59,8 @@ public function __construct(array $attributes = []) $this->fillable = array_keys($defaultUserMeta); $this->wpPrefix = config('press.wordpress_prefix'); - $this->table = $this->wpPrefix.'users'; - $this->metatable = $this->wpPrefix.'usermeta'; + $this->table = $this->wpPrefix . 'users'; + $this->metatable = $this->wpPrefix . 'usermeta'; $this->initializeMetaFields(); } diff --git a/packages/sync/src/Models/Platform.php b/packages/sync/src/Models/Platform.php index baff5d039..d4e3fb780 100644 --- a/packages/sync/src/Models/Platform.php +++ b/packages/sync/src/Models/Platform.php @@ -3,6 +3,7 @@ namespace Moox\Sync\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; class Platform extends Model { @@ -39,12 +40,12 @@ class Platform extends Model 'master' => 'boolean', ]; - public function sourcePlatform() + public function sourcePlatform(): HasMany { return $this->hasMany(Sync::class, 'source_platform_id'); } - public function targetPlatform() + public function targetPlatform(): HasMany { return $this->hasMany(Sync::class, 'target_platform_id'); } diff --git a/packages/sync/src/Models/Sync.php b/packages/sync/src/Models/Sync.php index 5df1176e5..671747091 100644 --- a/packages/sync/src/Models/Sync.php +++ b/packages/sync/src/Models/Sync.php @@ -3,11 +3,8 @@ namespace Moox\Sync\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; -/** - * @property \Moox\Sync\Models\Platform $sourcePlatform - * @property \Moox\Sync\Models\Platform $targetPlatform - */ class Sync extends Model { /** @@ -54,12 +51,12 @@ class Sync extends Model 'interval' => 'integer', ]; - public function sourcePlatform() + public function sourcePlatform(): BelongsTo { return $this->belongsTo(Platform::class, 'source_platform_id'); } - public function targetPlatform() + public function targetPlatform(): BelongsTo { return $this->belongsTo(Platform::class, 'target_platform_id'); }