Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed Apr 28, 2024
1 parent a07063d commit 5626176
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tests/Unit/CachedComponent/CachedComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ class CachedComponent extends \Vormkracht10\PermanentCache\CachedComponent
{
protected $store = 'file:unique-cache-key';

public function __construct(public string $value = '')
{
}

public function render(): string
{
$value = $this->value ?? str_random();

return <<<'HTML'
<div>This is a cached component: {{ str_random() }}</div>
<div>This is a cached component: {{ $value }}</div>
HTML;
}
}
13 changes: 13 additions & 0 deletions tests/Unit/CachedComponent/CachedComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,16 @@

$this->assertEquals($firstRunOutput, $secondRunOutput);
});


test('test cached component with parameters is cached correctly', function () {
$randomString = str_random();

$cachedComponentWithParameters = new CachedComponent(value: $randomString);

$firstRunOutput = Blade::renderComponent($cachedComponentWithParameters);
$secondRunOutput = Blade::renderComponent($cachedComponentWithParameters);

$this->assertEquals($firstRunOutput, '<div>This is a cached component: '.$randomString.'</div>');
$this->assertEquals($secondRunOutput, '<div>This is a cached component: '.$randomString.'</div>');
});
4 changes: 2 additions & 2 deletions tests/Unit/CachedComponent/ScheduledCachedComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ class ScheduledCachedComponent extends \Vormkracht10\PermanentCache\CachedCompon
{
protected $store = 'file:unique-cache-key';

public function __construct(public string $parameter = '')
public function __construct(public string $value = '')
{
}

public function render(): string
{
$value = $this->parameter;
$value = $this->value;

return <<<'HTML'
<div>This is a {{ $value ?? 'cached' }} component!</div>
Expand Down

0 comments on commit 5626176

Please sign in to comment.