From 81fec3431d480822a7cbec223a5e6137ade119e3 Mon Sep 17 00:00:00 2001 From: Alex Renoki Date: Sun, 13 Nov 2022 20:46:17 +0200 Subject: [PATCH] Fixed polling because of direct attribute checks --- composer.json | 1 + src/Traits/QueryCacheable.php | 13 +++++---- tests/LivewireTest.php | 41 +++++++++++++++++++++++++++ tests/TestCase.php | 13 +++++++-- tests/views/livewire/layout.blade.php | 14 +++++++++ tests/views/livewire/post.blade.php | 4 +++ 6 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 tests/LivewireTest.php create mode 100644 tests/views/livewire/layout.blade.php create mode 100644 tests/views/livewire/post.blade.php diff --git a/composer.json b/composer.json index 9538e7c..1803029 100644 --- a/composer.json +++ b/composer.json @@ -39,6 +39,7 @@ "require-dev": { "chelout/laravel-relationship-events": "^1.5", "laravel/legacy-factories": "^1.3", + "livewire/livewire": "dev-master", "mockery/mockery": "^1.5", "orchestra/database": "^6.28|^7.0", "orchestra/testbench": "^6.28|^7.0", diff --git a/src/Traits/QueryCacheable.php b/src/Traits/QueryCacheable.php index d7be9c1..c9f85a8 100644 --- a/src/Traits/QueryCacheable.php +++ b/src/Traits/QueryCacheable.php @@ -27,6 +27,7 @@ trait QueryCacheable */ public static function bootQueryCacheable() { + /** @var \Illuminate\Database\Eloquent\Model $this */ if (isset(static::$flushCacheOnUpdate) && static::$flushCacheOnUpdate) { static::observe( static::getFlushQueryCacheObserver() @@ -69,6 +70,7 @@ protected function getCacheBaseTags(): array */ public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModels = null): array { + /** @var \Illuminate\Database\Eloquent\Model $this */ return $this->getCacheBaseTags(); } @@ -77,6 +79,7 @@ public function getCacheTagsToInvalidateOnUpdate($relation = null, $pivotedModel */ protected function newBaseQueryBuilder() { + /** @var \Illuminate\Database\Eloquent\Model $this */ $connection = $this->getConnection(); $builder = new Builder( @@ -87,7 +90,7 @@ protected function newBaseQueryBuilder() $builder->dontCache(); - if ($this->cacheFor) { + if (property_exists($this, 'cacheFor')) { $builder->cacheFor($this->cacheFor); } @@ -95,7 +98,7 @@ protected function newBaseQueryBuilder() $builder->cacheFor($this->cacheForValue($builder)); } - if ($this->cacheTags) { + if (property_exists($this, 'cacheTags')) { $builder->cacheTags($this->cacheTags); } @@ -103,7 +106,7 @@ protected function newBaseQueryBuilder() $builder->cacheTags($this->cacheTagsValue($builder)); } - if ($this->cachePrefix) { + if (property_exists($this, 'cachePrefix')) { $builder->cachePrefix($this->cachePrefix); } @@ -111,7 +114,7 @@ protected function newBaseQueryBuilder() $builder->cachePrefix($this->cachePrefixValue($builder)); } - if ($this->cacheDriver) { + if (property_exists($this, 'cacheDriver')) { $builder->cacheDriver($this->cacheDriver); } @@ -119,7 +122,7 @@ protected function newBaseQueryBuilder() $builder->cacheDriver($this->cacheDriverValue($builder)); } - if ($this->cacheUsePlainKey) { + if (property_exists($this, 'cacheUsePlainKey')) { $builder->withPlainKey(); } diff --git a/tests/LivewireTest.php b/tests/LivewireTest.php new file mode 100644 index 0000000..20fd5f8 --- /dev/null +++ b/tests/LivewireTest.php @@ -0,0 +1,41 @@ +create(); + + /** @var \Livewire\Testing\TestableLivewire $component */ + Livewire::test(PostComponent::class, ['post' => $posts->first()]) + ->assertOk() + ->assertSee($posts[0]->name) + ->pretendWereSendingAComponentUpdateRequest( + 'callMethod', + ['id' => 'grwk', 'method' => '$refresh', 'params' => []], + ); + } +} + +class PostComponent extends Component +{ + public Post $post; + + public static function getName() + { + return 'post'; + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 3705f41..0e2ec9d 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -37,7 +37,7 @@ public function setUp(): void protected function getPackageProviders($app) { return [ - // + \Livewire\LivewireServiceProvider::class, ]; } @@ -52,15 +52,24 @@ public function getEnvironmentSetUp($app) 'database' => __DIR__.'/database/database.sqlite', 'prefix' => '', ]); + $app['config']->set( - 'cache.driver', getenv('CACHE_DRIVER') ?: env('CACHE_DRIVER', 'array') + 'cache.driver', + getenv('CACHE_DRIVER') ?: env('CACHE_DRIVER', 'array') ); + $app['config']->set('auth.providers.users.model', User::class); $app['config']->set('auth.providers.posts.model', Post::class); $app['config']->set('auth.providers.kids.model', Kid::class); $app['config']->set('auth.providers.books.model', Book::class); $app['config']->set('auth.providers.pages.model', Page::class); $app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD'); + + $app['config']->set('view.paths', [ + __DIR__.'/views', + ]); + + $app['config']->set('livewire.view_path', __DIR__.'/views/livewire'); } /** diff --git a/tests/views/livewire/layout.blade.php b/tests/views/livewire/layout.blade.php new file mode 100644 index 0000000..2ef1395 --- /dev/null +++ b/tests/views/livewire/layout.blade.php @@ -0,0 +1,14 @@ + + + + + + + Document + @livewireStyles + + + + @livewireScripts + + diff --git a/tests/views/livewire/post.blade.php b/tests/views/livewire/post.blade.php new file mode 100644 index 0000000..fb74375 --- /dev/null +++ b/tests/views/livewire/post.blade.php @@ -0,0 +1,4 @@ +
+

Title: {{ $post->name }}

+

Time: {{ now() }}

+