mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Make createLocalViewFactory compatible with Laravel 8 (#1026)
* Make createLocalViewFactory compatible with Laravel 8 Fixes https://github.com/barryvdh/laravel-ide-helper/issues/1024 * tests: move up mockFilesystem so it get be re-used in other tests Note: removed `$this->mockOutput = '';` as it was a no-op, that property doesn't exist (it was probably a typo, but I guess we don't need it anyway) * tests: show basic features for ide-helper:meta working
This commit is contained in:
@@ -15,6 +15,7 @@ use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
|
|||||||
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
use Barryvdh\LaravelIdeHelper\Console\MetaCommand;
|
||||||
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
use Illuminate\View\Engines\EngineResolver;
|
use Illuminate\View\Engines\EngineResolver;
|
||||||
use Illuminate\View\Engines\PhpEngine;
|
use Illuminate\View\Engines\PhpEngine;
|
||||||
@@ -116,7 +117,11 @@ class IdeHelperServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$resolver = new EngineResolver();
|
$resolver = new EngineResolver();
|
||||||
$resolver->register('php', function () {
|
$resolver->register('php', function () {
|
||||||
|
if ((int) Application::VERSION < 8) {
|
||||||
return new PhpEngine();
|
return new PhpEngine();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PhpEngine($this->app['files']);
|
||||||
});
|
});
|
||||||
$finder = new FileViewFinder($this->app['files'], [__DIR__ . '/../resources/views']);
|
$finder = new FileViewFinder($this->app['files'], [__DIR__ . '/../resources/views']);
|
||||||
$factory = new Factory($resolver, $finder, $this->app['events']);
|
$factory = new Factory($resolver, $finder, $this->app['events']);
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\MetaCommand;
|
||||||
|
|
||||||
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||||
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery\MockInterface;
|
||||||
|
|
||||||
|
class MetaCommandTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testCommand(): void
|
||||||
|
{
|
||||||
|
$this->mockFilesystem();
|
||||||
|
|
||||||
|
/** @var Filesystem|MockInterface $mockFileSystem */
|
||||||
|
$mockFileSystem = $this->app->make(Filesystem::class);
|
||||||
|
$this->instance('files', $mockFileSystem);
|
||||||
|
|
||||||
|
$mockFileSystem
|
||||||
|
->shouldReceive('getRequire')
|
||||||
|
->andReturnUsing(function ($__path, $__data) {
|
||||||
|
return (static function () use ($__path, $__data) {
|
||||||
|
extract($__data, EXTR_SKIP);
|
||||||
|
|
||||||
|
return require $__path;
|
||||||
|
})();
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->artisan('ide-helper:meta');
|
||||||
|
|
||||||
|
// We're not testing the whole file, just some basic structure elements
|
||||||
|
self::assertStringContainsString("namespace PHPSTORM_META {\n", $this->mockFilesystemOutput);
|
||||||
|
self::assertStringContainsString("PhpStorm Meta file, to provide autocomplete information for PhpStorm\n", $this->mockFilesystemOutput);
|
||||||
|
self::assertStringContainsString('override(', $this->mockFilesystemOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get package providers.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Foundation\Application $app
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
protected function getPackageProviders($app)
|
||||||
|
{
|
||||||
|
return [IdeHelperServiceProvider::class];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,13 +7,9 @@ namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand;
|
|||||||
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
use Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\SnapshotPhpDriver;
|
use Barryvdh\LaravelIdeHelper\Tests\SnapshotPhpDriver;
|
||||||
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
||||||
use Illuminate\Filesystem\Filesystem;
|
|
||||||
use Mockery;
|
|
||||||
|
|
||||||
abstract class AbstractModelsCommand extends TestCase
|
abstract class AbstractModelsCommand extends TestCase
|
||||||
{
|
{
|
||||||
protected $mockFilesystemOutput;
|
|
||||||
|
|
||||||
protected function setUp(): void
|
protected function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
@@ -57,33 +53,6 @@ abstract class AbstractModelsCommand extends TestCase
|
|||||||
$config->set('ide-helper.type_overrides', []);
|
$config->set('ide-helper.type_overrides', []);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function mockFilesystem()
|
|
||||||
{
|
|
||||||
$this->mockOutput = '';
|
|
||||||
|
|
||||||
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
||||||
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('get')
|
|
||||||
->andReturnUsing(function ($file) {
|
|
||||||
return file_get_contents($file);
|
|
||||||
});
|
|
||||||
|
|
||||||
$mockFilesystem
|
|
||||||
->shouldReceive('put')
|
|
||||||
->with(
|
|
||||||
Mockery::any(),
|
|
||||||
Mockery::any()
|
|
||||||
)
|
|
||||||
->andReturnUsing(function ($path, $contents) {
|
|
||||||
$this->mockFilesystemOutput .= $contents;
|
|
||||||
|
|
||||||
return strlen($contents);
|
|
||||||
});
|
|
||||||
|
|
||||||
$this->instance(Filesystem::class, $mockFilesystem);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function assertMatchesMockedSnapshot()
|
protected function assertMatchesMockedSnapshot()
|
||||||
{
|
{
|
||||||
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
|
$this->assertMatchesSnapshot($this->mockFilesystemOutput, new SnapshotPhpDriver());
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ declare(strict_types=1);
|
|||||||
namespace Barryvdh\LaravelIdeHelper\Tests;
|
namespace Barryvdh\LaravelIdeHelper\Tests;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
use Illuminate\Filesystem\Filesystem;
|
||||||
|
use Mockery;
|
||||||
use Orchestra\Testbench\TestCase as BaseTestCase;
|
use Orchestra\Testbench\TestCase as BaseTestCase;
|
||||||
use Spatie\Snapshots\MatchesSnapshots;
|
use Spatie\Snapshots\MatchesSnapshots;
|
||||||
use Symfony\Component\Console\Tester\CommandTester;
|
use Symfony\Component\Console\Tester\CommandTester;
|
||||||
@@ -13,6 +15,8 @@ abstract class TestCase extends BaseTestCase
|
|||||||
{
|
{
|
||||||
use MatchesSnapshots;
|
use MatchesSnapshots;
|
||||||
|
|
||||||
|
protected $mockFilesystemOutput;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `CommandTester` is directly returned, use methods like
|
* The `CommandTester` is directly returned, use methods like
|
||||||
* `->getDisplay()` or `->getStatusCode()` on it.
|
* `->getDisplay()` or `->getStatusCode()` on it.
|
||||||
@@ -50,4 +54,30 @@ abstract class TestCase extends BaseTestCase
|
|||||||
{
|
{
|
||||||
$this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver());
|
$this->assertMatchesSnapshot($actualContent, new SnapshotTxtDriver());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function mockFilesystem()
|
||||||
|
{
|
||||||
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
||||||
|
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('get')
|
||||||
|
->andReturnUsing(function ($file) {
|
||||||
|
return file_get_contents($file);
|
||||||
|
});
|
||||||
|
|
||||||
|
$mockFilesystem
|
||||||
|
->shouldReceive('put')
|
||||||
|
->with(
|
||||||
|
Mockery::any(),
|
||||||
|
Mockery::any()
|
||||||
|
)
|
||||||
|
->andReturnUsing(function ($path, $contents) {
|
||||||
|
$this->mockFilesystemOutput .= $contents;
|
||||||
|
|
||||||
|
return strlen($contents);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->instance(Filesystem::class, $mockFilesystem);
|
||||||
|
$this->instance('files', $mockFilesystem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user