[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,
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
'include_factory_builders' => true,
+2
View File
@@ -45,6 +45,8 @@ return [
| Set to true to generate factory generators for better factory()
| method auto-completion.
|
| Deprecated for Laravel 8 or latest.
|
*/
'include_factory_builders' => false,
+14 -7
View File
@@ -12,18 +12,25 @@ class Factories
{
$factories = [];
$factory = app(Factory::class);
if (static::isLaravelSevenOrLower()) {
$factory = app(Factory::class);
$definitions = (new ReflectionClass(Factory::class))->getProperty('definitions');
$definitions->setAccessible(true);
$definitions = (new ReflectionClass(Factory::class))->getProperty('definitions');
$definitions->setAccessible(true);
foreach ($definitions->getValue($factory) as $factory_target => $config) {
try {
$factories[] = new ReflectionClass($factory_target);
} catch (Exception $exception) {
foreach ($definitions->getValue($factory) as $factory_target => $config) {
try {
$factories[] = new ReflectionClass($factory_target);
} catch (Exception $exception) {
}
}
}
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);
}
}