TS 73 PHP Code Completion

PHP Editor Test Specification for NetBeans 7.3

Author: Martin Kanak
Updates by: Milan Molda
Version: 1.0
Last Update: 25th April 2013
Introduction: This specification provides usecases for PHP editor in the NetBeans IDE
Comments: Note that code completion is always being developed and features changed. This TS contains basic code completion features that have to work. All other features will be/are covered by functional and unit tests as they are easily maintained and configured. List of covered topics by automated tests will be added to the list of TSs once the overview is complete.

Mac OS specific details: To find Options on MacOS, go to Netbeans menu -> Preferences

Contents


Test suite: Code Completion

Purpose: Check that code completion works properly in PHP code and HTML for PHP source and PHP web page.
Prerequisites: a PHP project is created in the Netbeans IDE.

  1. Create a PHP source file.
    1. In the main menu, choose File > New File...
    2. In the Categories list, select PHP. In the File Types list, choose PHP File. Click Next.
    3. Accept default values by pressing Finish button.
    • EXPECTED RESULT: A new PHP web page is created and opened in the editor.
  2. Verify automatic code completion invocation.
    1. In PHP source, type $.
    • EXPECTED RESULT: Code completion is invoked automatically - a list of available variables appears.
  3. Verify local variable code completion.
    1. Create a PHP function.
    2. Declare a variable in the function.
    3. Type several first symbols of the variable name and invoke code completion.
    • EXPECTED RESULT: Code completion appears and the variable name is among suggestions.
  4. Verify global variable code completion.
    1. Create a PHP function.
    2. Declare a global variable.
    3. Type several first symbols of the variable name and invoke code completion.
    • EXPECTED RESULT: Code completion appears and the variable name is among suggestions.
  5. Verify variable from included file code completion.
    1. Include an other PHP file into PHP source.
    2. Open that PHP source and create a global variable there.
    3. Create a PHP function in the first source.
    4. Inside that function, type several first symbols of the variable name and invoke code completion.
    5. Choose that variable in the list and press Enter.
    • EXPECTED RESULT: Code is completed properly. No require or include directive is auto-generated.
  6. Verify variable from required file code completion.
    1. Add an other PHP file into PHP source using the require directive.
    2. Open that PHP source and create a global variable there.
    3. Create a PHP function in the first source.
    4. Inside that function, type several first symbols of the variable name and invoke code completion.
    5. Choose that variable in the list and press Enter.
    • EXPECTED RESULT: Code is completed properly. No require or include directive is auto-generated.
  7. Verify code completion inside the identifier.
    1. Place the caret inside of existing PHP identifier.
    2. Invoke code completion.
    • EXPECTED RESULT: Code completion appears and the list of suggestions corresponds to the beginning of the identifier.
  8. Verify documentation hints for built-in identifiers.
    1. Invoke code completion for a whitespace.
    2. Select a built-in identifier in the list (like $GLOBALS, $_ENV)
    • EXPECTED RESULT: In the details code completion view, a description of the identifier appears.
  9. Verify documentation hints for keywords.
    1. Check #199406
    2. Invoke code completion for a whitespace.
    3. Select a keyword in the list (like extends, if).
    • EXPECTED RESULT: In the details code completion view, a description of the keyword appears.
  10. Verify keywords code completion.
    1. Type the beginning of a keyword in a situation appropriate for its usage.
    2. Invoke code completion.
    • EXPECTED RESULT: Code completion appears and the keyword is among suggestions.
  11. Verify code completion with a single option.
    1. Type the beginning of a identifier so that there is only one option for code completion.
    2. Invoke code completion.
    • EXPECTED RESULT: Identifier is instantly completed without any popup windows.
  12. Verify JavaDoc window.
    1. Create a PHP function.
    2. Add some JavaDoc to that function. Don't save the source.
    3. In some other place, type the beginning of that function name and invoke code completion.
    4. Select that function in the popup window.
    • EXPECTED RESULT: Just entered JavaDoc is shown in the JavaDoc window of code completion.
  13. Verify code completion after EXTENDS.
    1. Define Foo class.
    2. Type "class MyClass extends F".
    3. Invoke code completion.
    • EXPECTED RESULT: Code completion appears and Foo class is shown. No any other identifiers are shown.
  14. Verify code completion in // comments.
    1. Create // style comment .
    2. Invoke code completion at that line after //.
    • EXPECTED RESULT: Code completion doesn't appear. It shouldn't be available in comments.
  15. Verify code completion in /* */ comments.
    1. Create /* */ style comment .
    2. Invoke code completion inside of that comment.
    • EXPECTED RESULT: Code completion does appear.
  16. Verify code completion in /** */ comments.
    1. Create /** */ comment .
    2. Invoke code completion inside of that comment.
    • EXPECTED RESULT: Code completion shows a list of JavaDoc tags (like @abstract).
  17. Verify smart method code completion
    1. Copy the code below to php file
    2. Invoke code completion at place of "|" (first remove the "|" char from code)
    • EXPECTED RESULT: Code completion the bar method, when you confirm it following is inserted bar($string, $int, $float), so the parameters are filled in based on their types and type described in PhpDoc of function bar() .
class Foo{   
    /**
     *Some PhpDoc
     * @param string $s
     * @param int $i
     * @param float $f 
     */
    function bar($s, $i, $f){}
    
    function foobar(){
        $string ="";
        $int = 42;
        $float = 3.1456;
        $this->|       
    }
}
  1. Verify smart method code completion 2
    1. Edit the code from previous test case: declare variable $s in foobar()
    2. Invoke code completion at place of "|" (first remove the "|" char from code)
    • EXPECTED RESULT: Code completion offers bar($s, $int, $float), so the parameters are filled in similarly like in previous test case but now not only type is considered but also name of the variable to be used (so $s is used instead of $string).
...   
    function foobar(){
        $string ="";
        $s = "";
        $int = 42;
        $float = 3.1456;
        $this->|       
    }
}
  1. Verify smart try/catch code completion
    1. Use the code below
    2. Invoke code completion at place of "|" (first remove the "|" char from code)
    • EXPECTED RESULT: Code completion offers only classes inherited from Execption.
   try{
      new AppendIterator;
    }  catch (|)
    }


Test suite: Hints

  1. Identical Comparison Hint.
    1. In a php file, use the code below the main menu, choose File > New File...
    2. In the Categories list, select PHP. In the File Types list, choose PHP File. Click Next.
    3. Accept default values by pressing Finish button.
    4. add following code to the file

$a = "1";
$b = "1";
if ($a == $b) {
    
}
    1. Place cursor on the line if comparison
    • EXPECTED RESULT: Hint should appear suggesting to avoid == comparison.
  1. Immutable varible use.
    1. In a php file, use the code below the main menu, choose File > New File...
    2. In the Categories list, select PHP. In the File Types list, choose PHP File. Click Next.
    3. Accept default values by pressing Finish button.
    4. add following code to the file
$aa="saasa";
echo "A";
$aa="1212121";
    • EXPECTED RESULT: Hint with text starting with "Too many assignment(2)" should appear
  1. Ambiguous Comparison Hint
    1. In the main menu, choose File > New File...
    2. In the Categories list, select PHP. In the File Types list, choose PHP File. Click Next.
    3. Accept default values by pressing Finish button.
    4. Add code below to the file
    • EXPECTED RESULT: Hints should appear suggesting to avoid accidental assignment.
if ($a = $b) {
    
}

Test suite: Insert Code

Prerequisites: a PHP project is created in the Netbeans IDE.

  1. Verify context menu
    1. Create a new PHP file
    2. Go to Source|Insert code
    • EXPECTED RESULT: The item "Insert code" is present in the context menu.
  2. Verify Fluent Setters
    1. Create a new PHP file
    2. Paste following code to source
<?php
        class Foo{
            private $Bar;
            |
        }
?>
    1. Place cursor on "|" (first remove the "|" char from code)
    2. Ivoke "Insert Code" (Go to Source|Insert Code)
    3. Choose Setter...
    4. Then select options similar to the one on screenshot below
    5. File:Gen-methods-1.png
    6. Click OK
    • EXPECTED RESULT: $this is returned from a generated setter. (see image below)

      File:Gen-methods-2.png
  1. Verify Type Hints
    1. Create a new PHP file
    2. Paste following code to source
<?php
class Foo {
   /**
   * @var Bar 
   */
   private $bar;

   |
?>
    1. Place cursor on "|" (first remove the "|" char from code)
    2. Ivoke "Insert Code" (Go to Source|Insert Code)
    3. Choose Constructor...
    4. Then select all fields (Foo, Foo|bar) and click OK
    • EXPECTED RESULT: Code must be similar to the one on screenshot

      File:Gen-methods-3.png

Test suite: Text Expansion from Templates

  1. Verify Templates Creation
    1. Choose Tools -> Options -> Editor -> Code Templates
    2. Choose PHP Language
    3. Choose New
    4. Write ajaj into dialog
    5. Add expaned text for abbreviation jajaj
    6. Press OK
    7. Create New Empty Project
    8. Delete index.php content
    9. Add following to index.php
<?

?>
    1. Write ajaj and press tab
    • EXPECTED RESULT: ajaj will be expanded to jajaj
  1. Verify Templates Deletion
    1. Choose Tools -> Options -> Editor -> Code Templates
    2. Choose PHP Language
    3. Choose ajaj abbreviation
    4. Choose Delete
    5. Press OK
    6. Create New Empty Project
    7. Delete index.php content
    8. Add following to index.php
<?

?>
    1. Write ajaj and press tab
    • EXPECTED RESULT: ajaj will NOT be expanded to jajaj


Test suite: Improved code folding

  1. Check new code folding for if, else, elseif, do, while, for, foreach, switch, case, try and catch.
    1. check issue #210160
    2. Copy code below
    3. Try to fold, expand, fold all/expand all nodes using keyboard shortcuts and folding marks
    4. Fold some node and move cursor over it
    5. Preview window should be shown
    6. Double click on folded code
    • EXPECTED RESULT: Code is expanded after double click. All operations are working and succesful
class A {

    public function foo() {

        if (true) {
            try {

                while (true) {
                    switch ($r) {
                        case 'aaaa':
                            break;
                        default:
                            break;
                    }
                }
            } catch (Exception $e) {
                
            }
        } elseif (false) {
            
        } else {
            foreach ($array as $value) {
                
            }
            
            for ($index = 0; $index < count($array); $index++) {
                
            }
        }
    }

}

Testsuite: Coloring

  1. Coloring of HTML tags inside PHPDocs
    1. Create new php file
    2. paste following code
/**
 * <code>test</code>
 */
    • EXPECTED RESULT: Colors of html tags should be different than the rest of comment

Testsuite: Aliases

Prerequisites: a PHP project is created in the Netbeans IDE.

  1. Verify that aliases can be generated from first letters of namespaces (and then numbered)
    1. Go to Tools|Options|Editor|Formatting
    2. Select PHP language, then select Category: Uses
    3. Select "Generate Aliases from Capitals of Namespaces" and click OK
    4. Create a new PHP file
    5. Paste following code into source
<?php

namespace Foo\Bar;

class ClassName {
    
}

namespace Fom\Bom;

class ClassName {
    
}

namespace Baz\Bat;

class ClassName {
    
}

namespace Omg;
|
$a = new Foo\Bar\ClassName();
$b = new Fom\Bom\ClassName();
$c = new Baz\Bat\ClassName();

?>
    1. Place cursor on place of "|" (first remove the "|" char from code)
    2. Go to Source -> select "Fix Uses..." and click OK
    • EXPECTED RESULT: After code must be similar to the one on screenshot.

      File:Php_aliases.png

TestSuite: Parsers for Namespaced Annotations

