mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Update testsuite for Generator, simplify service provider and mock (#1635)
* Add templates to Eloquent * Test generator, update constructor * composer fix-style * Add filename test * UPdate test --------- Co-authored-by: laravel-ide-helper <[email protected]>
This commit is contained in:
co-authored by
laravel-ide-helper
parent
c33eacdefc
commit
14fdb572bb
@@ -81,7 +81,12 @@ class Alias
|
||||
$this->detectExtendsNamespace();
|
||||
|
||||
if (!empty($this->namespace)) {
|
||||
try {
|
||||
$this->classAliases = (new UsesResolver())->loadFromClass($this->root);
|
||||
} catch (Throwable $e) {
|
||||
$this->classAliases = [];
|
||||
}
|
||||
|
||||
|
||||
//Create a DocBlock and serializer instance
|
||||
$this->phpdoc = new DocBlock(new ReflectionClass($alias), new Context($this->namespace, $this->classAliases));
|
||||
|
||||
@@ -14,7 +14,9 @@ namespace Barryvdh\LaravelIdeHelper\Console;
|
||||
use Barryvdh\LaravelIdeHelper\Eloquent;
|
||||
use Barryvdh\LaravelIdeHelper\Generator;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use Illuminate\View\Factory;
|
||||
use Symfony\Component\Console\Input\InputArgument;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
|
||||
@@ -45,7 +47,7 @@ class GeneratorCommand extends Command
|
||||
/** @var Filesystem */
|
||||
protected $files;
|
||||
|
||||
/** @var \Illuminate\View\Factory */
|
||||
/** @var Factory */
|
||||
protected $view;
|
||||
|
||||
protected $onlyExtend;
|
||||
@@ -55,14 +57,12 @@ class GeneratorCommand extends Command
|
||||
*
|
||||
* @param \Illuminate\Config\Repository $config
|
||||
* @param Filesystem $files
|
||||
* @param \Illuminate\View\Factory $view
|
||||
* @param Factory $view
|
||||
*/
|
||||
public function __construct(
|
||||
/*ConfigRepository */
|
||||
$config,
|
||||
Repository $config,
|
||||
Filesystem $files,
|
||||
/* Illuminate\View\Factory */
|
||||
$view
|
||||
Factory $view
|
||||
) {
|
||||
$this->config = $config;
|
||||
$this->files = $files;
|
||||
|
||||
@@ -13,6 +13,9 @@ namespace Barryvdh\LaravelIdeHelper\Console;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Factories;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Contracts\Config\Repository;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
@@ -41,10 +44,10 @@ class MetaCommand extends Command
|
||||
/** @var \Illuminate\Contracts\Filesystem\Filesystem */
|
||||
protected $files;
|
||||
|
||||
/** @var \Illuminate\Contracts\View\Factory */
|
||||
/** @var Factory */
|
||||
protected $view;
|
||||
|
||||
/** @var \Illuminate\Contracts\Config\Repository */
|
||||
/** @var Repository */
|
||||
protected $config;
|
||||
|
||||
protected $methods = [
|
||||
@@ -63,12 +66,15 @@ class MetaCommand extends Command
|
||||
|
||||
/**
|
||||
*
|
||||
* @param \Illuminate\Contracts\Filesystem\Filesystem $files
|
||||
* @param \Illuminate\Contracts\View\Factory $view
|
||||
* @param \Illuminate\Contracts\Config\Repository $config
|
||||
* @param Filesystem $files
|
||||
* @param Factory $view
|
||||
* @param Repository $config
|
||||
*/
|
||||
public function __construct($files, $view, $config)
|
||||
{
|
||||
public function __construct(
|
||||
Filesystem $files,
|
||||
Factory $view,
|
||||
Repository $config
|
||||
) {
|
||||
$this->files = $files;
|
||||
$this->view = $view;
|
||||
$this->config = $config;
|
||||
|
||||
@@ -64,41 +64,20 @@ class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProv
|
||||
{
|
||||
$configPath = __DIR__ . '/../config/ide-helper.php';
|
||||
$this->mergeConfigFrom($configPath, 'ide-helper');
|
||||
$localViewFactory = $this->createLocalViewFactory();
|
||||
|
||||
$this->app->singleton(
|
||||
'command.ide-helper.generate',
|
||||
function ($app) use ($localViewFactory) {
|
||||
return new GeneratorCommand($app['config'], $app['files'], $localViewFactory);
|
||||
}
|
||||
);
|
||||
|
||||
$this->app->singleton(
|
||||
'command.ide-helper.models',
|
||||
function ($app) {
|
||||
return new ModelsCommand($app['files']);
|
||||
}
|
||||
);
|
||||
|
||||
$this->app->singleton(
|
||||
'command.ide-helper.meta',
|
||||
function ($app) use ($localViewFactory) {
|
||||
return new MetaCommand($app['files'], $localViewFactory, $app['config']);
|
||||
}
|
||||
);
|
||||
|
||||
$this->app->singleton(
|
||||
'command.ide-helper.eloquent',
|
||||
function ($app) {
|
||||
return new EloquentCommand($app['files']);
|
||||
}
|
||||
);
|
||||
$this->app->when([GeneratorCommand::class, MetaCommand::class])
|
||||
->needs(\Illuminate\Contracts\View\Factory::class)
|
||||
->give(function () {
|
||||
return $this->createLocalViewFactory();
|
||||
});
|
||||
|
||||
$this->commands(
|
||||
'command.ide-helper.generate',
|
||||
'command.ide-helper.models',
|
||||
'command.ide-helper.meta',
|
||||
'command.ide-helper.eloquent'
|
||||
[
|
||||
GeneratorCommand::class,
|
||||
ModelsCommand::class,
|
||||
MetaCommand::class,
|
||||
EloquentCommand::class,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -109,7 +88,12 @@ class IdeHelperServiceProvider extends ServiceProvider implements DeferrableProv
|
||||
*/
|
||||
public function provides()
|
||||
{
|
||||
return ['command.ide-helper.generate', 'command.ide-helper.models'];
|
||||
return [
|
||||
GeneratorCommand::class,
|
||||
ModelsCommand::class,
|
||||
MetaCommand::class,
|
||||
EloquentCommand::class,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||
use Barryvdh\LaravelIdeHelper\Tests\SnapshotPhpDriver;
|
||||
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||
|
||||
abstract class AbstractGeneratorCommand extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
$this->mockFilesystem();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get package providers.
|
||||
*
|
||||
* @param \Illuminate\Foundation\Application $app
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPackageProviders($app)
|
||||
{
|
||||
return [IdeHelperServiceProvider::class];
|
||||
}
|
||||
|
||||
protected function assertMatchesMockedSnapshot()
|
||||
{
|
||||
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand\GenerateIdeHelper;
|
||||
|
||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||
use Barryvdh\LaravelIdeHelper\Tests\Console\GeneratorCommand\AbstractGeneratorCommand;
|
||||
|
||||
class Test extends AbstractGeneratorCommand
|
||||
{
|
||||
public function testGenerator(): void
|
||||
{
|
||||
$command = $this->app->make(GeneratorCommand::class);
|
||||
|
||||
$tester = $this->runCommand($command);
|
||||
|
||||
$this->assertSame(0, $tester->getStatusCode());
|
||||
$this->assertStringContainsString('A new helper file was written to _ide_helper.php', $tester->getDisplay());
|
||||
$this->assertStringContainsString('public static function configure($basePath = null)', $this->mockFilesystemOutput);
|
||||
}
|
||||
|
||||
public function testFilename(): void
|
||||
{
|
||||
$command = $this->app->make(GeneratorCommand::class);
|
||||
|
||||
$tester = $this->runCommand($command, [
|
||||
'filename' => 'foo.php',
|
||||
]);
|
||||
|
||||
$this->assertSame(0, $tester->getStatusCode());
|
||||
$this->assertStringContainsString('A new helper file was written to foo.php', $tester->getDisplay());
|
||||
}
|
||||
}
|
||||
+22668
File diff suppressed because it is too large
Load Diff
+22668
File diff suppressed because it is too large
Load Diff
@@ -12,13 +12,18 @@ use stdClass;
|
||||
|
||||
class MetaCommandTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->mockFilesystem();
|
||||
}
|
||||
|
||||
public function testCommand(): void
|
||||
{
|
||||
$this->mockFilesystem();
|
||||
|
||||
/** @var Filesystem|MockInterface $mockFileSystem */
|
||||
$mockFileSystem = $this->app->make(Filesystem::class);
|
||||
$this->instance('files', $mockFileSystem);
|
||||
$this->instance(Filesystem::class, $mockFileSystem);
|
||||
|
||||
$mockFileSystem
|
||||
->shouldReceive('getRequire')
|
||||
@@ -49,11 +54,9 @@ class MetaCommandTest extends TestCase
|
||||
return new stdClass();
|
||||
});
|
||||
|
||||
$this->mockFilesystem();
|
||||
|
||||
/** @var Filesystem|MockInterface $mockFileSystem */
|
||||
$mockFileSystem = $this->app->make(Filesystem::class);
|
||||
$this->instance('files', $mockFileSystem);
|
||||
$this->instance(Filesystem::class, $mockFileSystem);
|
||||
|
||||
$mockFileSystem
|
||||
->shouldReceive('getRequire')
|
||||
|
||||
+1
-7
@@ -57,13 +57,7 @@ abstract class TestCase extends BaseTestCase
|
||||
|
||||
protected function mockFilesystem()
|
||||
{
|
||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||
|
||||
$mockFilesystem
|
||||
->shouldReceive('get')
|
||||
->andReturnUsing(function ($file) {
|
||||
return file_get_contents($file);
|
||||
});
|
||||
$mockFilesystem = Mockery::mock(Filesystem::class)->makePartial();
|
||||
|
||||
$mockFilesystem
|
||||
->shouldReceive('put')
|
||||
|
||||
Reference in New Issue
Block a user