From ec8462b7d0dfd8939e408771642318c58c327d43 Mon Sep 17 00:00:00 2001 From: Fabian Schmick Date: Mon, 14 Oct 2024 11:16:26 +0000 Subject: [PATCH 01/14] Validate shortcode controllername service configurations --- src/Handler/EmbeddedShortcodeHandler.php | 15 ++++--- .../EmbeddedShortcodeHandlerTest.php | 44 +++++++++++++++++-- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/Handler/EmbeddedShortcodeHandler.php b/src/Handler/EmbeddedShortcodeHandler.php index 8dec477..cfb6b97 100644 --- a/src/Handler/EmbeddedShortcodeHandler.php +++ b/src/Handler/EmbeddedShortcodeHandler.php @@ -33,17 +33,18 @@ class EmbeddedShortcodeHandler /** @var RequestStack */ private $requestStack; - /** - * @param string $controllerName - * @param string $renderer - */ public function __construct( FragmentHandler $fragmentHandler, - $controllerName, - $renderer, + string $controllerName, + string $renderer, RequestStack $requestStack, - ?LoggerInterface $logger = null + LoggerInterface $logger = null ) { + $callableFragments = explode('::', $controllerName); + if (!is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) { + throw new \InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); + } + $this->fragmentHandler = $fragmentHandler; $this->controllerName = $controllerName; $this->renderer = $renderer; diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index fa5977e..c727559 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -6,6 +6,9 @@ use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; +use Symfony\Component\HttpKernel\Fragment\FragmentHandler; +use Webfactory\ShortcodeBundle\Controller\GuideController; +use Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler; use Webfactory\ShortcodeBundle\Test\EndToEndTestHelper; /** @@ -37,7 +40,7 @@ public function expand_shortcodes_registered_in_different_ways(string $shortcode self::assertSame('test foo=bar', $this->processShortcodes("[$shortcodeName foo=bar]")); } - public static function provideShortcodeNames(): Generator + public function provideShortcodeNames(): Generator { yield 'Inline shortcode defined in bundle config' => ['test-config-inline']; yield 'ESI-based shortcode defined in bundle config' => ['test-config-esi']; @@ -58,13 +61,48 @@ public function processing_with_esi_fragments(string $shortcodeName): void self::assertStringContainsString('processShortcodes("[$shortcodeName foo=bar]", $request)); } - public static function provideEsiShortcodes(): Generator + public function provideEsiShortcodes(): Generator { yield 'ESI-based shortcode defined in bundle configuration' => ['test-config-esi']; yield 'ESI-based shortcode defined in service configuration' => ['test-service-esi']; } - private function processShortcodes(string $content, ?Request $request = null): string + /** + * @test + */ + public function validate_valid_controller_names(): void + { + $this->expectNotToPerformAssertions(); + + new EmbeddedShortcodeHandler( + $this->createMock(FragmentHandler::class), + GuideController::class.'::detailAction', + 'inline', + $this->createMock(RequestStack::class) + ); + } + + /** + * @test + * + * @dataProvider provideControllerNames + */ + public function validate_invalid_controller_names(string $controllerName): void + { + $this->expectException(\InvalidArgumentException::class); + + new EmbeddedShortcodeHandler($this->createMock(FragmentHandler::class), $controllerName, 'inline', $this->createMock(RequestStack::class)); + } + + public function provideControllerNames(): Generator + { + yield 'Empty string' => ['']; + yield 'Not existing controller' => ['Foo/Bar/Not/Exist::method']; + yield 'Missing method name' => [GuideController::class]; + yield 'Not existing method' => [GuideController::class.'_notExistingMethod']; + } + + private function processShortcodes(string $content, Request $request = null): string { self::bootKernel(); From 277bddc32deefa4b367b95fa8c72c68319b51ba5 Mon Sep 17 00:00:00 2001 From: FabianSchmick Date: Mon, 14 Oct 2024 11:17:11 +0000 Subject: [PATCH 02/14] Fix CS with PHP-CS-Fixer --- src/Handler/EmbeddedShortcodeHandler.php | 7 ++++--- tests/Functional/EmbeddedShortcodeHandlerTest.php | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Handler/EmbeddedShortcodeHandler.php b/src/Handler/EmbeddedShortcodeHandler.php index cfb6b97..56179fc 100644 --- a/src/Handler/EmbeddedShortcodeHandler.php +++ b/src/Handler/EmbeddedShortcodeHandler.php @@ -2,6 +2,7 @@ namespace Webfactory\ShortcodeBundle\Handler; +use InvalidArgumentException; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Symfony\Component\HttpFoundation\RequestStack; @@ -38,11 +39,11 @@ public function __construct( string $controllerName, string $renderer, RequestStack $requestStack, - LoggerInterface $logger = null + ?LoggerInterface $logger = null ) { $callableFragments = explode('::', $controllerName); - if (!is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) { - throw new \InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); + if (!\is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) { + throw new InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); } $this->fragmentHandler = $fragmentHandler; diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index c727559..fe1d480 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -3,6 +3,7 @@ namespace Webfactory\ShortcodeBundle\Tests\Functional; use Generator; +use InvalidArgumentException; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -89,7 +90,7 @@ public function validate_valid_controller_names(): void */ public function validate_invalid_controller_names(string $controllerName): void { - $this->expectException(\InvalidArgumentException::class); + $this->expectException(InvalidArgumentException::class); new EmbeddedShortcodeHandler($this->createMock(FragmentHandler::class), $controllerName, 'inline', $this->createMock(RequestStack::class)); } @@ -102,7 +103,7 @@ public function provideControllerNames(): Generator yield 'Not existing method' => [GuideController::class.'_notExistingMethod']; } - private function processShortcodes(string $content, Request $request = null): string + private function processShortcodes(string $content, ?Request $request = null): string { self::bootKernel(); From 680eafa101bbd293841d8ddc316143a694a6ac7c Mon Sep 17 00:00:00 2001 From: Fabian Schmick Date: Mon, 14 Oct 2024 11:20:52 +0000 Subject: [PATCH 03/14] Fix merge issue --- tests/Functional/EmbeddedShortcodeHandlerTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index fe1d480..0325fa4 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -41,7 +41,7 @@ public function expand_shortcodes_registered_in_different_ways(string $shortcode self::assertSame('test foo=bar', $this->processShortcodes("[$shortcodeName foo=bar]")); } - public function provideShortcodeNames(): Generator + public static function provideShortcodeNames(): Generator { yield 'Inline shortcode defined in bundle config' => ['test-config-inline']; yield 'ESI-based shortcode defined in bundle config' => ['test-config-esi']; @@ -62,7 +62,7 @@ public function processing_with_esi_fragments(string $shortcodeName): void self::assertStringContainsString('processShortcodes("[$shortcodeName foo=bar]", $request)); } - public function provideEsiShortcodes(): Generator + public static function provideEsiShortcodes(): Generator { yield 'ESI-based shortcode defined in bundle configuration' => ['test-config-esi']; yield 'ESI-based shortcode defined in service configuration' => ['test-service-esi']; From ec8ad73e5ac3df5d62a98059197a00bbeeb15eef Mon Sep 17 00:00:00 2001 From: Fabian Schmick Date: Tue, 15 Oct 2024 07:33:57 +0000 Subject: [PATCH 04/14] Refactoring --- tests/Functional/EmbeddedShortcodeHandlerTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index 0325fa4..34a7d89 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -71,13 +71,13 @@ public static function provideEsiShortcodes(): Generator /** * @test */ - public function validate_valid_controller_names(): void + public function throws_no_exception_on_valid_controller_name(): void { $this->expectNotToPerformAssertions(); new EmbeddedShortcodeHandler( $this->createMock(FragmentHandler::class), - GuideController::class.'::detailAction', + ShortcodeTestController::class.'::test', 'inline', $this->createMock(RequestStack::class) ); @@ -88,7 +88,7 @@ public function validate_valid_controller_names(): void * * @dataProvider provideControllerNames */ - public function validate_invalid_controller_names(string $controllerName): void + public function throws_exception_on_invalid_controller_names(string $controllerName): void { $this->expectException(InvalidArgumentException::class); @@ -98,9 +98,9 @@ public function validate_invalid_controller_names(string $controllerName): void public function provideControllerNames(): Generator { yield 'Empty string' => ['']; - yield 'Not existing controller' => ['Foo/Bar/Not/Exist::method']; - yield 'Missing method name' => [GuideController::class]; - yield 'Not existing method' => [GuideController::class.'_notExistingMethod']; + yield 'Not existing controller' => ['Foo\Bar::baz']; + yield 'Missing method name' => [ShortcodeTestController::class]; + yield 'Not existing method' => [ShortcodeTestController::class.'_notExistingMethod']; } private function processShortcodes(string $content, ?Request $request = null): string From b66660027b749bfc0649120219bf36bc8ab7bece Mon Sep 17 00:00:00 2001 From: FabianSchmick Date: Tue, 15 Oct 2024 07:34:16 +0000 Subject: [PATCH 05/14] Fix CS with PHP-CS-Fixer --- tests/Functional/EmbeddedShortcodeHandlerTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index 34a7d89..758923d 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -8,7 +8,6 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpKernel\Fragment\FragmentHandler; -use Webfactory\ShortcodeBundle\Controller\GuideController; use Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler; use Webfactory\ShortcodeBundle\Test\EndToEndTestHelper; From a9c04f637278bbf88477ac47af94412e75f2ec51 Mon Sep 17 00:00:00 2001 From: Fabian Schmick Date: Tue, 15 Oct 2024 07:36:51 +0000 Subject: [PATCH 06/14] Add missing namespace --- tests/Functional/EmbeddedShortcodeHandlerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index 758923d..7c2c6cc 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -10,6 +10,7 @@ use Symfony\Component\HttpKernel\Fragment\FragmentHandler; use Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler; use Webfactory\ShortcodeBundle\Test\EndToEndTestHelper; +use Webfactory\ShortcodeBundle\Tests\Fixtures\Controller\ShortcodeTestController; /** * Test shortcode processing using EmbeddedShortcodeHandler and a fixture ShortodeTestController, From 8cbc736accbce16223789dc04f62a7d6e7f7ac50 Mon Sep 17 00:00:00 2001 From: Fabian Schmick Date: Tue, 15 Oct 2024 09:23:41 +0000 Subject: [PATCH 07/14] Remove test because this will be captered in throws_exception_on_invalid_controller_names --- tests/Fixtures/config/config.yml | 1 - tests/Functional/EmbeddedShortcodeHandlerTest.php | 2 +- tests/Functional/ShortcodeDefinitionTestHelperTest.php | 9 --------- 3 files changed, 1 insertion(+), 11 deletions(-) diff --git a/tests/Fixtures/config/config.yml b/tests/Fixtures/config/config.yml index 2f277fb..e092f58 100644 --- a/tests/Fixtures/config/config.yml +++ b/tests/Fixtures/config/config.yml @@ -18,7 +18,6 @@ webfactory_shortcode: controller: 'Webfactory\ShortcodeBundle\Tests\Fixtures\Controller\ShortcodeTestController::test' description: "Description for the 'test-shortcode-guide' shortcode" example: "test-shortcode-guide test=true" - test-config-invalid-controller: 'Foo\Bar::baz' services: Webfactory\ShortcodeBundle\Tests\Fixtures\Controller\: diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index 7c2c6cc..5f8bd30 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -95,7 +95,7 @@ public function throws_exception_on_invalid_controller_names(string $controllerN new EmbeddedShortcodeHandler($this->createMock(FragmentHandler::class), $controllerName, 'inline', $this->createMock(RequestStack::class)); } - public function provideControllerNames(): Generator + public static function provideControllerNames(): Generator { yield 'Empty string' => ['']; yield 'Not existing controller' => ['Foo\Bar::baz']; diff --git a/tests/Functional/ShortcodeDefinitionTestHelperTest.php b/tests/Functional/ShortcodeDefinitionTestHelperTest.php index 5b9fd63..0e2dd36 100644 --- a/tests/Functional/ShortcodeDefinitionTestHelperTest.php +++ b/tests/Functional/ShortcodeDefinitionTestHelperTest.php @@ -31,15 +31,6 @@ public function throws_exception_for_handlers_that_do_not_use_controllers(): voi $this->helper->resolveShortcodeController('placeholder'); // uses the \Thunder\Shortcode\Handler\PlaceholderHandler handler class directly } - /** - * @test - */ - public function throws_exception_for_shortcode_with_unresolvable_controller(): void - { - self::expectException(InvalidArgumentException::class); - $this->helper->resolveShortcodeController('test-config-invalid-controller'); - } - /** * @test */ From 3d62079fc8e1d56fc584392f226c155853f338c0 Mon Sep 17 00:00:00 2001 From: FabianSchmick Date: Tue, 15 Oct 2024 09:24:00 +0000 Subject: [PATCH 08/14] Fix CS with PHP-CS-Fixer --- tests/Functional/ShortcodeDefinitionTestHelperTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Functional/ShortcodeDefinitionTestHelperTest.php b/tests/Functional/ShortcodeDefinitionTestHelperTest.php index 0e2dd36..6401568 100644 --- a/tests/Functional/ShortcodeDefinitionTestHelperTest.php +++ b/tests/Functional/ShortcodeDefinitionTestHelperTest.php @@ -2,7 +2,6 @@ namespace Webfactory\ShortcodeBundle\Tests\Functional; -use InvalidArgumentException; use RuntimeException; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Thunder\Shortcode\Handler\PlaceholderHandler; From 6f1bc2ee0bd6f72813332cfc6ba31b8234adf05f Mon Sep 17 00:00:00 2001 From: Malte Wunsch Date: Wed, 30 Oct 2024 10:40:18 +0100 Subject: [PATCH 09/14] Gitignore newer phpunit cache directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 50ffed0..8e28ce8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ composer.lock vendor/ phpunit.xml +.phpunit.cache/ .phpunit.result.cache .php-cs-fixer.cache tests/Fixtures/cache/ From 23024c874159b8cf384931f10a3f12084df26224 Mon Sep 17 00:00:00 2001 From: Malte Wunsch Date: Wed, 30 Oct 2024 10:37:43 +0100 Subject: [PATCH 10/14] Test invokable controller can be used --- .../Controller/InvokableShortcodeTestController.php | 13 +++++++++++++ tests/Fixtures/config/config.yml | 1 + tests/Functional/EmbeddedShortcodeHandlerTest.php | 6 ++++++ 3 files changed, 20 insertions(+) create mode 100644 tests/Fixtures/Controller/InvokableShortcodeTestController.php diff --git a/tests/Fixtures/Controller/InvokableShortcodeTestController.php b/tests/Fixtures/Controller/InvokableShortcodeTestController.php new file mode 100644 index 0000000..8acbf0f --- /dev/null +++ b/tests/Fixtures/Controller/InvokableShortcodeTestController.php @@ -0,0 +1,13 @@ + ['test-service-esi']; } + /** @test */ + public function invokable_controller_can_be_used(): void + { + self::assertSame('invokable-controller-response', $this->processShortcodes('

[test-config-invokable]

')); + } + /** * @test */ From cf8eea22125364921dd7b2555d6c0e95b69c7cac Mon Sep 17 00:00:00 2001 From: Malte Wunsch Date: Wed, 30 Oct 2024 10:43:23 +0100 Subject: [PATCH 11/14] Remove redundant test --- tests/Functional/EmbeddedShortcodeHandlerTest.php | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index 746519d..763b5cf 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -74,21 +74,6 @@ public function invokable_controller_can_be_used(): void self::assertSame('invokable-controller-response', $this->processShortcodes('

[test-config-invokable]

')); } - /** - * @test - */ - public function throws_no_exception_on_valid_controller_name(): void - { - $this->expectNotToPerformAssertions(); - - new EmbeddedShortcodeHandler( - $this->createMock(FragmentHandler::class), - ShortcodeTestController::class.'::test', - 'inline', - $this->createMock(RequestStack::class) - ); - } - /** * @test * From f29494dea02967e021aaca059195dc1d22825b97 Mon Sep 17 00:00:00 2001 From: Malte Wunsch Date: Wed, 30 Oct 2024 11:08:07 +0100 Subject: [PATCH 12/14] Allow usage of invokable controllers --- src/Handler/EmbeddedShortcodeHandler.php | 23 +++++++++++++++---- .../EmbeddedShortcodeHandlerTest.php | 1 + 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Handler/EmbeddedShortcodeHandler.php b/src/Handler/EmbeddedShortcodeHandler.php index 56179fc..d42fbd2 100644 --- a/src/Handler/EmbeddedShortcodeHandler.php +++ b/src/Handler/EmbeddedShortcodeHandler.php @@ -41,10 +41,7 @@ public function __construct( RequestStack $requestStack, ?LoggerInterface $logger = null ) { - $callableFragments = explode('::', $controllerName); - if (!\is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) { - throw new InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); - } + $this->validateControllerName($controllerName); $this->fragmentHandler = $fragmentHandler; $this->controllerName = $controllerName; @@ -92,4 +89,22 @@ public function getControllerName(): string { return $this->controllerName; } + + private function validateControllerName(string $controllerName): void + { + if (class_exists($controllerName)) { + // Check with method_exists instead of is_callable, because is_callable would need an object instance to + // positively test an invokable classes + if (method_exists($controllerName, '__invoke')) { + return; + } + + throw new InvalidArgumentException('The configured controller "'.$controllerName.'" does not refer a method. Although a class "'.$controllerName.'" exists, but has no __invoke method.'); + } + + $callableFragments = explode('::', $controllerName); + if (!\is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) { + throw new InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); + } + } } diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index 763b5cf..b814d63 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -92,6 +92,7 @@ public static function provideControllerNames(): Generator yield 'Not existing controller' => ['Foo\Bar::baz']; yield 'Missing method name' => [ShortcodeTestController::class]; yield 'Not existing method' => [ShortcodeTestController::class.'_notExistingMethod']; + yield 'Missing class' => ['ThisClassDoesNotExist']; } private function processShortcodes(string $content, ?Request $request = null): string From 640c445fa3502b1756bd4c2e4d3aacba25f2c3ad Mon Sep 17 00:00:00 2001 From: Malte Wunsch Date: Wed, 30 Oct 2024 11:14:30 +0100 Subject: [PATCH 13/14] Validate controller references with scope resolution operator stricter --- src/Handler/EmbeddedShortcodeHandler.php | 2 +- tests/Functional/EmbeddedShortcodeHandlerTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Handler/EmbeddedShortcodeHandler.php b/src/Handler/EmbeddedShortcodeHandler.php index d42fbd2..4c1509e 100644 --- a/src/Handler/EmbeddedShortcodeHandler.php +++ b/src/Handler/EmbeddedShortcodeHandler.php @@ -103,7 +103,7 @@ private function validateControllerName(string $controllerName): void } $callableFragments = explode('::', $controllerName); - if (!\is_array($callableFragments) || !isset($callableFragments[1]) || !method_exists($callableFragments[0], $callableFragments[1])) { + if (!\is_array($callableFragments) || count($callableFragments) !== 2 || !method_exists($callableFragments[0], $callableFragments[1])) { throw new InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); } } diff --git a/tests/Functional/EmbeddedShortcodeHandlerTest.php b/tests/Functional/EmbeddedShortcodeHandlerTest.php index b814d63..23a7476 100644 --- a/tests/Functional/EmbeddedShortcodeHandlerTest.php +++ b/tests/Functional/EmbeddedShortcodeHandlerTest.php @@ -93,6 +93,7 @@ public static function provideControllerNames(): Generator yield 'Missing method name' => [ShortcodeTestController::class]; yield 'Not existing method' => [ShortcodeTestController::class.'_notExistingMethod']; yield 'Missing class' => ['ThisClassDoesNotExist']; + yield 'Valid reference followed by a second scope resolution operator' => [ShortcodeTestController::class.'::test::']; } private function processShortcodes(string $content, ?Request $request = null): string From 86309e3956d8743752ce47ad8fbdefa46aeaf612 Mon Sep 17 00:00:00 2001 From: MalteWunsch Date: Wed, 30 Oct 2024 10:18:38 +0000 Subject: [PATCH 14/14] Fix CS with PHP-CS-Fixer --- src/Handler/EmbeddedShortcodeHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Handler/EmbeddedShortcodeHandler.php b/src/Handler/EmbeddedShortcodeHandler.php index 4c1509e..0b6ca2f 100644 --- a/src/Handler/EmbeddedShortcodeHandler.php +++ b/src/Handler/EmbeddedShortcodeHandler.php @@ -103,7 +103,7 @@ private function validateControllerName(string $controllerName): void } $callableFragments = explode('::', $controllerName); - if (!\is_array($callableFragments) || count($callableFragments) !== 2 || !method_exists($callableFragments[0], $callableFragments[1])) { + if (!\is_array($callableFragments) || 2 !== \count($callableFragments) || !method_exists($callableFragments[0], $callableFragments[1])) { throw new InvalidArgumentException('The controller method: "'.$controllerName.'" does not exist.'); } }