TS 74 PHP Code Completion

PHP Editor Test Specification for NetBeans 7.4

Author: Milan Molda
Original Author: Martin Kanak
Version: 1.0
Last Update: 23rd July 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 (|)
    }
  1. "Self", "static" and "this" in @return annotation
    1. Create a new PHP file and paste following code
    2.         class Foo { 
                  public $var; 
                  public $var2; 
                  
                  /** 
                   * @return this 
                   */ 
                  public static function getFoo() { 
                      
                  } 
              } 
              Foo::getFoo()->|
    3. Invoke code completion at | position
    • EXPECTED RESULT: var, var2 and getFoo() are offered. Same items are offered when changed @return this to @return static or @return self
  2. Deprecated elements support
    1. File:TS_74_PHP_Editor_Deprecated.png
    2. Create a new PHP file and paste folowing code
    3. class Foo { 
          /** @deprecated */ 
          public $bar; 
          public $var; 
      } 
      (new Foo())->|
    4. Invoke code completion at | position
    • EXPECTED RESULT: Variable bar is striked trough in both code completion and definition
  3. String Auto-Concatenation after Typed Break
    1. Create a new PHP file
    2. Create a new string variable, e.g. $var = "some text";
    3. Press enter to break line somewhere inside quotes.
    • EXPECTED RESULT: Strings are concatenated automatically


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) {
    
}
  1. Hint to detect depth of nested blocks
    1. Create a new PHP file
    2. Write a function with couple of nested blocks or copy code bellow
    3. function foobar() {
          while(true) {
              for(;;) {
                  for(;;) {
                      for(;;) {
                      }
                  }
              }
          }
      }
    • EXPECTED RESULT: Too many nested blocks hint is shown
  2. Unreachable statements hint
    1. Create a new PHP file
    2. Use all of these statements: return, throw, break, continue and add code after them.
    3. function name() {
          return 0;
          echo "unreachable";
      }
      
      function foo() {
          throw new Exception();
          echo "unreachable";
      }
      
      switch ($foo) {
          case 0:
              break;
              echo "unreachable";
      }
      
      for($i = 0; $i < 10; $i++) {
          $i *= 2;
          continue;
          echo "unreachable";
      }
    • EXPECTED RESULT: Unreachable statement hint is shown after return, throw, break, continue
  3. Hint to detect empty statements
    1. Create a new PHP file
    2. Insert some empty statements, like ; or { };
    • EXPECTED RESULT: Empty statement hint is shown
  4. Hint to detect direct use of superglobal arrays
    1. Create a new PHP file
    2. Use superglobal arrays $_COOKIE, $_ENV, $_GET, $_POST, $_SERVER directly
    • EXPECTED RESULT: Direct use of superglobals hint is shown
  5. Hint conditions should use brackets
    1. Create a new PHP file
    2. Use conditions without braces
    3. if(true)
          echo "something";
    • EXPECTED RESULT: Hint Conditions should use brackets is shown
  6. Hint to check whether current use of "@" is proper
    1. Create a new PHP file
    2. Paste following code
    3. @fopen();
      
      @file();
    • EXPECTED RESULT: Error Control Operator Misuse Hint is show on line with @file();. Error Control Operator Misuse Hint is not shown on line with @fopen();
  7. Too many lines Hint
    1. Create a new PHP file
    2. (Optionally) Open Tools->Options and select Editor. On Hints tab select PHP language. Under Too Many Lines edit Class Declaration, Function (Method) Declaration, Interface Declaration, Trait Declaration. Set Maximum lines allowed to some smaller number.
    3. Create Class, Function, Interface and Trait with more lines than defined in Hint settings. Default values are 100 lines for Class, Interface and Trait and 10 lines for Functions.
    • EXPECTED RESULT: Too many lines Hint is shown for Class, Interface, Trait and Function with more lines than allowed
  8. Hint to check the closing PHP delimiter at the end of file
    1. Create a new PHP file
    2. Add closing PHP delimiter ?> at end of file (if there is not)
    • EXPECTED RESULT: Unnecessary Closing Delimiter Hint is shown

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 generating static getters and setters
    1. Create a new PHP file
    2. Create a new class with some static variables
    3. From Source menu select Insert Code (or use Alt+Insert)
    4. Select Generate Getters and Setters. Check static variables and click OK.
    • EXPECTED RESULT: Static getters and setters for variables are created.

      File:Gen-static-getters-setters.png
  2. 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: Refactoring

Purpose: Check functioning of refactoring options offered for PHP projects
Preqequisites: New PHP project is created from NetBeans IDE

  1. Rename refactor a class method
    1. Create a class Foo with public methods bar($barStr) and baz.
    2. Add a method work to Foo, in which calls to bar and baz are made.
    3. Instantiate a new Foo object and add a call to bar() in index.php
    4. Go back to Foo.php, right click on method bar, and choose Refactor > Rename.
    5. In the dialog that appears enter netCat as "New name", and click Preview.
    6. Refactoring window appears showing diff of Foo.php and index.php before and after refactoring, finding 3 occurences. Click Do Refactoring.
    • EXPECTED RESULT: bar($barStr) is renamed to netCat($barStr). Foo::work() now calls netCat() instead of bar(). Method call in index.php is also renamed.
  2. Safely delete a class
    1. Use the project from the previous test case.
    2. Right click Foo.php and choose Delete.
    3. Tick "Safely delete (with usage search)" and click on Preview.
    • EXPECTED RESULT: NetBeans will give you a warning "References to elements in selected file were found. Remove all references to these elements in order to safely delete your file"
