Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 20 additions & 19 deletions tests/Feature/Concerns/HasDynamicLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Esign\Linkable\Tests\Feature\Concerns;

use PHPUnit\Framework\Attributes\Test;
use Esign\Linkable\Concerns\HasDynamicLink;
use Esign\Linkable\Tests\Support\Models\MenuItem;
use Esign\Linkable\Tests\Support\Models\ModelWithRegularMorphToRelation;
Expand All @@ -11,7 +12,7 @@
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Schema;

class HasDynamicLinkTest extends TestCase
final class HasDynamicLinkTest extends TestCase
{
use DatabaseMigrations;

Expand All @@ -34,8 +35,8 @@ protected function tearDown(): void
parent::tearDown();
}

/** @test */
public function it_can_check_if_it_has_an_internal_link()
#[Test]
public function it_can_check_if_it_has_an_internal_link(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItemA = MenuItem::create([
Expand All @@ -53,8 +54,8 @@ public function it_can_check_if_it_has_an_internal_link()
$this->assertFalse($menuItemB->hasDynamicLink());
}

/** @test */
public function it_can_check_if_it_has_an_external_link()
#[Test]
public function it_can_check_if_it_has_an_external_link(): void
{
$menuItemA = MenuItem::create([
'dynamic_link_type' => HasDynamicLink::$linkTypeExternal,
Expand All @@ -71,8 +72,8 @@ public function it_can_check_if_it_has_an_external_link()
$this->assertFalse($menuItemB->hasDynamicLink());
}

/** @test */
public function it_can_get_an_internal_link()
#[Test]
public function it_can_get_an_internal_link(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItemA = MenuItem::create([
Expand All @@ -90,8 +91,8 @@ public function it_can_get_an_internal_link()
$this->assertNull($menuItemB->dynamicLink());
}

/** @test */
public function it_can_get_null_as_a_link_when_the_link_type_isnt_internal_or_external()
#[Test]
public function it_can_get_null_as_a_link_when_the_link_type_isnt_internal_or_external(): void
{
$menuItem = MenuItem::create([
'dynamic_link_type' => null,
Expand All @@ -102,8 +103,8 @@ public function it_can_get_null_as_a_link_when_the_link_type_isnt_internal_or_ex
$this->assertNull($menuItem->dynamicLink());
}

/** @test */
public function it_can_get_an_external_url()
#[Test]
public function it_can_get_an_external_url(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItemA = MenuItem::create([
Expand All @@ -121,8 +122,8 @@ public function it_can_get_an_external_url()
$this->assertNull($menuItemB->dynamicLink());
}

/** @test */
public function it_can_check_if_a_link_is_of_type()
#[Test]
public function it_can_check_if_a_link_is_of_type(): void
{
$menuItem = MenuItem::create([
'dynamic_link_type' => HasDynamicLink::$linkTypeExternal,
Expand All @@ -136,8 +137,8 @@ public function it_can_check_if_a_link_is_of_type()
$this->assertFalse($menuItem->dynamicLinkIsOfType([HasDynamicLink::$linkTypeInternal]));
}

/** @test */
public function it_can_get_the_dynamic_link_type()
#[Test]
public function it_can_get_the_dynamic_link_type(): void
{
$menuItem = MenuItem::create([
'dynamic_link_type' => HasDynamicLink::$linkTypeExternal,
Expand All @@ -148,8 +149,8 @@ public function it_can_get_the_dynamic_link_type()
$this->assertEquals(HasDynamicLink::$linkTypeExternal, $menuItem->dynamicLinkType());
}

/** @test */
public function it_can_get_the_dynamic_link_url()
#[Test]
public function it_can_get_the_dynamic_link_url(): void
{
$menuItem = MenuItem::create([
'dynamic_link_type' => HasDynamicLink::$linkTypeExternal,
Expand All @@ -160,8 +161,8 @@ public function it_can_get_the_dynamic_link_url()
$this->assertEquals('http://localhost', $menuItem->dynamicLinkUrl());
}

/** @test */
public function it_can_use_a_regular_morph_to_relation()
#[Test]
public function it_can_use_a_regular_morph_to_relation(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItem = ModelWithRegularMorphToRelation::create([
Expand Down
39 changes: 20 additions & 19 deletions tests/Feature/Relations/SingleColumnMorphToTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,45 @@

namespace Esign\Linkable\Tests\Feature\Relations;

use PHPUnit\Framework\Attributes\Test;
use Error;
use Esign\Linkable\Tests\Support\Models\MenuItem;
use Esign\Linkable\Tests\Support\Models\Post;
use Esign\Linkable\Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use PDOException;

class SingleColumnMorphToTest extends TestCase
final class SingleColumnMorphToTest extends TestCase
{
use DatabaseMigrations;

/** @test */
public function it_can_query_a_related_model()
#[Test]
public function it_can_query_a_related_model(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItem = MenuItem::create(['dynamic_link_linkable_model' => "post:{$post->id}"]);

$this->assertTrue($menuItem->dynamicLinkLinkable->is($post));
}

/** @test */
public function it_can_return_null_if_a_related_model_does_not_exist()
#[Test]
public function it_can_return_null_if_a_related_model_does_not_exist(): void
{
$menuItem = MenuItem::create(['dynamic_link_linkable_model' => "post:non-existing-id"]);

$this->assertNull($menuItem->dynamicLinkLinkable);
}

/** @test */
public function it_can_return_null_if_the_foreign_key_is_null()
#[Test]
public function it_can_return_null_if_the_foreign_key_is_null(): void
{
$menuItem = MenuItem::create(['dynamic_link_linkable_model' => null]);

$this->assertNull($menuItem->dynamicLinkLinkable);
}

/** @test */
public function it_can_throw_an_exception_if_the_foreign_key_is_empty()
#[Test]
public function it_can_throw_an_exception_if_the_foreign_key_is_empty(): void
{
$this->expectException(PDOException::class);

Expand All @@ -48,8 +49,8 @@ public function it_can_throw_an_exception_if_the_foreign_key_is_empty()
$this->assertNull($menuItem->dynamicLinkLinkable);
}

/** @test */
public function it_can_throw_an_exception_if_the_model_does_not_exist()
#[Test]
public function it_can_throw_an_exception_if_the_model_does_not_exist(): void
{
$this->expectException(Error::class);
$this->expectExceptionMessage('Class "article" not found');
Expand All @@ -58,8 +59,8 @@ public function it_can_throw_an_exception_if_the_model_does_not_exist()
$this->assertNull($menuItem->dynamicLinkLinkable);
}

/** @test */
public function it_can_eager_load_related_models()
#[Test]
public function it_can_eager_load_related_models(): void
{
$postA = Post::create(['title' => 'Hello World']);
$postB = Post::create(['title' => 'Hello World 2']);
Expand All @@ -72,8 +73,8 @@ public function it_can_eager_load_related_models()
$this->assertTrue($menuItemLinkables->contains($postB));
}

/** @test */
public function it_can_associate_a_model()
#[Test]
public function it_can_associate_a_model(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItem = MenuItem::create(['dynamic_link_linkable_model' => null]);
Expand All @@ -83,8 +84,8 @@ public function it_can_associate_a_model()
$this->assertTrue($menuItem->dynamicLinkLinkable->is($post));
}

/** @test */
public function it_can_associate_a_null_value()
#[Test]
public function it_can_associate_a_null_value(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItem = MenuItem::create(['dynamic_link_linkable_model' => "post:{$post->id}"]);
Expand All @@ -94,8 +95,8 @@ public function it_can_associate_a_null_value()
$this->assertNull($menuItem->dynamicLinkLinkable);
}

/** @test */
public function it_can_dissociate_a_model()
#[Test]
public function it_can_dissociate_a_model(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItem = MenuItem::create(['dynamic_link_linkable_model' => "post:{$post->id}"]);
Expand Down
19 changes: 10 additions & 9 deletions tests/Feature/View/Components/DynamicLinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Esign\Linkable\Tests\Feature\View\Components;

use PHPUnit\Framework\Attributes\Test;
use Esign\Linkable\Concerns\HasDynamicLink;
use Esign\Linkable\Tests\Support\Models\MenuItem;
use Esign\Linkable\Tests\Support\Models\ModelWithoutDynamicLinkTrait;
Expand All @@ -10,12 +11,12 @@
use Illuminate\Foundation\Testing\Concerns\InteractsWithViews;
use Illuminate\View\ViewException;

class DynamicLinkTest extends TestCase
final class DynamicLinkTest extends TestCase
{
use InteractsWithViews;

/** @test */
public function it_can_render_the_view_for_an_external_link()
#[Test]
public function it_can_render_the_view_for_an_external_link(): void
{
$menuItem = MenuItem::create([
'dynamic_link_type' => HasDynamicLink::$linkTypeExternal,
Expand All @@ -34,8 +35,8 @@ public function it_can_render_the_view_for_an_external_link()
);
}

/** @test */
public function it_can_render_the_view_for_an_internal_link()
#[Test]
public function it_can_render_the_view_for_an_internal_link(): void
{
$post = Post::create(['title' => 'Hello World']);
$menuItem = MenuItem::create([
Expand All @@ -55,8 +56,8 @@ public function it_can_render_the_view_for_an_internal_link()
);
}

/** @test */
public function it_can_render_null_for_a_non_existing_dynamic_link_type()
#[Test]
public function it_can_render_null_for_a_non_existing_dynamic_link_type(): void
{
$menuItem = MenuItem::create([
'dynamic_link_type' => 'non-existing-link-type',
Expand All @@ -72,8 +73,8 @@ public function it_can_render_null_for_a_non_existing_dynamic_link_type()
$component->assertSee(null);
}

/** @test */
public function it_can_throw_an_exception_when_given_a_model_that_does_not_implement_the_dynamic_link_trait()
#[Test]
public function it_can_throw_an_exception_when_given_a_model_that_does_not_implement_the_dynamic_link_trait(): void
{
$this->expectException(ViewException::class);
$this->expectExceptionMessage(sprintf(
Expand Down
Loading