Skip to content

Commit

Permalink
test: use a WorkbenchTestCase
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Oct 4, 2024
1 parent e3dec94 commit 2f7605c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 125 deletions.
74 changes: 74 additions & 0 deletions src/Laravel/Tests/Eloquent/Metadata/ModelMetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace ApiPlatform\Laravel\Tests\Eloquent\Metadata;

use ApiPlatform\Laravel\Eloquent\Metadata\ModelMetadata;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Orchestra\Testbench\Concerns\WithWorkbench;
use Orchestra\Testbench\TestCase;
use Workbench\App\Models\Book;

/**
* @author Tobias Oitzinger <tobiasoitzinger@gmail.com>
*/
final class ModelMetadataTest extends TestCase
{
use RefreshDatabase;
use WithWorkbench;

public function testHiddenAttributesAreCorrectlyIdentified(): void
{
$model = new class extends Model {
protected $hidden = ['secret'];

public function secret(): HasMany
{
return $this->hasMany(Book::class);
}
};

$metadata = new ModelMetadata();
$this->assertCount(0, $metadata->getRelations($model));
}

public function testVisibleAttributesAreCorrectlyIdentified(): void
{
$model = new class extends Model {
protected $visible = ['secret'];

public function secret(): HasMany
{
return $this->hasMany(Book::class);
}
};

$metadata = new ModelMetadata();
$this->assertCount(1, $metadata->getRelations($model));
}

public function testAllAttributesVisibleByDefault(): void
{
$model = new class extends Model {
public function secret(): HasMany
{
return $this->hasMany(Book::class);
}
};

$metadata = new ModelMetadata();
$this->assertCount(1, $metadata->getRelations($model));
}
}
125 changes: 0 additions & 125 deletions tests/Laravel/Metadata/VisibleHiddenAttributesTest.php

This file was deleted.

0 comments on commit 2f7605c

Please sign in to comment.