mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 10:07:12 +00:00
* composer require --dev friendsofphp/php-cs-fixer:^2 * php-cs-fixer: ignore cache and custom local config file * php-cs-fixer: initial config * php-cs-fixer: replace commands in composer * php-cs-fixer: add PSR12 "as good as it currently gets" * php-cs-fixer: apply PSR12 to codebase * tests: add workaround to keep unused imports for snapshot testing * php-cs-fixer: apply no_unused_imports * php-cs-fixer: apply array_syntax short * php-cs-fixer: apply single_quote * php-cs-fixer: switch ordered_imports sort_algorithm to alpha Let's be opinionated here for consistency * php-cs-fixer: split between non-tests and tests and share config * php-cs-fixer: apply declare_strict_types for tests * php-cs-fixer: apply fully_qualified_strict_types * php-cs-fixer: apply space_after_semicolon * php-cs-fixer: apply trailing_comma_in_multiline_array * php-cs-fixer: apply trim_array_spaces * php-cs-fixer: apply unary_operator_spaces * php-cs-fixer: apply whitespace_after_comma_in_array * php-cs-fixer: apply native_function_invocation * php-cs-fixer: apply concat_space * grumphp: reflect we're using phpcsfixer now * composer remove --dev squizlabs/php_codesniffer * gha: simplify fix-style approach Not really necessary to remove packages and then manually prevent unrelated commits creeping in Co-authored-by: Barry vd. Heuvel <[email protected]>
66 lines
2.1 KiB
PHP
66 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console;
|
|
|
|
use Barryvdh\LaravelIdeHelper\Console\EloquentCommand;
|
|
use Barryvdh\LaravelIdeHelper\Tests\TestCase;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Filesystem\Filesystem;
|
|
use Mockery;
|
|
use ReflectionClass;
|
|
|
|
class EloquentCommandTest extends TestCase
|
|
{
|
|
public function testCommand()
|
|
{
|
|
$modelFilename = $this->getVendorModelFilename();
|
|
$modelSource = file_get_contents($modelFilename);
|
|
if (false !== strpos($modelSource, '* @mixin')) {
|
|
$msg = sprintf('Class %s already contains the @mixin markers', Model::class);
|
|
$this->markTestSkipped($msg);
|
|
}
|
|
|
|
$actualContent = null;
|
|
$mockFilesystem = Mockery::mock(Filesystem::class);
|
|
$mockFilesystem
|
|
->shouldReceive('get')
|
|
// We don't care about actual args (filename)
|
|
->andReturn('abstract class Model implements'); // This is enough to trigger the replacement logic
|
|
$mockFilesystem
|
|
->shouldReceive('put')
|
|
->with(
|
|
Mockery::any(), // First arg is path, we don't care
|
|
Mockery::capture($actualContent)
|
|
)
|
|
->andReturn(1) // Simulate we wrote _something_ to the file
|
|
->once();
|
|
|
|
$this->instance(Filesystem::class, $mockFilesystem);
|
|
$command = $this->app->make(EloquentCommand::class);
|
|
|
|
$tester = $this->runCommand($command);
|
|
|
|
$this->assertMatchesTxtSnapshot($actualContent);
|
|
|
|
$display = $tester->getDisplay();
|
|
$this->assertRegExp(
|
|
';Unexpected no document on Illuminate\\\Database\\\Eloquent\\\Model;',
|
|
$display
|
|
);
|
|
$this->assertRegExp(
|
|
';Wrote expected docblock to .*/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php;',
|
|
$display
|
|
);
|
|
}
|
|
|
|
private function getVendorModelFilename(): string
|
|
{
|
|
$class = Model::class;
|
|
$reflectedClass = new ReflectionClass($class);
|
|
|
|
return $reflectedClass->getFileName();
|
|
}
|
|
}
|