Compare commits

..
Author SHA1 Message Date
Barry vd. Heuvel d1d9d8eb45 Update CHANGELOG.md 2024-02-05 09:15:40 +01:00
35 changed files with 267 additions and 341 deletions
+14 -2
View File
@@ -19,13 +19,25 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php: [8.3, 8.2, 8.1, 8.0] php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3]
laravel: [10.*, 9.*] laravel: [10.*, 9.*, 8.*]
exclude: exclude:
- php: 8.0 - php: 8.0
laravel: 10.* laravel: 10.*
- php: 7.4
laravel: 10.*
- php: 7.3
laravel: 10.*
- php: 8.3 - php: 8.3
laravel: 9.* laravel: 9.*
- php: 7.4
laravel: 9.*
- php: 7.3
laravel: 9.*
- php: 8.3
laravel: 8.*
- php: 8.2
laravel: 8.*
name: P${{ matrix.php }} - Laravel${{ matrix.laravel }} name: P${{ matrix.php }} - Laravel${{ matrix.laravel }}
steps: steps:
- name: Checkout code - name: Checkout code
+1 -1
View File
@@ -17,7 +17,7 @@ jobs:
- name: Setup PHP - name: Setup PHP
uses: shivammathur/setup-php@v2 uses: shivammathur/setup-php@v2
with: with:
php-version: 8.1 php-version: 8.0
coverage: none coverage: none
extensions: pdo_sqlite extensions: pdo_sqlite
+17 -6
View File
@@ -18,17 +18,28 @@ jobs:
COMPOSER_NO_INTERACTION: 1 COMPOSER_NO_INTERACTION: 1
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [ubuntu-20.04, windows-2019] os: [ubuntu-20.04, windows-2019]
php: [8.3, 8.2, 8.1, 8.0] php: [8.3, 8.2, 8.1, 8.0, 7.4, 7.3]
laravel: [9.*, 10.*] laravel: [8.*, 9.*, 10.*]
stability: [prefer-lowest, prefer-stable] dependency-version: [prefer-lowest, prefer-stable]
exclude: exclude:
- php: 8.0 - php: 8.0
laravel: 10.* laravel: 10.*
- php: 7.4
laravel: 10.*
- php: 7.3
laravel: 10.*
- php: 8.0 - php: 8.0
stability: prefer-lowest dependency-version: prefer-lowest
- php: 7.4
laravel: 9.*
- php: 7.3
laravel: 9.*
- os: windows-2019
php: 7.4
- os: windows-2019
php: 7.3
steps: steps:
- name: Set git to use LF - name: Set git to use LF
if: ${{ matrix.os == 'windows-2019' }} if: ${{ matrix.os == 'windows-2019' }}
@@ -51,7 +62,7 @@ jobs:
composer remove vimeo/psalm --no-update --dev composer remove vimeo/psalm --no-update --dev
composer remove friendsofphp/php-cs-fixer --no-update --dev composer remove friendsofphp/php-cs-fixer --no-update --dev
composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress composer require "laravel/framework:${{ matrix.laravel }}" --no-update --no-progress
composer update --prefer-dist --no-progress --${{ matrix.stability }} composer update --prefer-dist --no-progress
- name: Execute Unit Tests - name: Execute Unit Tests
run: composer test-ci run: composer test-ci
+3 -3
View File
@@ -1,8 +1,8 @@
.phpunit.result.cache .phpunit.result.cache
/.idea /.idea
/.php-cs-fixer.cache /.php_cs
/.php-cs-fixer.php /.php_cs.cache
/.php-cs-fixer.tests.cache /.php_cs.tests.cache
/composer.lock /composer.lock
/vendor /vendor
@@ -30,6 +30,7 @@ return [
], ],
'return_type_declaration' => true, 'return_type_declaration' => true,
'short_scalar_cast' => true, 'short_scalar_cast' => true,
'single_blank_line_before_namespace' => true,
'single_trait_insert_per_statement' => true, 'single_trait_insert_per_statement' => true,
'ternary_operator_spaces' => true, 'ternary_operator_spaces' => true,
'visibility_required' => [ 'visibility_required' => [
@@ -55,7 +56,7 @@ return [
'no_unused_imports' => true, 'no_unused_imports' => true,
'single_quote' => true, 'single_quote' => true,
'space_after_semicolon' => true, 'space_after_semicolon' => true,
'trailing_comma_in_multiline' => true, 'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true, 'trim_array_spaces' => true,
'unary_operator_spaces' => true, 'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true, 'whitespace_after_comma_in_array' => true,
+3 -3
View File
@@ -5,10 +5,10 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__) ->in(__DIR__)
->exclude('tests'); ->exclude('tests');
$config = require __DIR__ . '/.php-cs-fixer.common.php'; $config = require __DIR__ . '/.php_cs.common.php';
return (new PhpCsFixer\Config()) return PhpCsFixer\Config::create()
->setFinder($finder) ->setFinder($finder)
->setRules($config) ->setRules($config)
->setRiskyAllowed(true) ->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php-cs-fixer.cache'); ->setCacheFile(__DIR__ . '/.php_cs.cache');
@@ -5,7 +5,7 @@ $finder = PhpCsFixer\Finder::create()
->in(__DIR__ . '/tests') ->in(__DIR__ . '/tests')
->exclude('__snapshots__'); ->exclude('__snapshots__');
$config = require __DIR__ . '/.php-cs-fixer.common.php'; $config = require __DIR__ . '/.php_cs.common.php';
// Additional rules for tests // Additional rules for tests
$config = array_merge( $config = array_merge(
@@ -15,8 +15,8 @@ $config = array_merge(
] ]
); );
return (new PhpCsFixer\Config()) return PhpCsFixer\Config::create()
->setFinder($finder) ->setFinder($finder)
->setRules($config) ->setRules($config)
->setRiskyAllowed(true) ->setRiskyAllowed(true)
->setCacheFile(__DIR__ . '/.php-cs-fixer.tests.cache'); ->setCacheFile(__DIR__ . '/.php_cs.tests.cache');
-7
View File
@@ -5,13 +5,6 @@ All notable changes to this project will be documented in this file.
[Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.14.0...master) [Next release](https://github.com/barryvdh/laravel-ide-helper/compare/v2.14.0...master)
-------------- --------------
### Changed
- Removed support for Laravel 8 and therefore for PHP < 8.0 [#1504 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1504)
### Added
- Add support for enum default arguments using enum cases. [#1464 / d8vjork](https://github.com/barryvdh/laravel-ide-helper/pull/1464)
2024-02-05, 2.14.0 2024-02-05, 2.14.0
------------------ ------------------
+4 -4
View File
@@ -11,7 +11,7 @@
This package generates helper files that enable your IDE to provide accurate autocompletion. This package generates helper files that enable your IDE to provide accurate autocompletion.
Generation is done based on the files in your project, so they are always up-to-date. Generation is done based on the files in your project, so they are always up-to-date.
It supports Laravel 9+ and PHP 8.0+ It supports Laravel 8+ and PHP 7.3+
- [Installation](#installation) - [Installation](#installation)
- [Usage](#usage) - [Usage](#usage)
@@ -145,9 +145,9 @@ The class name will be different from the model, avoiding the IDE duplicate anno
> Please make sure to back up your models, before writing the info. > Please make sure to back up your models, before writing the info.
Writing to the models should keep the existing comments and only append new properties/methods. It will not update changed properties/methods. Writing to the models should keep the existing comments and only append new properties/methods.
The existing PHPDoc is replaced, or added if not found.
With the `--reset (-R)` option, the whole existing PHPDoc is replaced, including any comments that have been made. The `--smart-reset` option will instead keep the 'text' part of the phpdoc comment, and just replace all the property/method defininitions. With the `--reset (-R)` option, the existing PHPDocs are ignored, and only the newly found columns/relations are saved as PHPDocs.
```bash ```bash
php artisan ide-helper:models "App\Models\Post" php artisan ide-helper:models "App\Models\Post"
+13 -14
View File
@@ -20,27 +20,26 @@
} }
], ],
"require": { "require": {
"php": "^8.0", "php": "^7.3 || ^8.0",
"ext-json": "*", "ext-json": "*",
"barryvdh/reflection-docblock": "^2.1.1", "barryvdh/reflection-docblock": "^2.0.6",
"composer/class-map-generator": "^1.0", "composer/class-map-generator": "^1.0",
"doctrine/dbal": "^3.1.4", "doctrine/dbal": "^2.6 || ^3",
"illuminate/console": "^9 || ^10", "illuminate/console": "^8 || ^9 || ^10",
"illuminate/filesystem": "^9 || ^10", "illuminate/filesystem": "^8 || ^9 || ^10",
"illuminate/support": "^9 || ^10", "illuminate/support": "^8 || ^9 || ^10",
"nikic/php-parser": "^4.18 || ^5", "nikic/php-parser": "^4.18 || ^5",
"phpdocumentor/type-resolver": "^1.1.0" "phpdocumentor/type-resolver": "^1.1.0"
}, },
"require-dev": { "require-dev": {
"ext-pdo_sqlite": "*", "ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "^3", "friendsofphp/php-cs-fixer": "^2",
"illuminate/config": "^9 || ^10", "illuminate/config": "^8 || ^9 || ^10",
"illuminate/view": "^9 || ^10", "illuminate/view": "^8 || ^9 || ^10",
"mockery/mockery": "^1.4", "mockery/mockery": "^1.4",
"nesbot/carbon": "^2.62.1", "orchestra/testbench": "^6 || ^7 || ^8",
"orchestra/testbench": "^7 || ^8", "phpunit/phpunit": "^8.5 || ^9",
"phpunit/phpunit": "^9", "spatie/phpunit-snapshot-assertions": "^3 || ^4",
"spatie/phpunit-snapshot-assertions": "^4",
"vimeo/psalm": "^5.4" "vimeo/psalm": "^5.4"
}, },
"suggest": { "suggest": {
@@ -82,7 +81,7 @@
], ],
"fix-style": [ "fix-style": [
"php-cs-fixer fix", "php-cs-fixer fix",
"php-cs-fixer fix --config=.php-cs-fixer.tests.php" "php-cs-fixer fix --config=.php_cs.tests.php"
], ],
"psalm-set-baseline": "psalm --set-baseline=psalm-baseline.xml", "psalm-set-baseline": "psalm --set-baseline=psalm-baseline.xml",
"test": "phpunit", "test": "phpunit",
-5
View File
@@ -16,9 +16,4 @@
<code>\Storage</code> <code>\Storage</code>
</UndefinedClass> </UndefinedClass>
</file> </file>
<file src="src/Console/ModelsCommand.php">
<UndefinedClass occurrences="1">
<code>\UnitEnum</code>
</UndefinedClass>
</file>
</files> </files>
+3 -1
View File
@@ -8,7 +8,6 @@
*/ */
?> ?>
/* @noinspection ALL */
// @formatter:off // @formatter:off
// phpcs:ignoreFile // phpcs:ignoreFile
@@ -23,6 +22,9 @@
*/ */
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?> <?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
<?php if ($namespace == '\Illuminate\Database\Eloquent') :
continue;
endif; ?>
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> { namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
<?php foreach ($aliases as $alias) : ?> <?php foreach ($aliases as $alias) : ?>
<?= trim($alias->getDocComment(' ')) ?> <?= trim($alias->getDocComment(' ')) ?>
-2
View File
@@ -1,8 +1,6 @@
<?= '<?php' ?> <?= '<?php' ?>
/* @noinspection ALL */
// @formatter:off // @formatter:off
// phpcs:ignoreFile
namespace PHPSTORM_META { namespace PHPSTORM_META {
+2 -2
View File
@@ -329,7 +329,7 @@ class Alias
continue; continue;
} }
$method = new \ReflectionMethod($className, $name); $method = new \ReflectionMethod($className, $name);
$class = new ReflectionClass($className); $class = new \ReflectionClass($className);
if (!in_array($magic, $this->usedMethods)) { if (!in_array($magic, $this->usedMethods)) {
if ($class !== $this->root) { if ($class !== $this->root) {
@@ -348,7 +348,7 @@ class Alias
protected function detectMethods() protected function detectMethods()
{ {
foreach ($this->classes as $class) { foreach ($this->classes as $class) {
$reflection = new ReflectionClass($class); $reflection = new \ReflectionClass($class);
$methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC); $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
if ($methods) { if ($methods) {
+2 -2
View File
@@ -42,7 +42,7 @@ class GeneratorCommand extends Command
/** @var \Illuminate\Config\Repository */ /** @var \Illuminate\Config\Repository */
protected $config; protected $config;
/** @var Filesystem */ /** @var \Illuminate\Filesystem\Filesystem */
protected $files; protected $files;
/** @var \Illuminate\View\Factory */ /** @var \Illuminate\View\Factory */
@@ -54,7 +54,7 @@ class GeneratorCommand extends Command
/** /**
* *
* @param \Illuminate\Config\Repository $config * @param \Illuminate\Config\Repository $config
* @param Filesystem $files * @param \Illuminate\Filesystem\Filesystem $files
* @param \Illuminate\View\Factory $view * @param \Illuminate\View\Factory $view
*/ */
public function __construct( public function __construct(
+16 -15
View File
@@ -266,7 +266,6 @@ class ModelsCommand extends Command
} }
$this->properties = []; $this->properties = [];
$this->methods = []; $this->methods = [];
$this->foreignKeyConstraintsColumns = [];
if (class_exists($name)) { if (class_exists($name)) {
try { try {
// handle abstract classes, interfaces, ... // handle abstract classes, interfaces, ...
@@ -355,7 +354,7 @@ class ModelsCommand extends Command
/** /**
* cast the properties's type from $casts. * cast the properties's type from $casts.
* *
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
*/ */
public function castPropertiesType($model) public function castPropertiesType($model)
{ {
@@ -499,7 +498,7 @@ class ModelsCommand extends Command
/** /**
* Load the properties from the database table. * Load the properties from the database table.
* *
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
* *
* @throws DBALException If custom field failed to register * @throws DBALException If custom field failed to register
*/ */
@@ -603,7 +602,7 @@ class ModelsCommand extends Command
} }
/** /**
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
*/ */
public function getPropertiesFromMethods($model) public function getPropertiesFromMethods($model)
{ {
@@ -778,7 +777,7 @@ class ModelsCommand extends Command
'int|null', 'int|null',
true, true,
false false
// What kind of comments should be added to the relation count here? // What kind of comments should be added to the relation count here?
); );
} }
} elseif ( } elseif (
@@ -1100,8 +1099,6 @@ class ModelsCommand extends Command
$default = 'null'; $default = 'null';
} elseif (is_int($default)) { } elseif (is_int($default)) {
//$default = $default; //$default = $default;
} elseif ($default instanceof \UnitEnum) {
$default = '\\' . get_class($default) . '::' . $default->name;
} else { } else {
$default = "'" . trim($default) . "'"; $default = "'" . trim($default) . "'";
} }
@@ -1129,7 +1126,7 @@ class ModelsCommand extends Command
return '\Illuminate\Database\Eloquent\Collection'; return '\Illuminate\Database\Eloquent\Collection';
} }
/** @var Model $model */ /** @var \Illuminate\Database\Eloquent\Model $model */
$model = new $className(); $model = new $className();
return '\\' . get_class($model->newCollection()); return '\\' . get_class($model->newCollection());
} }
@@ -1288,7 +1285,7 @@ class ModelsCommand extends Command
/** /**
* Generates methods provided by the SoftDeletes trait * Generates methods provided by the SoftDeletes trait
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
*/ */
protected function getSoftDeleteMethods($model) protected function getSoftDeleteMethods($model)
{ {
@@ -1305,7 +1302,7 @@ class ModelsCommand extends Command
/** /**
* Generate factory method from "HasFactory" trait. * Generate factory method from "HasFactory" trait.
* *
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
*/ */
protected function getFactoryMethods($model) protected function getFactoryMethods($model)
{ {
@@ -1333,12 +1330,16 @@ class ModelsCommand extends Command
return; return;
} }
$this->setMethod('factory', $factory, ['$count = null, $state = []']); if (version_compare($this->laravel->version(), '9', '>=')) {
$this->setMethod('factory', $factory, ['$count = null, $state = []']);
} else {
$this->setMethod('factory', $factory, ['...$parameters']);
}
} }
/** /**
* Generates methods that return collections * Generates methods that return collections
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
*/ */
protected function getCollectionMethods($model) protected function getCollectionMethods($model)
{ {
@@ -1381,7 +1382,7 @@ class ModelsCommand extends Command
return $type; return $type;
} }
$reflection = new ReflectionClass($type); $reflection = new \ReflectionClass($type);
if (!$reflection->implementsInterface(Castable::class)) { if (!$reflection->implementsInterface(Castable::class)) {
return $type; return $type;
@@ -1413,7 +1414,7 @@ class ModelsCommand extends Command
return $type; return $type;
} }
$reflection = new ReflectionClass($type); $reflection = new \ReflectionClass($type);
if (!$reflection->implementsInterface(CastsAttributes::class)) { if (!$reflection->implementsInterface(CastsAttributes::class)) {
return $type; return $type;
@@ -1619,7 +1620,7 @@ class ModelsCommand extends Command
} }
/** /**
* @param Model $model * @param \Illuminate\Database\Eloquent\Model $model
* @throws \Illuminate\Contracts\Container\BindingResolutionException * @throws \Illuminate\Contracts\Container\BindingResolutionException
* @throws \RuntimeException * @throws \RuntimeException
*/ */
+3 -11
View File
@@ -13,7 +13,6 @@ namespace Barryvdh\LaravelIdeHelper;
use Illuminate\Foundation\AliasLoader; use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Str; use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Macroable;
use ReflectionClass; use ReflectionClass;
@@ -27,7 +26,7 @@ class Generator
/** @var \Illuminate\View\Factory */ /** @var \Illuminate\View\Factory */
protected $view; protected $view;
/** @var OutputInterface */ /** @var \Symfony\Component\Console\Output\OutputInterface */
protected $output; protected $output;
protected $extra = []; protected $extra = [];
@@ -38,7 +37,7 @@ class Generator
/** /**
* @param \Illuminate\Config\Repository $config * @param \Illuminate\Config\Repository $config
* @param \Illuminate\View\Factory $view * @param \Illuminate\View\Factory $view
* @param OutputInterface $output * @param \Symfony\Component\Console\Output\OutputInterface $output
* @param string $helpers * @param string $helpers
*/ */
public function __construct( public function __construct(
@@ -154,11 +153,6 @@ class Generator
continue; continue;
} }
// Skip the swoole
if ($facade == 'SwooleTW\Http\Server\Facades\Server' && $name == 'Server' && !class_exists('Swoole\Http\Server')) {
continue;
}
$magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : []; $magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : [];
$alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces); $alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces);
if ($alias->isValid()) { if ($alias->isValid()) {
@@ -181,9 +175,7 @@ class Generator
*/ */
protected function getAliasesByExtendsNamespace() protected function getAliasesByExtendsNamespace()
{ {
$aliases = $this->getValidAliases()->filter(static function (Alias $alias) { $aliases = $this->getValidAliases();
return is_subclass_of($alias->getExtends(), Facade::class);
});
$this->addMacroableClasses($aliases); $this->addMacroableClasses($aliases);
+4 -4
View File
@@ -16,15 +16,15 @@ class GenerateModelHelper
*/ */
public static $shouldRun = false; public static $shouldRun = false;
/** @var Artisan */ /** @var \Illuminate\Contracts\Console\Kernel */
protected $artisan; protected $artisan;
/** @var Config */ /** @var \Illuminate\Contracts\Config\Repository */
protected $config; protected $config;
/** /**
* @param Artisan $artisan * @param \Illuminate\Contracts\Console\Kernel $artisan
* @param Config $config * @param \Illuminate\Contracts\Config\Repository $config
*/ */
public function __construct(Artisan $artisan, Config $config) public function __construct(Artisan $artisan, Config $config)
{ {
+1 -1
View File
@@ -22,7 +22,7 @@ use Illuminate\Support\Str;
class Method class Method
{ {
/** @var DocBlock */ /** @var \Barryvdh\Reflection\DocBlock */
protected $phpdoc; protected $phpdoc;
/** @var \ReflectionMethod */ /** @var \ReflectionMethod */
@@ -27,7 +27,7 @@ class Simple extends Model
* phpdoc is ignored here deliberately due to performance reasons and also * phpdoc is ignored here deliberately due to performance reasons and also
* isn't supported by Laravel itself. * isn't supported by Laravel itself.
* *
* @return Attribute * @return \Illuminate\Database\Eloquent\Casts\Attribute
*/ */
protected function notAnAttribute() protected function notAnAttribute()
{ {
@@ -9,6 +9,15 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand class Test extends AbstractModelsCommand
{ {
protected function setUp(): void
{
parent::setUp();
if (!class_exists('\Illuminate\Database\Eloquent\Casts\Attribute')) {
$this->markTestSkipped('This test requires Laravel 8.77 or newer');
}
}
public function test(): void public function test(): void
{ {
$command = $this->app->make(ModelsCommand::class); $command = $this->app->make(ModelsCommand::class);
@@ -38,7 +38,7 @@ class Simple extends Model
* phpdoc is ignored here deliberately due to performance reasons and also * phpdoc is ignored here deliberately due to performance reasons and also
* isn't supported by Laravel itself. * isn't supported by Laravel itself.
* *
* @return Attribute * @return \Illuminate\Database\Eloquent\Casts\Attribute
*/ */
protected function notAnAttribute() protected function notAnAttribute()
{ {
@@ -17,11 +17,19 @@ class Test extends AbstractModelsCommand
'--write' => true, '--write' => true,
]); ]);
$errors = [ if (PHP_VERSION_ID >= 80000) {
'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Attempt to read property "created_at" on null', $errors = [
'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Attempt to read property "created_at" on null', 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Attempt to read property "created_at" on null',
'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Attempt to read property "created_at" on null', 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Attempt to read property "created_at" on null',
]; 'Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Attempt to read property "created_at" on null',
];
} else {
$errors = [
"Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicBelongsTo() : Trying to get property 'created_at' of non-object",
"Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasMany() : Trying to get property 'created_at' of non-object",
"Error resolving relation model of Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\DynamicRelations\Models\Dynamic:dynamicHasOne() : Trying to get property 'created_at' of non-object",
];
}
$this->assertSame(0, $tester->getStatusCode()); $this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay()); $this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
+30 -1
View File
@@ -8,12 +8,41 @@ use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand; use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
use Closure; use Closure;
use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Foundation\Application;
use Illuminate\Support\Str; use Illuminate\Support\Str;
class Test extends AbstractModelsCommand class Test extends AbstractModelsCommand
{ {
public function testFactory(): void public function test_8(): void
{ {
if (!version_compare(Application::VERSION, '8.2', '>=') || !version_compare(Application::VERSION, '9', '<')) {
$this->markTestSkipped(
'This test only works in Laravel >= 8.2 and < 9'
);
}
Factory::guessFactoryNamesUsing(static::getFactoryNameResolver());
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
'--write' => true,
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertStringNotContainsString('not found', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
public function test_9(): void
{
if (!version_compare(Application::VERSION, '9', '>=')) {
$this->markTestSkipped(
'This test only works in Laravel >= 9'
);
}
Factory::guessFactoryNamesUsing(static::getFactoryNameResolver()); Factory::guessFactoryNamesUsing(static::getFactoryNameResolver());
$command = $this->app->make(ModelsCommand::class); $command = $this->app->make(ModelsCommand::class);
@@ -0,0 +1,94 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithCustomNamespace
*
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace query()
* @mixin \Eloquent
*/
class ModelWithCustomNamespace extends Model
{
use HasFactory;
/**
* Create a new factory instance for the model.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
protected static function newFactory()
{
return ModelWithCustomNamespaceFactory::new();
}
}
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithFactory
*
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithFactoryFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory query()
* @mixin \Eloquent
*/
class ModelWithFactory extends Model
{
use HasFactory;
}
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithNestedFactory
*
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithNestedFactoryFactory factory(...$parameters)
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory query()
* @mixin \Eloquent
*/
class ModelWithNestedFactory extends ModelWithFactory
{
}
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithoutFactory
*
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory query()
* @mixin \Eloquent
*/
class ModelWithoutFactory extends Model
{
use HasFactory;
}
@@ -1,12 +0,0 @@
<?php
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums;
enum PostStatus
{
case Published;
case Unpublished;
case Archived;
}
@@ -1,17 +0,0 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Models;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public function scopeHasStatus(Builder $query, ?PostStatus $status = PostStatus::Published)
{
//
}
}
@@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults;
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand
{
public function test(): void
{
if (!version_compare(PHP_VERSION, '8.1', '>=')) {
$this->markTestSkipped(
'This test only works in PHP >= 8.1'
);
}
$command = $this->app->make(ModelsCommand::class);
$tester = $this->runCommand($command, [
'--write' => true,
]);
$this->assertSame(0, $tester->getStatusCode());
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
$this->assertMatchesMockedSnapshot();
}
}
@@ -1,172 +0,0 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus;
/**
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Models\Post
*
* @property integer $id
* @property string|null $char_nullable
* @property string $char_not_nullable
* @property string|null $string_nullable
* @property string $string_not_nullable
* @property string|null $text_nullable
* @property string $text_not_nullable
* @property string|null $medium_text_nullable
* @property string $medium_text_not_nullable
* @property string|null $long_text_nullable
* @property string $long_text_not_nullable
* @property integer|null $integer_nullable
* @property integer $integer_not_nullable
* @property integer|null $tiny_integer_nullable
* @property integer $tiny_integer_not_nullable
* @property integer|null $small_integer_nullable
* @property integer $small_integer_not_nullable
* @property integer|null $medium_integer_nullable
* @property integer $medium_integer_not_nullable
* @property integer|null $big_integer_nullable
* @property integer $big_integer_not_nullable
* @property integer|null $unsigned_integer_nullable
* @property integer $unsigned_integer_not_nullable
* @property integer|null $unsigned_tiny_integer_nullable
* @property integer $unsigned_tiny_integer_not_nullable
* @property integer|null $unsigned_small_integer_nullable
* @property integer $unsigned_small_integer_not_nullable
* @property integer|null $unsigned_medium_integer_nullable
* @property integer $unsigned_medium_integer_not_nullable
* @property integer|null $unsigned_big_integer_nullable
* @property integer $unsigned_big_integer_not_nullable
* @property float|null $float_nullable
* @property float $float_not_nullable
* @property float|null $double_nullable
* @property float $double_not_nullable
* @property string|null $decimal_nullable
* @property string $decimal_not_nullable
* @property string|null $unsigned_decimal_nullable
* @property string $unsigned_decimal_not_nullable
* @property integer|null $boolean_nullable
* @property integer $boolean_not_nullable
* @property string|null $enum_nullable
* @property string $enum_not_nullable
* @property string|null $json_nullable
* @property string $json_not_nullable
* @property string|null $jsonb_nullable
* @property string $jsonb_not_nullable
* @property string|null $date_nullable
* @property string $date_not_nullable
* @property string|null $datetime_nullable
* @property string $datetime_not_nullable
* @property string|null $datetimetz_nullable
* @property string $datetimetz_not_nullable
* @property string|null $time_nullable
* @property string $time_not_nullable
* @property string|null $timetz_nullable
* @property string $timetz_not_nullable
* @property string|null $timestamp_nullable
* @property string $timestamp_not_nullable
* @property string|null $timestamptz_nullable
* @property string $timestamptz_not_nullable
* @property integer|null $year_nullable
* @property integer $year_not_nullable
* @property mixed|null $binary_nullable
* @property mixed $binary_not_nullable
* @property string|null $uuid_nullable
* @property string $uuid_not_nullable
* @property string|null $ipaddress_nullable
* @property string $ipaddress_not_nullable
* @property string|null $macaddress_nullable
* @property string $macaddress_not_nullable
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static Builder|Post hasStatus(?\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus $status = \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GenerateBasicPhpDocWithEnumDefaults\Enums\PostStatus::Published)
* @method static Builder|Post newModelQuery()
* @method static Builder|Post newQuery()
* @method static Builder|Post query()
* @method static Builder|Post whereBigIntegerNotNullable($value)
* @method static Builder|Post whereBigIntegerNullable($value)
* @method static Builder|Post whereBinaryNotNullable($value)
* @method static Builder|Post whereBinaryNullable($value)
* @method static Builder|Post whereBooleanNotNullable($value)
* @method static Builder|Post whereBooleanNullable($value)
* @method static Builder|Post whereCharNotNullable($value)
* @method static Builder|Post whereCharNullable($value)
* @method static Builder|Post whereCreatedAt($value)
* @method static Builder|Post whereDateNotNullable($value)
* @method static Builder|Post whereDateNullable($value)
* @method static Builder|Post whereDatetimeNotNullable($value)
* @method static Builder|Post whereDatetimeNullable($value)
* @method static Builder|Post whereDatetimetzNotNullable($value)
* @method static Builder|Post whereDatetimetzNullable($value)
* @method static Builder|Post whereDecimalNotNullable($value)
* @method static Builder|Post whereDecimalNullable($value)
* @method static Builder|Post whereDoubleNotNullable($value)
* @method static Builder|Post whereDoubleNullable($value)
* @method static Builder|Post whereEnumNotNullable($value)
* @method static Builder|Post whereEnumNullable($value)
* @method static Builder|Post whereFloatNotNullable($value)
* @method static Builder|Post whereFloatNullable($value)
* @method static Builder|Post whereId($value)
* @method static Builder|Post whereIntegerNotNullable($value)
* @method static Builder|Post whereIntegerNullable($value)
* @method static Builder|Post whereIpaddressNotNullable($value)
* @method static Builder|Post whereIpaddressNullable($value)
* @method static Builder|Post whereJsonNotNullable($value)
* @method static Builder|Post whereJsonNullable($value)
* @method static Builder|Post whereJsonbNotNullable($value)
* @method static Builder|Post whereJsonbNullable($value)
* @method static Builder|Post whereLongTextNotNullable($value)
* @method static Builder|Post whereLongTextNullable($value)
* @method static Builder|Post whereMacaddressNotNullable($value)
* @method static Builder|Post whereMacaddressNullable($value)
* @method static Builder|Post whereMediumIntegerNotNullable($value)
* @method static Builder|Post whereMediumIntegerNullable($value)
* @method static Builder|Post whereMediumTextNotNullable($value)
* @method static Builder|Post whereMediumTextNullable($value)
* @method static Builder|Post whereSmallIntegerNotNullable($value)
* @method static Builder|Post whereSmallIntegerNullable($value)
* @method static Builder|Post whereStringNotNullable($value)
* @method static Builder|Post whereStringNullable($value)
* @method static Builder|Post whereTextNotNullable($value)
* @method static Builder|Post whereTextNullable($value)
* @method static Builder|Post whereTimeNotNullable($value)
* @method static Builder|Post whereTimeNullable($value)
* @method static Builder|Post whereTimestampNotNullable($value)
* @method static Builder|Post whereTimestampNullable($value)
* @method static Builder|Post whereTimestamptzNotNullable($value)
* @method static Builder|Post whereTimestamptzNullable($value)
* @method static Builder|Post whereTimetzNotNullable($value)
* @method static Builder|Post whereTimetzNullable($value)
* @method static Builder|Post whereTinyIntegerNotNullable($value)
* @method static Builder|Post whereTinyIntegerNullable($value)
* @method static Builder|Post whereUnsignedBigIntegerNotNullable($value)
* @method static Builder|Post whereUnsignedBigIntegerNullable($value)
* @method static Builder|Post whereUnsignedDecimalNotNullable($value)
* @method static Builder|Post whereUnsignedDecimalNullable($value)
* @method static Builder|Post whereUnsignedIntegerNotNullable($value)
* @method static Builder|Post whereUnsignedIntegerNullable($value)
* @method static Builder|Post whereUnsignedMediumIntegerNotNullable($value)
* @method static Builder|Post whereUnsignedMediumIntegerNullable($value)
* @method static Builder|Post whereUnsignedSmallIntegerNotNullable($value)
* @method static Builder|Post whereUnsignedSmallIntegerNullable($value)
* @method static Builder|Post whereUnsignedTinyIntegerNotNullable($value)
* @method static Builder|Post whereUnsignedTinyIntegerNullable($value)
* @method static Builder|Post whereUpdatedAt($value)
* @method static Builder|Post whereUuidNotNullable($value)
* @method static Builder|Post whereUuidNullable($value)
* @method static Builder|Post whereYearNotNullable($value)
* @method static Builder|Post whereYearNullable($value)
* @mixin \Eloquent
*/
class Post extends Model
{
public function scopeHasStatus(Builder $query, ?PostStatus $status = PostStatus::Published)
{
//
}
}
@@ -11,7 +11,7 @@ class CastableReturnsAnonymousCaster implements Castable
{ {
public static function castUsing(array $arguments) public static function castUsing(array $arguments)
{ {
return new class () implements CastsAttributes { return new class() implements CastsAttributes {
/** /**
* @inheritDoc * @inheritDoc
* @return CastedProperty * @return CastedProperty
@@ -11,7 +11,7 @@ class CastableWithoutReturnType implements Castable
{ {
public static function castUsing(array $arguments) public static function castUsing(array $arguments)
{ {
return new class () implements CastsAttributes { return new class() implements CastsAttributes {
public function get($model, string $key, $value, array $attributes) public function get($model, string $key, $value, array $attributes)
{ {
return new CastedProperty(); return new CastedProperty();
@@ -10,7 +10,7 @@ class CustomCasterWithDocblockReturnFqn implements CastsAttributes
{ {
/** /**
* @inheritDoc * @inheritDoc
* @return CastedProperty * @return \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\LaravelCustomCasts\Casts\CastedProperty
*/ */
public function get($model, string $key, $value, array $attributes) public function get($model, string $key, $value, array $attributes)
{ {
@@ -9,6 +9,15 @@ use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
class Test extends AbstractModelsCommand class Test extends AbstractModelsCommand
{ {
protected function setUp(): void
{
parent::setUp();
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('This test requires PHP 8.0 or higher');
}
}
public function test(): void public function test(): void
{ {
$command = $this->app->make(ModelsCommand::class); $command = $this->app->make(ModelsCommand::class);
+6 -2
View File
@@ -190,6 +190,10 @@ class MacroTest extends TestCase
public function testInitPhpDocParamsWithUnionTypes(): void public function testInitPhpDocParamsWithUnionTypes(): void
{ {
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('This test requires PHP 8.0 or higher');
}
$phpdoc = (new MacroMock())->getPhpDoc(eval(<<<'PHP' $phpdoc = (new MacroMock())->getPhpDoc(eval(<<<'PHP'
return new ReflectionFunction( return new ReflectionFunction(
/** /**
@@ -227,7 +231,7 @@ class MacroTest extends TestCase
{ {
$reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke'); $reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke');
$macro = new Macro($reflectionMethod, UrlGenerator::class, new ReflectionClass(UrlGenerator::class), 'macroName'); $macro = new Macro($reflectionMethod, UrlGenerator::class, new \ReflectionClass(UrlGenerator::class), 'macroName');
$this->assertInstanceOf(Macro::class, $macro); $this->assertInstanceOf(Macro::class, $macro);
} }
@@ -239,7 +243,7 @@ class MacroTest extends TestCase
{ {
$reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke'); $reflectionMethod = new \ReflectionMethod(UrlGeneratorMacroClass::class, '__invoke');
$macro = new Macro($reflectionMethod, 'URL', new ReflectionClass(UrlGenerator::class), 'macroName'); $macro = new Macro($reflectionMethod, 'URL', new \ReflectionClass(UrlGenerator::class), 'macroName');
$output = <<<'DOC' $output = <<<'DOC'
/** /**
* *