Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Jan 2, 2024
1 parent 3eb5c0d commit 244cf57
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/Fields/HasManyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\HasMany;
use Cone\Root\Models\Medium;
use Cone\Root\Tests\TestCase;
use Cone\Root\Tests\User;

class HasManyTest extends TestCase
{
protected HasMany $field;

public function setUp(): void
{
parent::setUp();

$this->field = new HasMany('Uploads');
}

public function test_a_has_many_field_hydates_model(): void
{
$user = User::factory()->create();

$medium = Medium::factory()->create();

$this->field->resolveHydrate($this->app['request'], $user, [$medium->getKey()]);

$this->assertTrue($user->uploads->contains($medium));
}
}
31 changes: 31 additions & 0 deletions tests/Fields/HasOneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Cone\Root\Tests\Fields;

use Cone\Root\Fields\HasOne;
use Cone\Root\Models\Medium;
use Cone\Root\Tests\TestCase;
use Cone\Root\Tests\User;

class HasOneTest extends TestCase
{
protected HasOne $field;

public function setUp(): void
{
parent::setUp();

$this->field = new HasOne('Latest Upload', 'latestUpload');
}

public function test_a_has_one_field_hydates_model(): void
{
$user = User::factory()->create();

$medium = Medium::factory()->create();

$this->field->resolveHydrate($this->app['request'], $user, $medium->getKey());

$this->assertTrue($user->latestUpload->is($medium));
}
}
6 changes: 6 additions & 0 deletions tests/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Cone\Root\Traits\HasMetaData;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Relations\HasOne;

class User extends Model implements MustVerifyEmail, RootUser
{
Expand All @@ -23,4 +24,9 @@ protected static function newFactory(): UserFactory
protected $model = User::class;
};
}

public function latestUpload(): HasOne
{
return $this->uploads()->one()->ofMany();
}
}

0 comments on commit 244cf57

Please sign in to comment.