mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
* Removed support for Laravel 8 and therefore for PHP < 8.0 * Update php-cs-fixer to v3 * composer fix-style
46 lines
1.6 KiB
PHP
46 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories;
|
|
|
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
|
use Closure;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Test extends AbstractModelsCommand
|
|
{
|
|
public function testFactory(): void
|
|
{
|
|
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 static function getFactoryNameResolver(): Closure
|
|
{
|
|
// This mimics the default resolver, but with adjusted test namespaces.
|
|
// Illuminate\Database\Eloquent\Factories\Factory::resolveFactoryName
|
|
return function (string $modelName): string {
|
|
$appNamespace = 'Barryvdh\\LaravelIdeHelper\\Tests\\Console\\ModelsCommand\\Factories\\';
|
|
|
|
$modelName = Str::startsWith($modelName, $appNamespace . 'Models\\')
|
|
? Str::after($modelName, $appNamespace . 'Models\\')
|
|
: Str::after($modelName, $appNamespace);
|
|
|
|
return $appNamespace . 'Factories\\' . $modelName . 'Factory';
|
|
};
|
|
}
|
|
}
|