diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/StringLiteralLanguageInjectorTest.java b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/StringLiteralLanguageInjectorTest.java new file mode 100644 index 000000000..183976221 --- /dev/null +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/StringLiteralLanguageInjectorTest.java @@ -0,0 +1,334 @@ +package fr.adrienbrault.idea.symfony2plugin.tests.lang; + +import com.intellij.testFramework.fixtures.InjectionTestFixture; +import com.jetbrains.php.lang.PhpFileType; +import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; +import org.jetbrains.annotations.NotNull; + +import static fr.adrienbrault.idea.symfony2plugin.lang.StringLiteralLanguageInjector.LANGUAGE_ID_EXPRESSION_LANGUAGE; + +public class StringLiteralLanguageInjectorTest extends SymfonyLightCodeInsightFixtureTestCase { + + private InjectionTestFixture injectionTestFixture; + + @Override + public void setUp() throws Exception { + super.setUp(); + myFixture.copyFileToProject("classes.php"); + injectionTestFixture = new InjectionTestFixture(myFixture); + } + + public String getTestDataPath() { + return "src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/fixtures"; + } + + public void testExpressionLanguageLanguageInjections() { + assertInjectedLangAtCaret( + "');", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "evaluate('');\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "compile('');\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "parse('');\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "condition('');\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "condition(condition: '');\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")]\n" + + " public function contact() {}\n" + + "}\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "')]\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")]\n" + + "class BlogPost {}\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + "class BlogPost {}\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + "class BlogPost {}\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")]\n" + + "class BlogPost {}\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")]\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")]\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "')]\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "')]\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact() {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "')]\n" + + " public function contact($post) {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "')]\n" + + " public function contact($post) {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\")\n" + + " */\n" + + " public function contact($post) {}\n" + + "}", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\");\n", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + + assertInjectedLangAtCaret( + "\");", + LANGUAGE_ID_EXPRESSION_LANGUAGE + ); + } + + private void assertInjectedLangAtCaret(@NotNull String configureByText, @NotNull String lang) { + myFixture.configureByText(PhpFileType.INSTANCE, configureByText); + injectionTestFixture.assertInjectedLangAtCaret(lang); + } +} diff --git a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/fixtures/classes.php b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/fixtures/classes.php index b113d0fa9..0efda91dd 100644 --- a/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/fixtures/classes.php +++ b/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/lang/fixtures/classes.php @@ -23,6 +23,143 @@ public static function fromJsonString() {} public function setJson() {} } } + +namespace Symfony\Component\DependencyInjection\Loader\Configurator { + function expr(string $expression) {} +} + +namespace Symfony\Component\ExpressionLanguage { + class ExpressionLanguage + { + public function compile($expression, array $names = []) {} + public function evaluate($expression, array $values = []) {} + public function parse($expression, array $names = []) {} + } + + class Expression + { + public function __construct(string $expression) {} + } +} + +namespace Symfony\Component\Routing\Annotation { + /** + * @Annotation + * @Target({"CLASS", "METHOD"}) + */ + #[\Attribute(\Attribute::IS_REPEATABLE | \Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] + class Route + { + public function __construct( + $data = [], + $path = null, + string $name = null, + array $requirements = [], + array $options = [], + array $defaults = [], + string $host = null, + array $methods = [], + array $schemes = [], + string $condition = null, + int $priority = null, + string $locale = null, + string $format = null, + bool $utf8 = null, + bool $stateless = null + ) {} + } +} + +namespace Symfony\Component\Routing\Loader\Configurator\Traits { + trait RouteTrait + { + public function condition(string $condition): {} + } +} + +namespace Symfony\Component\Routing\Loader\Configurator { + class RoutingConfigurator + { + use \Symfony\Component\Routing\Loader\Configurator\Traits\RouteTrait; + } +} + +namespace Symfony\Component\Validator\Constraints { + /** + * @Annotation + * @Target({"CLASS", "PROPERTY", "METHOD", "ANNOTATION"}) + */ + #[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] + class Expression + { + public function __construct( + $expression, + string $message = null, + array $values = null, + array $groups = null, + $payload = null, + array $options = [] + ) {} + } +} + +namespace Sensio\Bundle\FrameworkExtraBundle\Configuration { + /** + * @Annotation + */ + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] + class Cache + { + public function __construct( + array $values = [], + string $expires = null, + $maxage = null, + $smaxage = null, + bool $public = null, + bool $mustRevalidate = null, + array $vary = null, + string $lastModified = null, + string $etag = null, + $maxstale = null, + $staleWhileRevalidate = null, + $staleIfError = null + ) {} + } + + /** + * @Annotation + */ + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] + class Entity { + public function __construct( + $data = [], + string $expr = null, + string $class = null, + array $options = [], + bool $isOptional = false, + string $converter = null + ) {} + } + + /** + * @Annotation + */ + #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] + class Security + { + public function __construct( + $data = [], + string $message = null, + ?int $statusCode = null + ) {} + } + + /** + * @Annotation + */ + class Route extends \Symfony\Component\Routing\Annotation\Route {} +} + namespace Doctrine\ORM { class EntityManager { public function createQuery() {}