mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
* travis: use explicit test matrix and drop PHP < 7.2 * composer: use more liberal version requirements for orchestra This is to easier satisfy when we want to use older Laravel versions on travis * tests: add shim for assertStringContainsString for older Laravel/phpunit versions Specifically, Laravel 5.5 works with an older phpunit version, which does not feature assertStringContainsString * composer: bump minimum PHP version to 7.2 * travis: explicitly install Mockery for testing older Laravel versions * composer: make mockery a root requirement and remove the one from travis * travis: further improve based on suggestions from https://github.com/fruitcake/laravel-cors/blob/master/.travis.yml * tests: skip test if mixin markers are already present in model We're also testing Laravel 5.5 which contains them (they were removed later)
66 lines
2.2 KiB
PHP
66 lines
2.2 KiB
PHP
<?php
|
|
|
|
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);
|
|
|
|
$expectedContent = '/**
|
|
*
|
|
*
|
|
* @mixin \Eloquent
|
|
* @mixin \Illuminate\Database\Eloquent\Builder
|
|
* @mixin \Illuminate\Database\Query\Builder
|
|
*/
|
|
abstract class Model implements';
|
|
$this->assertSame($expectedContent, $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();
|
|
}
|
|
}
|