[LARAVEL 8] include_factory_builders does not work anymore (#1047) (#1049)

* [LARAVEL 8] include_factory_builders does not work anymore (#1047)

* Change skip expression
Append comment about deprecated to config file
Append comment about deprecated to README file
This commit is contained in:
Igor Finagin
2020-09-20 08:36:35 +02:00
committed by GitHub
parent 2ff9672a49
commit fd4d280a80
4 changed files with 35 additions and 7 deletions
+1
View File
@@ -256,6 +256,7 @@ Then run `php artisan ide-helper:generate`, you will now see all Fluent methods
If you would like the `factory()->create()` and `factory()->make()` methods to return the correct model class, If you would like the `factory()->create()` and `factory()->make()` methods to return the correct model class,
you can enable custom factory builders with the `include_factory_builders` line your `config/ide-helper.php` file. you can enable custom factory builders with the `include_factory_builders` line your `config/ide-helper.php` file.
Deprecated for Laravel 8 or latest.
```php ```php
'include_factory_builders' => true, 'include_factory_builders' => true,
+2
View File
@@ -45,6 +45,8 @@ return [
| Set to true to generate factory generators for better factory() | Set to true to generate factory generators for better factory()
| method auto-completion. | method auto-completion.
| |
| Deprecated for Laravel 8 or latest.
|
*/ */
'include_factory_builders' => false, 'include_factory_builders' => false,
+7
View File
@@ -12,6 +12,7 @@ class Factories
{ {
$factories = []; $factories = [];
if (static::isLaravelSevenOrLower()) {
$factory = app(Factory::class); $factory = app(Factory::class);
$definitions = (new ReflectionClass(Factory::class))->getProperty('definitions'); $definitions = (new ReflectionClass(Factory::class))->getProperty('definitions');
@@ -23,7 +24,13 @@ class Factories
} catch (Exception $exception) { } catch (Exception $exception) {
} }
} }
}
return $factories; return $factories;
} }
protected static function isLaravelSevenOrLower()
{
return class_exists('Illuminate\Database\Eloquent\Factory');
}
} }
+18
View File
@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Barryvdh\LaravelIdeHelper\Tests\Factories;
use Barryvdh\LaravelIdeHelper\Factories;
use PHPUnit\Framework\TestCase;
class AllTest extends TestCase
{
public function testAll(): void
{
$factories = Factories::all();
self::assertEmpty($factories);
}
}