generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from stevebauman/main
Add ability for other resources to be turbo-streamable
- Loading branch information
Showing
9 changed files
with
131 additions
and
11 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
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
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,8 @@ | ||
<?php | ||
|
||
namespace Tonysm\TurboLaravel\Views; | ||
|
||
interface TurboStreamable | ||
{ | ||
public function getDomId(); | ||
} |
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
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,13 @@ | ||
<?php | ||
|
||
namespace Tonysm\TurboLaravel\Tests\Stubs\Models; | ||
|
||
use Tonysm\TurboLaravel\Views\TurboStreamable; | ||
|
||
class TestTurboStreamable implements TurboStreamable | ||
{ | ||
public function getDomId() | ||
{ | ||
return 'turbo-dom-id'; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
namespace Tonysm\TurboLaravel\Tests; | ||
|
||
use Tonysm\TurboLaravel\Views\TurboStreamable; | ||
|
||
class TestTurboStreamable implements TurboStreamable | ||
{ | ||
public function getDomId() | ||
{ | ||
return 'turbo-dom-id'; | ||
} | ||
} |
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,44 @@ | ||
<?php | ||
|
||
namespace Tonysm\TurboLaravel\Tests\Views; | ||
|
||
use RuntimeException; | ||
use stdClass; | ||
use Tonysm\TurboLaravel\Tests\TestCase; | ||
use Tonysm\TurboLaravel\Tests\TestTurboStreamable; | ||
use Tonysm\TurboLaravel\Views\RecordIdentifier; | ||
|
||
class RecordIdentifierStreamableTest extends TestCase | ||
{ | ||
private $streamable; | ||
private $singular; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->streamable = new TestTurboStreamable; | ||
$this->singular = "test_turbo_streamable"; | ||
} | ||
|
||
/** @test */ | ||
public function dom_id_of_streamable() | ||
{ | ||
$this->assertEquals("{$this->singular}_turbo-dom-id", (new RecordIdentifier($this->streamable))->domId()); | ||
} | ||
|
||
/** @test */ | ||
public function dom_id_of_streamable_with_custom_prefix() | ||
{ | ||
$this->assertEquals("custom_prefix_{$this->singular}_turbo-dom-id", (new RecordIdentifier($this->streamable))->domId("custom_prefix")); | ||
} | ||
|
||
/** @test */ | ||
public function exception_is_thrown_when_given_non_streamable_instance() | ||
{ | ||
$this->expectException(RuntimeException::class); | ||
$this->expectExceptionMessage('[stdClass] must be an instance of Eloquent or TurboStreamable.'); | ||
|
||
new RecordIdentifier(new stdClass); | ||
} | ||
} |
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
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