mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
* feat: add config option for nullable relationships Introduce enforce_nullable_relationships configuration to control nullable Eloquent relationships. * refactor: update logic for nullable relationships Update isRelationNullable method to respect new config option. * test: add tests for nullable relationship config - Verify behavior of enforce_nullable_relationships configuration option. - Create snapshot to reflect enforce_nullable_relationships set to false. * docs: improve documented context and usage * docs: update CHANGELOG with enforce_nullable_relationships option
69 lines
2.6 KiB
PHP
69 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations;
|
|
|
|
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToAnyMorphedRelationType;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToAnyRelationType;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToBadlyNamedNotManyRelationType;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToManyRelationType;
|
|
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Relations\Types\SampleToOneRelationType;
|
|
use Illuminate\Support\Facades\Config;
|
|
|
|
class Test extends AbstractModelsCommand
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Config::set('ide-helper.additional_relation_types', [
|
|
'testToOneRelation' => SampleToOneRelationType::class,
|
|
'testToManyRelation' => SampleToManyRelationType::class,
|
|
'testToAnyRelation' => SampleToAnyRelationType::class,
|
|
'testToAnyMorphedRelation' => SampleToAnyMorphedRelationType::class,
|
|
'testToBadlyNamedNotManyRelation' => SampleToBadlyNamedNotManyRelationType::class,
|
|
]);
|
|
|
|
Config::set('ide-helper.additional_relation_return_types', [
|
|
'testToAnyRelation' => 'many',
|
|
'testToAnyMorphedRelation' => 'morphTo',
|
|
'testToBadlyNamedNotManyRelation' => 'one',
|
|
]);
|
|
}
|
|
|
|
public function test(): void
|
|
{
|
|
$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->assertMatchesMockedSnapshot();
|
|
}
|
|
|
|
public function testRelationNotNullable(): void
|
|
{
|
|
// Disable enforcing nullable relationships
|
|
Config::set('ide-helper.enforce_nullable_relationships', false);
|
|
|
|
$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->assertMatchesMockedSnapshot();
|
|
|
|
// Re-enable default enforcing nullable relationships
|
|
Config::set('ide-helper.enforce_nullable_relationships', true);
|
|
}
|
|
}
|