From da9746c84818b178094952c270d36b6dfda61743 Mon Sep 17 00:00:00 2001 From: Korney Czukowski Date: Mon, 3 Feb 2020 07:56:29 +0100 Subject: [PATCH 1/5] Enable and fix unused test methods --- .../annotation/util/AnnotationUtilsTest.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java index e93a9be3cc0b..7f1f4f9e156d 100644 --- a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java +++ b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java @@ -91,28 +91,24 @@ public void testQualifiedExtractParamTypes() throws Exception { assertTrue(types.containsKey(new OffsetRange(59, 75))); } - public void extractJustSomeParamTypes_01() throws Exception { + public void testExtractJustSomeParamTypes_01() throws Exception { Set manyToOneRegexs = new HashSet(); manyToOneRegexs.add("targetEntity"); //NOI18N Map types = AnnotationUtils.extractTypesFromParameters("ManyToOne(targetEntity=\"Cart\", cascade={\"all\"}, fetch=\"EAGER\")", manyToOneRegexs); assertNotNull(types); - assertEquals(2, types.size()); - String type1 = types.get(new OffsetRange(0, 9)); - assertEquals("ManyToOne", type1); - String type2 = types.get(new OffsetRange(24, 28)); - assertEquals("Cart", type2); + assertEquals(1, types.size()); + String type1 = types.get(new OffsetRange(24, 28)); + assertEquals("Cart", type1); } - public void extractJustSomeParamTypes_02() throws Exception { + public void testExtractJustSomeParamTypes_02() throws Exception { Set manyToOneRegexs = new HashSet(); manyToOneRegexs.add("targetEntity"); //NOI18N Map types = AnnotationUtils.extractTypesFromParameters("ManyToOne(targetEntity=\"\\Foo\\Cart\", cascade={\"all\"}, fetch=\"EAGER\")", manyToOneRegexs); assertNotNull(types); - assertEquals(2, types.size()); - String type1 = types.get(new OffsetRange(0, 9)); - assertEquals("ManyToOne", type1); - String type2 = types.get(new OffsetRange(24, 33)); - assertEquals("\\Foo\\Cart", type2); + assertEquals(1, types.size()); + String type1 = types.get(new OffsetRange(24, 33)); + assertEquals("\\Foo\\Cart", type1); } public void testNotNullTypeAnnotation_01() throws Exception { From 9b217756a02da23bbfe544688dd4c5308dc524b6 Mon Sep 17 00:00:00 2001 From: Korney Czukowski Date: Mon, 3 Feb 2020 08:14:33 +0100 Subject: [PATCH 2/5] Parametrize tests to separate test logic and data --- .../annotation/util/AnnotationUtilsTest.java | 285 +++++++++++------- 1 file changed, 179 insertions(+), 106 deletions(-) diff --git a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java index 7f1f4f9e156d..d852d057e7a8 100644 --- a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java +++ b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java @@ -18,125 +18,198 @@ */ package org.netbeans.modules.php.api.annotation.util; +import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.netbeans.junit.NbTestCase; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; import org.netbeans.modules.csl.api.OffsetRange; /** * * @author Ondrej Brejla */ -public class AnnotationUtilsTest extends NbTestCase { +@RunWith(Enclosed.class) +public class AnnotationUtilsTest { private static final String ANNOTATION_NAME = "Annotation"; - public AnnotationUtilsTest(String name) { - super(name); - } - - public void testValidUseCase_01() throws Exception { - assertTrue(AnnotationUtils.isTypeAnnotation("\\Foo\\Bar\\Baz\\" + ANNOTATION_NAME, ANNOTATION_NAME)); - } - - public void testValidUseCase_02() throws Exception { - assertTrue(AnnotationUtils.isTypeAnnotation("Foo\\Bar\\Baz\\" + ANNOTATION_NAME, ANNOTATION_NAME)); - } - - public void testValidUseCase_03() throws Exception { - assertTrue(AnnotationUtils.isTypeAnnotation(ANNOTATION_NAME, ANNOTATION_NAME)); - } - - public void testValidUseCase_04() throws Exception { - assertTrue(AnnotationUtils.isTypeAnnotation(ANNOTATION_NAME.toLowerCase(), ANNOTATION_NAME)); - } - - public void testValidUseCase_05() throws Exception { - assertTrue(AnnotationUtils.isTypeAnnotation("Foo\\Bar\\Baz\\" + ANNOTATION_NAME.toLowerCase(), ANNOTATION_NAME)); - } - - public void testInvalidUseCase_01() throws Exception { - assertFalse(AnnotationUtils.isTypeAnnotation(ANNOTATION_NAME + "\\Foo\\Bar\\Baz\\", ANNOTATION_NAME)); - } - - public void testInvalidUseCase_02() throws Exception { - assertFalse(AnnotationUtils.isTypeAnnotation("\\Foo\\Bar" + ANNOTATION_NAME + "\\Baz\\", ANNOTATION_NAME)); - } - - public void testExtractParamTypes() throws Exception { - Set discriminatorMapRegexs = new HashSet(); - discriminatorMapRegexs.add(""); //NOI18N - Map types = AnnotationUtils.extractTypesFromParameters("DiscriminatorMap({\"person\" = \" Person \", \"employee\" = \" Employee \"})", discriminatorMapRegexs); - assertNotNull(types); - assertTrue(!types.isEmpty()); - assertEquals(2, types.size()); - assertTrue(types.containsValue("Person")); - assertTrue(types.containsValue("Employee")); - assertTrue(types.containsKey(new OffsetRange(31, 37))); - assertTrue(types.containsKey(new OffsetRange(56, 64))); - } - - public void testQualifiedExtractParamTypes() throws Exception { - Set discriminatorMapRegexs = new HashSet(); - discriminatorMapRegexs.add(""); //NOI18N - Map types = AnnotationUtils.extractTypesFromParameters("DiscriminatorMap({\"person\" = \" My\\Person \", \"employee\" = \" \\Full\\Q\\Employee \"})", discriminatorMapRegexs); - assertNotNull(types); - assertTrue(!types.isEmpty()); - assertEquals(2, types.size()); - assertTrue(types.containsValue("My\\Person")); - assertTrue(types.containsValue("\\Full\\Q\\Employee")); - assertTrue(types.containsKey(new OffsetRange(31, 40))); - assertTrue(types.containsKey(new OffsetRange(59, 75))); - } - - public void testExtractJustSomeParamTypes_01() throws Exception { - Set manyToOneRegexs = new HashSet(); - manyToOneRegexs.add("targetEntity"); //NOI18N - Map types = AnnotationUtils.extractTypesFromParameters("ManyToOne(targetEntity=\"Cart\", cascade={\"all\"}, fetch=\"EAGER\")", manyToOneRegexs); - assertNotNull(types); - assertEquals(1, types.size()); - String type1 = types.get(new OffsetRange(24, 28)); - assertEquals("Cart", type1); - } - - public void testExtractJustSomeParamTypes_02() throws Exception { - Set manyToOneRegexs = new HashSet(); - manyToOneRegexs.add("targetEntity"); //NOI18N - Map types = AnnotationUtils.extractTypesFromParameters("ManyToOne(targetEntity=\"\\Foo\\Cart\", cascade={\"all\"}, fetch=\"EAGER\")", manyToOneRegexs); - assertNotNull(types); - assertEquals(1, types.size()); - String type1 = types.get(new OffsetRange(24, 33)); - assertEquals("\\Foo\\Cart", type1); - } - - public void testNotNullTypeAnnotation_01() throws Exception { - try { - AnnotationUtils.isTypeAnnotation(null, ""); - fail(); - } catch (NullPointerException ex) {} - } - - public void testNotNullTypeAnnotation_02() throws Exception { - try { - AnnotationUtils.isTypeAnnotation("", null); - fail(); - } catch (NullPointerException ex) {} - } - - public void testNotNullExtracParamTypes() throws Exception { - try { - AnnotationUtils.extractTypesFromParameters(null, Collections.EMPTY_SET); - fail(); - } catch (NullPointerException ex) {} - } - - public void testNotNullExtracParamTypesRegexs() throws Exception { - try { - AnnotationUtils.extractTypesFromParameters("", null); - fail(); - } catch (NullPointerException ex) {} + @RunWith(Parameterized.class) + public static class IsTypeAnnotationValidTest { + + @Parameters(name = "{index}: {0} is a type annotation of {1}") + public static Collection data() { + return Arrays.asList(new Object[][] { + {"\\Foo\\Bar\\Baz\\" + ANNOTATION_NAME, ANNOTATION_NAME}, + {"Foo\\Bar\\Baz\\" + ANNOTATION_NAME, ANNOTATION_NAME}, + {ANNOTATION_NAME, ANNOTATION_NAME}, + {ANNOTATION_NAME.toLowerCase(), ANNOTATION_NAME}, + {"Foo\\Bar\\Baz\\" + ANNOTATION_NAME.toLowerCase(), ANNOTATION_NAME}, + }); + } + + @Parameter(0) + public String lineToCheck; + + @Parameter(1) + public String annotationName; + + @Test + public void test() throws Exception { + assertTrue(AnnotationUtils.isTypeAnnotation(lineToCheck, annotationName)); + } + } + + @RunWith(Parameterized.class) + public static class IsTypeAnnotationInvalidTest { + + @Parameters(name = "{index}: {0} is not a type annotation of {1}") + public static Collection data() { + return Arrays.asList(new Object[][] { + {ANNOTATION_NAME + "\\Foo\\Bar\\Baz\\", ANNOTATION_NAME}, + {"\\Foo\\Bar" + ANNOTATION_NAME + "\\Baz\\", ANNOTATION_NAME}, + }); + } + + @Parameter(0) + public String lineToCheck; + + @Parameter(1) + public String annotationName; + + @Test + public void test() throws Exception { + assertFalse(AnnotationUtils.isTypeAnnotation(lineToCheck, annotationName)); + } + } + + @RunWith(Parameterized.class) + public static class IsTypeAnnotationNotNullableTest { + + @Parameters(name = "{index}: invoking isTypeAnnotation with [{0}, {1}] throws NullPointerException") + public static Collection data() { + return Arrays.asList(new Object[][] { + {null, ""}, + {"", null}, + }); + } + + @Parameter(0) + public String lineToCheck; + + @Parameter(1) + public String annotationName; + + @Test + public void test() throws Exception { + try { + AnnotationUtils.isTypeAnnotation(lineToCheck, annotationName); + fail(); + } catch (NullPointerException ex) {} + } + } + + @RunWith(Parameterized.class) + public static class ExtractTypesFromParametersTest { + + @Parameters(name = "{index}: extracting types from {0}") + public static Collection data() { + return Arrays.asList(new Object[][] { + { + "DiscriminatorMap({\"person\" = \" Person \", \"employee\" = \" Employee \"})", + new HashSet() {{ + add(""); + }}, + new HashMap() {{ + put(new OffsetRange(31, 37), "Person"); + put(new OffsetRange(56, 64), "Employee"); + }}, + }, + { + "DiscriminatorMap({\"person\" = \" My\\Person \", \"employee\" = \" \\Full\\Q\\Employee \"})", + new HashSet() {{ + add(""); + }}, + new HashMap() {{ + put(new OffsetRange(31, 40), "My\\Person"); + put(new OffsetRange(59, 75), "\\Full\\Q\\Employee"); + }}, + }, + { + "ManyToOne(targetEntity=\"Cart\", cascade={\"all\"}, fetch=\"EAGER\")", + new HashSet() {{ + add("targetEntity"); + }}, + new HashMap() {{ + put(new OffsetRange(24, 28), "Cart"); + }}, + }, + { + "ManyToOne(targetEntity=\"\\Foo\\Cart\", cascade={\"all\"}, fetch=\"EAGER\")", + new HashSet() {{ + add("targetEntity"); + }}, + new HashMap() {{ + put(new OffsetRange(24, 33), "\\Foo\\Cart"); + }}, + }, + }); + } + + @Parameter(0) + public String line; + + @Parameter(1) + public Set parameterNameRegexs; + + @Parameter(2) + public Map expected; + + @Test + public void test() throws Exception { + Map actual = AnnotationUtils.extractTypesFromParameters(line, parameterNameRegexs); + assertNotNull(actual); + assertEquals(expected, actual); + } + } + + @RunWith(Parameterized.class) + public static class ExtractTypesFromParametersNotNullableTest { + + @Parameters(name = "{index}: invoking extractTypesFromParameters with [{0}, {1}] throws NullPointerException") + public static Collection data() { + return Arrays.asList(new Object[][] { + {null, Collections.EMPTY_SET}, + {"", null}, + }); + } + + @Parameter(0) + public String line; + + @Parameter(1) + public Set parameterNameRegexs; + + @Test + public void test() throws Exception { + try { + AnnotationUtils.extractTypesFromParameters(line, parameterNameRegexs); + fail(); + } catch (NullPointerException ex) {} + } } } From 9d2ff1a4d97bb17010f5247ec62f289c8820fc40 Mon Sep 17 00:00:00 2001 From: Korney Czukowski Date: Thu, 6 Feb 2020 07:12:37 +0100 Subject: [PATCH 3/5] Support for unquoted class names in PHP annotations --- .../api/annotation/util/AnnotationUtils.java | 2 +- .../annotation/util/AnnotationUtilsTest.java | 55 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java b/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java index 71966f53a704..846c82d3d8ff 100644 --- a/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java +++ b/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java @@ -35,7 +35,7 @@ */ public class AnnotationUtils { - private static final String PARAM_TYPE_PATTERN = "\\s*=\\s*\\\"\\s*([\\w\\\\]+)\\s*\\\""; //NOI18N + private static final String PARAM_TYPE_PATTERN = "\\s*=\\s*(\\\"?)\\s*([\\w\\\\]+)\\s*\\1"; //NOI18N private static final Pattern INLINE_TYPE_PATTERN = Pattern.compile("@([\\w\\\\]+)"); //NOI18N diff --git a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java index d852d057e7a8..65c4d3975ed3 100644 --- a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java +++ b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java @@ -138,6 +138,16 @@ public static Collection data() { put(new OffsetRange(56, 64), "Employee"); }}, }, + { + "DiscriminatorMap({\"person\" = Person, \"employee\" = Employee })", + new HashSet() {{ + add(""); + }}, + new HashMap() {{ + put(new OffsetRange(29, 35), "Person"); + put(new OffsetRange(50, 58), "Employee"); + }}, + }, { "DiscriminatorMap({\"person\" = \" My\\Person \", \"employee\" = \" \\Full\\Q\\Employee \"})", new HashSet() {{ @@ -148,6 +158,16 @@ public static Collection data() { put(new OffsetRange(59, 75), "\\Full\\Q\\Employee"); }}, }, + { + "DiscriminatorMap({person = My\\Person, employee=\\Full\\Q\\Employee})", + new HashSet() {{ + add(""); + }}, + new HashMap() {{ + put(new OffsetRange(27, 36), "My\\Person"); + put(new OffsetRange(47, 63), "\\Full\\Q\\Employee"); + }}, + }, { "ManyToOne(targetEntity=\"Cart\", cascade={\"all\"}, fetch=\"EAGER\")", new HashSet() {{ @@ -157,6 +177,15 @@ public static Collection data() { put(new OffsetRange(24, 28), "Cart"); }}, }, + { + "ManyToOne(targetEntity=Cart, cascade={\"all\"}, fetch=\"EAGER\")", + new HashSet() {{ + add("targetEntity"); + }}, + new HashMap() {{ + put(new OffsetRange(23, 27), "Cart"); + }}, + }, { "ManyToOne(targetEntity=\"\\Foo\\Cart\", cascade={\"all\"}, fetch=\"EAGER\")", new HashSet() {{ @@ -166,6 +195,32 @@ public static Collection data() { put(new OffsetRange(24, 33), "\\Foo\\Cart"); }}, }, + { + "ManyToOne(targetEntity = \\Foo\\Cart, cascade={\"all\"}, fetch=\"EAGER\")", + new HashSet() {{ + add("targetEntity"); + }}, + new HashMap() {{ + put(new OffsetRange(25, 34), "\\Foo\\Cart"); + }}, + }, + { + "@Enum(class=\"Visibility\")", + new HashSet() {{ + add("class"); + }}, + new HashMap() {{ + put(new OffsetRange(13, 23), "Visibility"); + }}, + }, + { + // If there's a leading quote, then there must be a trailing quote as well. The other way around would work though. + "@Enum(class=\"Visibility)", + new HashSet() {{ + add("class"); + }}, + new HashMap(), + }, }); } From 58730a5368aa6cf8760838b33752b41c13b7cd72 Mon Sep 17 00:00:00 2001 From: Korney Czukowski Date: Thu, 6 Feb 2020 07:23:20 +0100 Subject: [PATCH 4/5] Support for ::class pseudo constants in PHP annotations --- .../api/annotation/util/AnnotationUtils.java | 2 +- .../annotation/util/AnnotationUtilsTest.java | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java b/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java index 846c82d3d8ff..57350e1046ce 100644 --- a/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java +++ b/php/php.api.annotation/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtils.java @@ -35,7 +35,7 @@ */ public class AnnotationUtils { - private static final String PARAM_TYPE_PATTERN = "\\s*=\\s*(\\\"?)\\s*([\\w\\\\]+)\\s*\\1"; //NOI18N + private static final String PARAM_TYPE_PATTERN = "\\s*=\\s*(\\\"?)\\s*([\\w\\\\]+)(?:::class)?\\s*\\1"; //NOI18N private static final Pattern INLINE_TYPE_PATTERN = Pattern.compile("@([\\w\\\\]+)"); //NOI18N diff --git a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java index 65c4d3975ed3..b07228d5c418 100644 --- a/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java +++ b/php/php.api.annotation/test/unit/src/org/netbeans/modules/php/api/annotation/util/AnnotationUtilsTest.java @@ -148,6 +148,16 @@ public static Collection data() { put(new OffsetRange(50, 58), "Employee"); }}, }, + { + "DiscriminatorMap({\"person\" = Person::class, \"employee\" = \"Employee\" })", + new HashSet() {{ + add(""); + }}, + new HashMap() {{ + put(new OffsetRange(29, 35), "Person"); + put(new OffsetRange(58, 66), "Employee"); + }}, + }, { "DiscriminatorMap({\"person\" = \" My\\Person \", \"employee\" = \" \\Full\\Q\\Employee \"})", new HashSet() {{ @@ -195,6 +205,15 @@ public static Collection data() { put(new OffsetRange(24, 33), "\\Foo\\Cart"); }}, }, + { + "ManyToOne(targetEntity=\"\\Foo\\Cart::class \" , cascade={\"all\"}, fetch=\"EAGER\")", + new HashSet() {{ + add("targetEntity"); + }}, + new HashMap() {{ + put(new OffsetRange(24, 33), "\\Foo\\Cart"); + }}, + }, { "ManyToOne(targetEntity = \\Foo\\Cart, cascade={\"all\"}, fetch=\"EAGER\")", new HashSet() {{ @@ -213,6 +232,24 @@ public static Collection data() { put(new OffsetRange(13, 23), "Visibility"); }}, }, + { + "@Enum(class=\"Visibility::class\")", + new HashSet() {{ + add("class"); + }}, + new HashMap() {{ + put(new OffsetRange(13, 23), "Visibility"); + }}, + }, + { + "@Enum(class=Visibility::class)", + new HashSet() {{ + add("class"); + }}, + new HashMap() {{ + put(new OffsetRange(12, 22), "Visibility"); + }}, + }, { // If there's a leading quote, then there must be a trailing quote as well. The other way around would work though. "@Enum(class=\"Visibility)", From 2cfdd07bb8f8cb3521d956c2b7441373f3700cd3 Mon Sep 17 00:00:00 2001 From: Korney Czukowski Date: Mon, 17 Feb 2020 06:55:47 +0100 Subject: [PATCH 5/5] Add test cases to Doctrine2 module --- .../DiscriminatorMapLineParserTest.java | 15 +++++++++++ .../orm/parser/EntityLineParserTest.java | 13 ++++++++++ .../orm/parser/ManyToManyLineParserTest.java | 13 ++++++++++ .../orm/parser/ManyToOneLineParserTest.java | 13 ++++++++++ .../orm/parser/OneToManyLineParserTest.java | 13 ++++++++++ .../orm/parser/OneToOneLineParserTest.java | 26 +++++++++++++++++++ ...ne2CommonLineAnnotationLineParserTest.java | 14 ++++++++++ 7 files changed, 107 insertions(+) diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/DiscriminatorMapLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/DiscriminatorMapLineParserTest.java index b0c0030df92e..5c02d91ab1d0 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/DiscriminatorMapLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/DiscriminatorMapLineParserTest.java @@ -170,4 +170,19 @@ public void testValidUseCase_08() throws Exception { assertEquals("Employee", type3); } + public void testValidUseCase_09() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\discriminatormap({\"person\" = Person::class, \"employee\" = \"Employee::class\"}) \t"); + assertEquals("DiscriminatorMap", parsedLine.getName()); + assertEquals("({\"person\" = Person::class, \"employee\" = \"Employee::class\"})", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(3, types.size()); + String type1 = types.get(new OffsetRange(0, 25)); + assertEquals("\\Foo\\Bar\\discriminatormap", type1); + String type2 = types.get(new OffsetRange(38, 44)); + assertEquals("Person", type2); + String type3 = types.get(new OffsetRange(67, 75)); + assertEquals("Employee", type3); + } + } diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/EntityLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/EntityLineParserTest.java index cf88e9cacfab..a59f88453964 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/EntityLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/EntityLineParserTest.java @@ -162,4 +162,17 @@ public void testValidUseCase_08() throws Exception { assertEquals("MyProject\\UserRepository", type2); } + public void testValidUseCase_09() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\entity(repositoryClass=\"MyProject\\UserRepository::class\") \t"); + assertEquals("Entity", parsedLine.getName()); + assertEquals("(repositoryClass=\"MyProject\\UserRepository::class\")", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(0, 15)); + assertEquals("\\Foo\\Bar\\entity", type1); + String type2 = types.get(new OffsetRange(33, 57)); + assertEquals("MyProject\\UserRepository", type2); + } + } diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToManyLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToManyLineParserTest.java index 561b5655bca1..ad3fd67e3df0 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToManyLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToManyLineParserTest.java @@ -161,4 +161,17 @@ public void testValidUseCase_08() throws Exception { assertEquals("Group", type2); } + public void testValidUseCase_09() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\manytomany(targetEntity=\"\\Foo\\Bar\\Group::class\", inversedBy=\"features\") \t"); + assertEquals("ManyToMany", parsedLine.getName()); + assertEquals("(targetEntity=\"\\Foo\\Bar\\Group::class\", inversedBy=\"features\")", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(0, 19)); + assertEquals("\\Foo\\Bar\\manytomany", type1); + String type2 = types.get(new OffsetRange(34, 48)); + assertEquals("\\Foo\\Bar\\Group", type2); + } + } diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToOneLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToOneLineParserTest.java index c218631b22c0..c0a8d6205f10 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToOneLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/ManyToOneLineParserTest.java @@ -161,4 +161,17 @@ public void testValidUseCase_08() throws Exception { assertEquals("Cart", type2); } + public void testValidUseCase_09() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\manytoone(targetEntity=\"Cart::class\", cascade={\"all\"}, fetch=\"EAGER\") \t"); + assertEquals("ManyToOne", parsedLine.getName()); + assertEquals("(targetEntity=\"Cart::class\", cascade={\"all\"}, fetch=\"EAGER\")", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(0, 18)); + assertEquals("\\Foo\\Bar\\manytoone", type1); + String type2 = types.get(new OffsetRange(33, 37)); + assertEquals("Cart", type2); + } + } diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToManyLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToManyLineParserTest.java index 22889da2e2b6..7892e0224acb 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToManyLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToManyLineParserTest.java @@ -161,4 +161,17 @@ public void testValidUseCase_08() throws Exception { assertEquals("Phonenumber", type2); } + public void testValidUseCase_09() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\onetomany(targetEntity=\\Foo\\Bar\\Phonenumber::class, mappedBy=\"user\", cascade={\"persist\", \"remove\", \"merge\"}, orphanRemoval=true) \t"); + assertEquals("OneToMany", parsedLine.getName()); + assertEquals("(targetEntity=\\Foo\\Bar\\Phonenumber::class, mappedBy=\"user\", cascade={\"persist\", \"remove\", \"merge\"}, orphanRemoval=true)", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(0, 18)); + assertEquals("\\Foo\\Bar\\onetomany", type1); + String type2 = types.get(new OffsetRange(32, 52)); + assertEquals("\\Foo\\Bar\\Phonenumber", type2); + } + } diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToOneLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToOneLineParserTest.java index 0b4140770293..f974382fda03 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToOneLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/orm/parser/OneToOneLineParserTest.java @@ -161,4 +161,30 @@ public void testValidUseCase_08() throws Exception { assertEquals("Customer", type2); } + public void testValidUseCase_09() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\onetoone(targetEntity=\"Customer::class\") \t"); + assertEquals("OneToOne", parsedLine.getName()); + assertEquals("(targetEntity=\"Customer::class\")", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(0, 17)); + assertEquals("\\Foo\\Bar\\onetoone", type1); + String type2 = types.get(new OffsetRange(32, 40)); + assertEquals("Customer", type2); + } + + public void testValidUseCase_10() throws Exception { + AnnotationParsedLine parsedLine = parser.parse("\\Foo\\Bar\\onetoone(targetEntity=Customer::class) \t"); + assertEquals("OneToOne", parsedLine.getName()); + assertEquals("(targetEntity=Customer::class)", parsedLine.getDescription()); + Map types = parsedLine.getTypes(); + assertNotNull(types); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(0, 17)); + assertEquals("\\Foo\\Bar\\onetoone", type1); + String type2 = types.get(new OffsetRange(31, 39)); + assertEquals("Customer", type2); + } + } diff --git a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/parser/Doctrine2CommonLineAnnotationLineParserTest.java b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/parser/Doctrine2CommonLineAnnotationLineParserTest.java index cf32d5fc3b88..cdf9404874cd 100644 --- a/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/parser/Doctrine2CommonLineAnnotationLineParserTest.java +++ b/php/php.doctrine2/test/unit/src/org/netbeans/modules/php/doctrine2/annotations/parser/Doctrine2CommonLineAnnotationLineParserTest.java @@ -160,4 +160,18 @@ public void testWithTypedParam_03() throws Exception { assertEquals("Index", type2); } + public void testWithTypedParam_04() throws Exception { + AnnotationParsedLine parsedLine = parser.parse(" targetEntity=MyProject\\UserRepository::class, indexes={ @Index(keys={\"username\"=\"desc\"}, options={\"unique\"=true}) }, "); + assertNotNull(parsedLine); + assertEquals("", parsedLine.getName()); + assertEquals("targetEntity=MyProject\\UserRepository::class, indexes={ @Index(keys={\"username\"=\"desc\"}, options={\"unique\"=true}) },", parsedLine.getDescription()); + assertFalse(parsedLine.startsWithAnnotation()); + Map types = parsedLine.getTypes(); + assertEquals(2, types.size()); + String type1 = types.get(new OffsetRange(17, 41)); + assertEquals("MyProject\\UserRepository", type1); + String type2 = types.get(new OffsetRange(61, 66)); + assertEquals("Index", type2); + } + }