You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2020/11/20 13:13:31 UTC

[GitHub] [netbeans] KacerCZ commented on a change in pull request #2535: [NETBEANS-5027] PHP - improved display of array parameter

KacerCZ commented on a change in pull request #2535:
URL: https://github.com/apache/netbeans/pull/2535#discussion_r527681681



##########
File path: php/php.editor/test/unit/src/org/netbeans/modules/php/editor/CodeUtilsTest.java
##########
@@ -179,4 +183,43 @@ public void testCommonNamespacePrefixes11() {
         assertEquals(0, prefixes.size());
     }
 
+    public void testGetParamDefaultValueEmptyArray() {
+        List<ArrayElement> emptyArray = Collections.emptyList();
+        FormalParameter param = createFormalParameterWithDefaultArray(emptyArray);
+        assertEquals("[]", CodeUtils.getParamDefaultValue(param));
+    }
+
+    public void testGetParamDefaultValueArrayOneItem() {
+        Scalar value = new Scalar(1, 1, "'a'", Scalar.Type.STRING);
+        ArrayElement item = new ArrayElement(1, 1, null, value);
+        List<ArrayElement> array = Arrays.asList(item);
+        FormalParameter param = createFormalParameterWithDefaultArray(array);
+        assertEquals("['a']", CodeUtils.getParamDefaultValue(param));
+    }
+
+    public void testGetParamDefaultValueArrayTwoItems() {
+        Scalar value1 = new Scalar(1, 1, "'a'", Scalar.Type.STRING);
+        ArrayElement item1 = new ArrayElement(1, 1, null, value1);
+        Scalar value2 = new Scalar(1, 1, "'b'", Scalar.Type.STRING);
+        ArrayElement item2 = new ArrayElement(1, 1, null, value2);
+        List<ArrayElement> array = Arrays.asList(item1, item2);
+        FormalParameter param = createFormalParameterWithDefaultArray(array);
+        assertEquals("['a',...]", CodeUtils.getParamDefaultValue(param));
+    }
+
+    public void testGetParamDefaultValueArrayItemWithKey() {
+        Scalar key = new Scalar(1, 1, "3", Scalar.Type.INT);
+        Scalar value = new Scalar(1, 1, "'a'", Scalar.Type.STRING);
+        ArrayElement item = new ArrayElement(1, 1, key, value);
+        List<ArrayElement> array = Arrays.asList(item);
+        FormalParameter param = createFormalParameterWithDefaultArray(array);
+        assertEquals("[3 => 'a']", CodeUtils.getParamDefaultValue(param));
+    }
+
+    private FormalParameter createFormalParameterWithDefaultArray(List<ArrayElement> arrayContent) {
+        ArrayCreation defaultValue = new ArrayCreation(1, 1, arrayContent, ArrayCreation.Type.NEW);
+        FormalParameter param = new FormalParameter(1, 1, null, null, defaultValue);
+        return param;
+    }
+

Review comment:
       If I understand you correctly you mean this case?
   <code>
   function printDate(\DateTime $date = new \DateTime()) {}
   </code>
   
   PHP does not support object as default value.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists