From 5626176f17f2aad747166d90fbfbc9f2c6179afc Mon Sep 17 00:00:00 2001 From: Mark van Eijk Date: Sun, 28 Apr 2024 10:18:27 +0200 Subject: [PATCH] wip --- tests/Unit/CachedComponent/CachedComponent.php | 8 +++++++- tests/Unit/CachedComponent/CachedComponentTest.php | 13 +++++++++++++ .../CachedComponent/ScheduledCachedComponent.php | 4 ++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/tests/Unit/CachedComponent/CachedComponent.php b/tests/Unit/CachedComponent/CachedComponent.php index 1091a49..b0c365e 100644 --- a/tests/Unit/CachedComponent/CachedComponent.php +++ b/tests/Unit/CachedComponent/CachedComponent.php @@ -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' -
This is a cached component: {{ str_random() }}
+
This is a cached component: {{ $value }}
HTML; } } diff --git a/tests/Unit/CachedComponent/CachedComponentTest.php b/tests/Unit/CachedComponent/CachedComponentTest.php index 3737f0f..fa19690 100644 --- a/tests/Unit/CachedComponent/CachedComponentTest.php +++ b/tests/Unit/CachedComponent/CachedComponentTest.php @@ -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, '
This is a cached component: '.$randomString.'
'); + $this->assertEquals($secondRunOutput, '
This is a cached component: '.$randomString.'
'); +}); diff --git a/tests/Unit/CachedComponent/ScheduledCachedComponent.php b/tests/Unit/CachedComponent/ScheduledCachedComponent.php index 58d525e..798347c 100644 --- a/tests/Unit/CachedComponent/ScheduledCachedComponent.php +++ b/tests/Unit/CachedComponent/ScheduledCachedComponent.php @@ -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'
This is a {{ $value ?? 'cached' }} component!