Menu

#69 Add new own test case

Accepted
nobody
None
Medium
Defect
2014-06-25
2014-02-28
Anonymous
No

Originally created by: mithesh....@clariontechnologies.co.in

Can you please let us know how can we add a new own customized Test Case in PHP Check Style?

For example if I want to check that if the php opening and closing tags should be on the first column of the file then could this Test be accomplished?

Also there some other Test Cases that we want to add. So can you please let us know how can we add our own Test Cases?

Related

Wiki: History

Discussion

  • Anonymous

    Anonymous - 2014-02-28

    Originally posted by: tch...@hotmail.com

    Hello,

    Currently PHPcheckstyle is very simple and has a monolitic approach, to add new test cases you need to edit the code of the project (file "phpcheckstyle.php"). All the configuration is done in the config file and the rules are predefined.

    PHP_CodeSniffer is more modular, a bit more complicated to setup maybe, but you can code your new rules in separate files and hook them to the main setup.

    But it should not be too complicated to edit the project to add your new rule and they may benefit to others.

    I need to document the project, but the main idea is the following :
    * the "run" file launch the scan on all the files
    * the "tokenizer" file take a filel in entry and return an array of tokens.
    * the "phpcheckstyle" file is the main part of the project. It launch the tokenization of the files and then analyze the stream of tokens.
    ** The "processToken" method is a big SWITCH / CASE that depending on the token launch another "processXXX" method.
    ** The "processXXX" methods detect different cases and launch the "check" rules.
    ** The "checkXXX" methods do the checks of the rules that are activated.

    If you want to add things to this project, you're welcome and if you need help don't hesitate to ask.

    Status: Accepted

     
  • Anonymous

    Anonymous - 2014-03-02

    Originally posted by: mithesh....@clariontechnologies.co.in

    Hey thank you very much for your prompt response.

    Can ask you for a favour how can I add TOKEN - '<?php' and '?>' to check whether they both are at the first column of the page?

    I tried for that but was not able to achieve the required functionality. Can you help me please?

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: tch...@hotmail.com

    Hello, sorry for the delay.

    The tokens are T_OPEN_TAG and T_CLOSE_TAG.

    We already check for T_OPEN_TAG in ligne 619 of phpcheckstyle.php, we launch the check for short open tag.

    We should probably add a case just behind for T_CLOSE_ADD and refactor to add 2 methodes : processOpenTag and processCloseTag.

    To test if you are on the first column, there is a "_isLineStart" flag. But i'm not sure it is very well managed, we have to do some tests.

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: mithesh....@clariontechnologies.co.in

    Hey Thanks for your reply, its DONE.

    Thanks for your help dude. Actually I had done for closing tag - '?>' but for opening tag was little bit tough.

    But now its DONE. Thanks again for your help.
    By the way can we detect that does image and anchor tag has title and alt attribute?

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: tch...@hotmail.com

    Cool, no problem. I would be interested in your patch, i may integrated it in the next version.

    For validating HTML it's a different subject. HTML is viewed as text inside the PHP code and is not analysed.
    You may want to use the W3C validator on the generated web pages : http://validator.w3.org/

    Or something like a plugin : https://addons.mozilla.org/fr/firefox/addon/html-validator/

    There is also a validator for javascript : JSLint or JSHint : http://www.jshint.com/

    It could be a nice project to validate also the HTML with static analysis but it may be difficult.

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: mithesh....@clariontechnologies.co.in

    Yaa, its little bit difficult to validate HTML. Me trying for that but I am getting all the HTML tags with the same ID in the token.

    As far as code for opening and closing tags are concerned, for opening tag I did the same thing that you told me to check for "_isLineStart" and for closing tag I used existing method - '_checkNoWhiteSpaceBefore'.

    But this method only checks for WHITESPACE not for TABS so for that I checked that if the current token is - '?>' then check for ($this->tokenizer->checkPreviousToken(T_TAB).

    Can you help me with this - Does all project “includes” have fully qualified path?

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: tch...@hotmail.com

    I will try to have a look this afternoon if I can.

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: mithesh....@clariontechnologies.co.in

    OK, thanks.

    Please do let me know for following two test cases if you can :-

    1) Is project maintaining and using configuration path variable?

    2) Does all project “includes” have fully qualified path?

     
  • Anonymous

    Anonymous - 2014-03-04

    Originally posted by: tch...@hotmail.com

    I have added a new rule "phpTagsStartLine" and commited a new version on trunk. Can you have a look ?

    I'm not sure to understand your 2 tests cases. Do you have some examples ?

    1) It looks difficult, currently each file is analysed separately. We should analyse the whole project and keep track of global variables and so ...

    2) By fully qualified path, do you mean an absolute path ? Otherwise it depends on the "include_path" variable and it can have multiple root paths. So it's not easy to say if a path is correct or not.

     
  • Anonymous

    Anonymous - 2014-03-05

    Originally posted by: mithesh....@clariontechnologies.co.in

    Hey thank you very much for support.

    But I one thing I want to know how can I download your latest version. I just downloaded the top most zip file from - 'https://code.google.com/p/phpcheckstyle/downloads/list' but it didn't had any rule named - 'phpTagsStartLine'.

    Also regarding other two test cases I think you understood it.
    For first test case - '1) Is project maintaining and using configuration path variable?' - yes you are absolutely correct its very difficult and we need to keep track whole project at a time.

    As far as second test case is considered I have DONE it but its not perfect. Trying on that only.

    Anyways Thanks again for your support.

     
  • Anonymous

    Anonymous - 2014-03-05

    Originally posted by: tch...@hotmail.com

    Hello,

    You can access latest source directly here : https://phpcheckstyle.googlecode.com/svn/trunk/

    I wanted to add a new version but Google Code has stopped the upload access.
    You can download the latest version on SourceForge :
    http://sourceforge.net/projects/phpcheckstyle/files/PHPCheckStyle-0.12.5.zip/download

     
  • Anonymous

    Anonymous - 2014-06-24

    Originally posted by: mithesh....@clariontechnologies.co.in

    Hey,

    I am trying to install plugin of PHPcheckstyle in netbeans but its giving following error. Can you please help.

     
  • Anonymous

    Anonymous - 2014-06-24

    Originally posted by: mithesh....@clariontechnologies.co.in

    I am running phpchkstyle/index.php using XAMPP on localhost. By this how can we exclude files or directories that does not need to be tested by PHPcheckstyle.

     
  • Anonymous

    Anonymous - 2014-06-25

    Originally posted by: tch...@hotmail.com

    For the Netbeans problem it seems like a problem of dependency between some plugins. I don't maintain the plugin and I don't currently use Netbeans. I'll need to do somes tests.

    Maybe ask on the plugin page : https://sourceforge.net/projects/phpmdnb/

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.