-
-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.