diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index b737a5f..6d336ed 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -55,12 +55,12 @@ jobs: - name: Prepare functional testcases run: composer bootstrap-test-environment - - name: Run functional tests - run: composer phpunit -- Tests/Functional --log-junit var/junit.xml - - name: Linting code run: composer lint + - name: Run functional tests + run: composer phpunit -- Tests/Functional --log-junit var/junit.xml + php-cs-fixer: name: Run php-cs-fixer runs-on: ubuntu-18.04 diff --git a/Controller/HeadlessWebsiteController.php b/Controller/HeadlessWebsiteController.php index ba58526..9308f7e 100644 --- a/Controller/HeadlessWebsiteController.php +++ b/Controller/HeadlessWebsiteController.php @@ -17,6 +17,7 @@ use JMS\Serializer\SerializerInterface; use Sulu\Bundle\HeadlessBundle\Content\StructureResolverInterface; use Sulu\Bundle\HttpCacheBundle\CacheLifetime\CacheLifetimeEnhancer; +use Sulu\Bundle\HttpCacheBundle\CacheLifetime\CacheLifetimeEnhancerInterface; use Sulu\Bundle\PreviewBundle\Preview\Preview; use Sulu\Component\Content\Compat\PageInterface; use Sulu\Component\Content\Compat\StructureInterface; @@ -53,8 +54,9 @@ public function indexAction( $response->headers->set('Content-Type', 'application/json'); } - if (!$preview && $this->getCacheTimeLifeEnhancer()) { - $this->getCacheTimeLifeEnhancer()->enhance($response, $structure); + $cacheLifetimeEnhancer = $this->getCacheLifetimeEnhancer(); + if (!$preview && $cacheLifetimeEnhancer) { + $cacheLifetimeEnhancer->enhance($response, $structure); } return $response; @@ -117,16 +119,20 @@ public static function getSubscribedServices(): array $subscribedServices = parent::getSubscribedServices(); $subscribedServices['sulu_headless.structure_resolver'] = StructureResolverInterface::class; $subscribedServices['jms_serializer'] = SerializerInterface::class; + $subscribedServices['sulu_http_cache.cache_lifetime.enhancer'] = '?' . CacheLifetimeEnhancerInterface::class; return $subscribedServices; } - protected function getCacheTimeLifeEnhancer(): ?CacheLifetimeEnhancer + protected function getCacheLifetimeEnhancer(): ?CacheLifetimeEnhancer { if (!$this->has('sulu_http_cache.cache_lifetime.enhancer')) { return null; } - return $this->get('sulu_http_cache.cache_lifetime.enhancer'); + /** @var CacheLifetimeEnhancer $cacheLifetimeEnhancer */ + $cacheLifetimeEnhancer = $this->get('sulu_http_cache.cache_lifetime.enhancer'); + + return $cacheLifetimeEnhancer; } } diff --git a/Tests/Functional/Controller/responses/headless_website__test_index.json b/Tests/Functional/Controller/responses/headless_website__test_index.json index a400bba..dfcd455 100644 --- a/Tests/Functional/Controller/responses/headless_website__test_index.json +++ b/Tests/Functional/Controller/responses/headless_website__test_index.json @@ -35,7 +35,7 @@ "categories": [], "tags": [], "images": [], - "segment": null, + "segments": [], "icon": [], "audience_targeting_groups": [] } diff --git a/Tests/Functional/Controller/responses/navigation__get_excerpt.json b/Tests/Functional/Controller/responses/navigation__get_excerpt.json index c401e24..450294a 100644 --- a/Tests/Functional/Controller/responses/navigation__get_excerpt.json +++ b/Tests/Functional/Controller/responses/navigation__get_excerpt.json @@ -31,7 +31,7 @@ "categories": [], "audience_targeting_groups": [], "tags": [], - "segment": "", + "segments": [], "icon": [], "images": [] }, @@ -67,7 +67,7 @@ "categories": [], "audience_targeting_groups": [], "tags": [], - "segment": "", + "segments": [], "icon": [ { "id": "@integer@", diff --git a/phpstan.neon b/phpstan.neon index 4115f66..b26ea37 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -18,5 +18,6 @@ parameters: symfony: container_xml_path: %rootDir%/../../../Tests/Application/var/cache/admin/dev/Sulu_Bundle_HeadlessBundle_Tests_Application_KernelDevDebugContainer.xml console_application_loader: Tests/phpstan/console-application.php + constant_hassers: false doctrine: objectManagerLoader: Tests/phpstan/object-manager.php