  1. Verify Parser for Namespaced Annotations
    1. Create a new PHP file
    2. Insert following code into the source
namespace Foo\Bar;

class Entity {}

namespace Baz;

use Foo\Bar;

class ClassName {

    /**
     * @Bar\Enti|ty
     * 
     */
    function functionName() {
        
    }

}
    1. Place cursor on place of "|" (first remove the "|" char from code)
    • EXPECTED RESULT: There are no hints and "Etity" is highlighted as you can see on this image

      File:Namespaced-annotation-parsers.png

Testsuite: Apache Conf support

  1. Verify coloring of Apache Configuration file
    1. Create new Apache Configuration file by New File -> Categories: Other -> File Types: Apache Conf file
    2. paste following code
<Files .htaccess>
order allow,deny
deny from all
</Files>

# redirect from dashboard/ to dashboard/web/
RedirectMatch permanent ^/dashboard/$ /dashboard/web/

php_value docref_root 0
php_value docref_ext 0
    • EXPECTED RESULT: Coloring is similar to the one on screenshot and the file icon indicates filetype

File:Htac.png


  1. Change Coloring for Apache Configuration file
    1. Go to Tools|Options| Fonts & Colors | Syntax, selec Apache Conf file
    2. change some color option
    • EXPECTED RESULT: Colors are changed appropriately


Testsuite: Neon support

  1. Verify coloring of Neon file
    1. Create new Neon file by New File -> Categories: Other -> File Types: Neon File
    2. paste following code
common: Very
address:
    property: 42 value

foo: {bar:1, foobar:2}
production < common:
    • EXPECTED RESULT: Coloring is similar to the one on screenshot and the file icon indicates filetype

File:PHP_Neon.png

  1. Change Coloring for Neon file
    1. Go to Tools|Options| Fonts & Colors | Syntax, selec Neon file
    2. change some color option
    • EXPECTED RESULT: Colors are changed appropriately

Testsuite: Twig support

Prerequisites: a PHP project is created in the Netbeans IDE.
Check status of auto formatting issue #209026