<?php

class FooBar {

    function bar($barStr) {
        
    }

    function baz() {
        
    }

    function work() {
        $this->bar(2);
        $this->baz();
    }

}

$bar = new FooBar();

$bar->work();
?>

  1. Rename refactoring improvement
    1. Create a new PHP Class file
    2. Right click on the class name and select Refactor -> Rename
    3. Type new class name and check "Rename Also File With Declaration" checkbox.
    4. Click on Preview button and than click on Do Refactoring button.
    • EXPECTED RESULT: Class name is renamed to new name. PHP file containing class is also renamed

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++) {
                
            }
        }
    }

}

Test suite: 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
  1. Different coloring of single/multi lines comments
    1. Create a new PHP file
    2. Write some single line (// ) and multi line (/* */ or /** */)comments
    3. From Tools menu select Options. Select Fonts and Colors and on Syntax tab select PHP Language.
    • EXPECTED RESULT: There is option to set (different) colors for Comments and Line Comments. Colors of single/multi line comments are changed properly in editor after applying changes.

      File:different-comments-coloring.png

Test suite: 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

Test Suite: 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

Test suite: INI files support

  1. Verify coloring of INI file
    1. Create new INI file by New File -> Categories: Other -> File Types: INI file
    2. paste following code
    3. ; this is an INI file
      [section]
      key = value
    • EXPECTED RESULT: Coloring is similar to the one on screenshot and the file icon indicates filetype.

      File:INI-coloring.png
  2. Toggle comment in INI file
    1. Create a new INI file
    2. Add some code into a file or copy code bellow
    3. [section]
      key = value
      hname = mm;
      sname = pp;
      otherkey = something;
    4. Put the caret on some line
    5. Select Source->Toggle Comment (or press Ctrl+Shift+C)
    • EXPECTED RESULT: Selected line is commented out. When you try toggle comment again, line is uncommented

Test suite: 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
  2. Toggle comment in Apache Conf file
    1. Create a new Apache Conf file
    2. Put some code into the file or copy the code bellow
    3. # disable directory listing
      Options -Indexes
      Options -Indexes
    4. Put the caret on a line which is not commented out
    5. Select Source->Toggle comment (or press Ctrl+Shift+C)
    • EXPECTED RESULT: The line is commented out. If you try toggle comment again, line is uncommented

Test suite: 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
  2. Toggle comment in Neon file
    1. Create a new Neon file
    2. Add some code into a file or copy code bellow
    3. common:
      	parameters:
      	php:
      		date.timezone: Europe/Prague
    4. Put the caret on some line
    5. Select Source->Toggle Comment (or press Ctrl+Shift+C)
    • EXPECTED RESULT: Selected line is commented out. When you try toggle comment again, line is uncommented
  3. Code completion for Types
    1. Create a new PHP Project, accept default values and click Next. On last page select Nette2 Framework
    2. In app/model folder create new PHP Class with name Foo
    3. <?php
      namespace MyNamespace\NeonTest;
      
      class Foo {
      }
      ?>
    4. Open config.neon file located in app/config/
    5. Under Services type 'class:' and invoke code completion
    • EXPECTED RESULT: Code completion with PHP Types appears and new class Foo is presented.

      File:TS_74_PHP_Neon_CC.png

Test suite: 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.

      File:PHP_Twig2.png
  1. Toggle comment in Twig file
    1. Create a new Twig HTML file
    2. Add some code or copy the code bellow
    3. {% if kenny.sick %}
          Kenny is sick!
      {% endif %}
    4. Place caret on some line and select Source->Toggle comment (or press Ctrl+Shift+C)
    • EXPECTED RESULT: Whole line is commented out. When pressed Ctrl+Shift+C again, line is uncommented
  2. Braces matching
    1. Create a new Twig HTML file
    2. Insert the code bellow
    3. {% block body %}
          {% if kenny.sick %}
                  {% block content_header_more %}
                      <p>kenny is sick!</p>
                  {% endblock %}
          {% endif %}
      {% endblock %}
    4. Put the caret on some of keywords to check braces matching
    • EXPECTED RESULT: When you put caret on if keyword, the corresponding endif is highlighted too. When you put caret on one of the block keywords, the corresponding endblock is highlighted too.

Test suite: 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
  2. Verify Error Highlighting and CC - continue
    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.
  3. Verify Error Highlighting and CC - continue 2
    1. change Project Properties -> Sources -> PHP Version to PHP 5.3
    • EXPECTED RESULT: error indication disappears

Test suite: 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'}();

Test suite: 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