  1. Create a Twig source file.
    1. Create new Twig file by New File -> Categories: PHP -> File Types: Twig HTML file. Click Next.
    2. Accept default values by pressing Finish button.
    • EXPECTED RESULT: A new Twig file is created and opened in the editor.
  2. Verify automatic code completion invocation.
    1. In Twig source, type {%
    • EXPECTED RESULT: Code completion is invoked automatically - a list of available Twig Tags/Filters/Functions/Tests/Operators appears.
  3. Verify documentation hints for Tags.
    1. In Twig source, type {% for invoke code completion.
    2. Select a tag in the list (like autoescape, if).
    • EXPECTED RESULT: In the details code completion view, a description of the tag appears.
  4. Verify documentation hints for Filters.
    1. In Twig source, type {% for invoke code completion.
    2. Select a filter in the list (like capitalize, date).
    • EXPECTED RESULT: In the details code completion view, a description of the filter appears.
  5. Verify documentation hints for Functions.
    1. In Twig source, type {% for invoke code completion.
    2. Select a function in the list (like attribute, cycle).
    • EXPECTED RESULT: In the details code completion view, a description of the function appears.
  6. Verify documentation hints for Tests.
    1. In Twig source, type {% for invoke code completion.
    2. Select a test in the list (like empty, even).
    • EXPECTED RESULT: In the details code completion view, a description of the test appears.
  7. Verify documentation hints for Operators.
    1. In Twig source, type {% for invoke code completion.
    2. Select a operator in the list (like and, is).
    • EXPECTED RESULT: In the details code completion view, a description of the operator appears.
  8. Verify coloring of Twig file
    1. Create new Twig file by New File -> Categories: PHP -> File Types: Twig HTML file
    2. paste following code
<!DOCTYPE html>
<html>
    <head>
        <title>My Webpage</title>
    </head>
    <body>
        <ul id="navigation">
        {% for item in navigation %}
            <li><a href="{{ item.href }}">{{ item.caption }}</a></li>
        {% endfor %}
        </ul>

        <h1>My Webpage</h1>
        {{ a_variable }}
    </body>
</html>
}
    • EXPECTED RESULT: Coloring is similar to the one on screenshot and the file icon indicates filetype File:PHP_Twig.png
  1. Change Coloring for Twig file
    1. Go to Tools|Options| Fonts & Colors | Syntax, selec Twig file
    2. change some color option
    • EXPECTED RESULT: Colors are changed appropriately
  2. Code folds
    1. Use the same code as above
    2. Make sure there folds for HTML and Twig elements
    3. Try to collapse/expand them using keyboard shortcuts, folding marks and double clicking on folded code
    • EXPECTED RESULT: All operations were OK
  3. Syntax validation
    1. Use the same code as above
    2. remove the line with "{% endfor %}"
    • EXPECTED RESULT: Error should be displayed with msg about unclosed for
  4. Verify Default Twig Templates
    1. Create new PHP project
    2. Create new Twig File
    3. Write following to the Twig File source {% ae and press TAB
    • EXPECTED RESULT: ae will be expanded to autoescape
  5. Verify Templates Creation
    1. Choose Tools -> Options -> Editor -> Code Templates
    2. Choose Twig Markup Language
    3. Choose New
    4. Write he into dialog
    5. Add expaned text for abbreviation helpMe
    6. Press OK
    7. Create New Empty Project
    8. Create New Twig File
    9. Write following to the Twig File source {% he and press TAB
    • EXPECTED RESULT: he will be expanded to helpMe
  6. Verify Templates Deletion
    1. Choose Tools -> Options -> Editor -> Code Templates
    2. Choose Twig Markup Language
    3. Choose he abbreviation
    4. Choose Delete
    5. Press OK
    6. Create New Empty Project
    7. Create New Twig File
    8. Write following to the Twig File source {% he and press TAB
    • EXPECTED RESULT: he will NOT be expanded
  7. Verify Interpolation Coloring
    1. Create new Twig File
    2. Paste following code
{{ "foo #{bar} baz" }}
{{ "foo #{1 + 2} baz" }}
    • EXPECTED RESULT: Coloring is similar to the one on screenshot.
    1. File:PHP_Twig2.png

Testsuite: PHP 5.3 Support

  1. Verify Error Highlighting and Code Completion of PHP5.3 if PHP5.2 is Used
    1. Verify that PHP5.2 is set as PHP version in Project Properties -> Sources
    2. write name and invoke code completion
    • EXPECTED RESULT: namespace keyword is offered
    1. press enter/accept offered keyword
    2. complete keyword to namespace A;
    • EXPECTED RESULT: namespace keyword is underlined by red color and red bullet with exclamation mark appears on left side of editor window.
    1. change Project Properties -> Sources -> PHP Version to PHP 5.3
    • EXPECTED RESULT: error indication disappears

Testsuite: PHP 5.4 Support

  1. Array Dereferencing
    1. Create new php class (copy code below)
    2. Invoke code completion at place of "|"
    • EXPECTED RESULT: Variable $var and method getArray() are offered
class Foo {
    
    public $var;
    /**
     * 
     * @return Foo[]
     */
    public function getArray(){
        return array(new Foo());
    }
}
$bar = new Foo();
$bar->getArray()[0]->|
?>
  1. Anonymous object variable
    1. Create new php class (copy code below)
    2. Invoke code completion at place of "|"
    • EXPECTED RESULT: Variables $var and $var2 are offered
class Foo {
    
    public $var;
    public $var2;
}
(new Foo())->|
  1. Binary notation for integers
    1. Create new php file
    2. Declare variable $foo
    3. Error should be displayed because of the '2' in the value
    4. Change the '2' to '1'
    • EXPECTED RESULT: No error is shown (except of possible warning about unused variable)
$foo =0b002;
  1. Class::{expr}()
    1. Create new php class (copy code below)
    • EXPECTED RESULT: No error is shown
class Foo {
    public static function bar(){
        echo "FooBar";
    }
}
Foo::{'bar'}();
  1. Callable
    1. Create new php function (copy code below)
    2. Invoke code completion at the place of "|"
    • EXPECTED RESULT: Item callable is offered by code completion
public static function bar(ca|){
        echo "FooBar";
    }
  1. Short Array Syntax
    1. Create new php file
    2. declare array using short syntax
    3. No error should be shown
    4. On a new line type '$' and invoke code completion
    • EXPECTED RESULT: Variable $a is among offered items and its type is array
$a = [1, 2, 3, 4];
$a = ['one' => 1, 'two' => 2, 'three' => 3, 'four' => 4];
  1. Traits
    1. Create php file
    2. Paste following code
<?php
   trait Test{
          
   }
        
   class Foo{
      use |
   }
?>
    1. Invoke code completion at the place of "|"
    • EXPECTED RESULT: Test trait is offered
  1. Traits2
    1. Create php file
    2. Paste following code
  <?php
        trait Test{
            public function testfunc(){}
        }
        
        class Foo{
            use Test;           
            function baz(){
                $this->|
            }
        }
        ?>
    1. Invoke code completion at the place of "|"
    • EXPECTED RESULT: baz() and testfunc() are offered
  1. PHP 5.4 Warnings
    1. Create new php file (make sure PHP Version in project Properties is set to 5.4)
    2. Paste somewhere the code below
    3. No error should be shown
    4. Change PHP version to 5.3
    • EXPECTED RESULT: Error should be shown saying that the code is not compatible with given project PHP version
class Foo {
    public static function bar() {
        echo "FooBar";
    }
}
Foo::{'bar'}();

Testsuite: Miscellanous

  1. Fix missing uses
    1. Create new php file (called index.php)
    2. Create new php class to new php file (Aa.php) with following code:
namespace testA;

class Aa {
    public static function funcAa(){}
}
    1. Repeat the same, create new php file (Bb.php):
namespace testB;
class Bb {
    public static function funcBb(){}
}
    1. switch to index.php and paste following code
use testB\Bb;
require_once 'Aa.php';
require_once 'Bb.php';

Aa::funcAa();
    1. Press Ctrl+Shift+I (or right click and Fix Uses)
    • EXPECTED RESULT: Dialog offering namespace testA is displayed, check that removing unused uses is checked. As a result, new use for testA is added and unused for testB is removed
  1. Fix unused uses hint
    1. Use all files from previous case
    2. change index.php to look like this:
use testB\Bb;
require_once 'Aa.php';
require_once 'Bb.php';
    • EXPECTED RESULT: Hint is shown next to the line with use offering to remove unused use. Confirm this action and the use should be removed

Test suite: Annotations

  1. Create custom annotation
    1. Go to Tools | Options | PHP | Annotations and press Add
    2. Custom Annotation dialog is opened, just confirm default values and hit OK
    3. close Options dialog
    4. Copy this code to php file:
/**
 *@s
 */
function functionName($a, $param) {
    return 12;
}
    1. Invoke CC after the @s
    2. @sample should be offered with help description, select it and press Enter
    3. template for @sample annotation should be inserted
    4. Go to Options|...|Annotations again, make sure that "For" scope says that @sample is for functions only
    5. Edit the annotation @sample and change scope to Class/Interface (only)
    6. Used the code above again and invoke code completion
    7. @sample should not be listed
    8. Go to Options|...|Annotations and remove annotation
    9. Repeat the completion with function above and make sure that @sample is not offered
    • EXPECTED RESULT: All operations went well
  1. Framework specific annotations
    1. Create project with following frameworks: Symfony2, Doctrine2 (both ORM and ODM), ApiGen and PHPUnit
    2. Create new php class and invoke code completion on line the above "@author" for "@"
/**
 * Description of FooClass
 * @
 * @author tester
 */
    • EXPECTED RESULT: Invoke code completion after '@' and check that there are items from 'origin' (text in the right side of code completion): PHPUnit, ApiGen, Symfony2 Extra, Doctrine2 ORM
Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo