SonarQube PHP
  1. SonarQube PHP
  2. SONARPHP-106

Support test-directory based PHPUnit tests when 'AllTests.php' is not defined.

    Details

    • Type: New Feature New Feature
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.3
    • Fix Version/s: 0.4
    • Component/s: None
    • Labels:
      None
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      Description

      When following the initial statement on how to organize PHPUnit tests (taken from: http://www.phpunit.de/manual/current/en/organizing-tests.html), then the file system is the primary option to create a test suite, simply by placing all tests inside a test folder (much like in Java projects)

      This makes testing easier and less error prone than having to specify the tests manually inside a separate PHP file. ... in the end it may also increase the acceptance rate within development

      (The PHP file is still important for complex projects)


      Attached is a patch that adds support for folder based PHPUnit tests simply by verifying whether a single test folder exists and no main class is present.
      If so the test folder is run instead of the AllTests.php file.

      Effectively PHPUnit tests can now be organized as if it were a maven project, without requiring any test suite classes.
      (Proper setup of sourceDirectory and testSourceDirectory inside the POM is still required as it was before)

        Issue Links

          Activity

          Hide
          Akram Ben Aissi added a comment -

          Since Sonar PHP Plugin 0.3, phpunit.xml and phpunit.xml.dist file are also supported as bootstrap for test cases.

          Show
          Akram Ben Aissi added a comment - Since Sonar PHP Plugin 0.3, phpunit.xml and phpunit.xml.dist file are also supported as bootstrap for test cases.
          Hide
          Akram Ben Aissi added a comment -

          The provided patch is not valid anymore.
          If no test file is provided or found, phpunit is launched with no argument in order to search phpunit.xml or phpunit.xml.dist which a file descriptor for unit tests. This is a standard behaviour for phpunit.

          If possible, I will have a look at integrating this patch anyway.

          Show
          Akram Ben Aissi added a comment - The provided patch is not valid anymore. If no test file is provided or found, phpunit is launched with no argument in order to search phpunit.xml or phpunit.xml.dist which a file descriptor for unit tests. This is a standard behaviour for phpunit. If possible, I will have a look at integrating this patch anyway.
          Hide
          Juergen Kellerer added a comment -

          I guess with the new codebase you would still call phpunit like "phpunit Tests" where the argument is the folder containing the test classes or the XML file describing them, correct?

          If this is the case, then the patch is no longer needed as phpunit will simply run all PHP files in the folder if no XML file is found.

          Show
          Juergen Kellerer added a comment - I guess with the new codebase you would still call phpunit like "phpunit Tests" where the argument is the folder containing the test classes or the XML file describing them, correct? If this is the case, then the patch is no longer needed as phpunit will simply run all PHP files in the folder if no XML file is found.
          Hide
          Akram Ben Aissi added a comment -

          After deeper investigation and discussion, the implementation will be completed.

          To maintain compatibility and to support best practices for unit tests descriptors, the default behaviour will remain using phpunit.xml or phpunit.dist.xml if present. If these files does not exist, test directories will be passed.

          Two options will be added:
          1- first option to ignore phpunit.xml file even if present
          2- second option to tell sonar php to use test directory as argument for phpunit true/false (default true).In case of multiple tests directories, a warning will be displayed. And maybe a specific implementation will be set up in this case.

          These options are available because you can also mix or exclude phpunit.xml and directory based configuration.

          Show
          Akram Ben Aissi added a comment - After deeper investigation and discussion, the implementation will be completed. To maintain compatibility and to support best practices for unit tests descriptors, the default behaviour will remain using phpunit.xml or phpunit.dist.xml if present. If these files does not exist, test directories will be passed. Two options will be added: 1- first option to ignore phpunit.xml file even if present 2- second option to tell sonar php to use test directory as argument for phpunit true/false (default true).In case of multiple tests directories, a warning will be displayed. And maybe a specific implementation will be set up in this case. These options are available because you can also mix or exclude phpunit.xml and directory based configuration.
          Hide
          Akram Ben Aissi added a comment -

          sonar.phpUnit.ignore.configuration: if true, phpunit will ignore any present phpunit.xml file for launching unit tests.
          if not set, or false, phpunit will use any existing phpunit.xml file in the running directory.

          sonar.phpUnit.analyze.test.directory: if true or if not set, sonar php will append test directory to phpunit. This will make phpunit look for test cases inside this directory. If several directories are defined as test directories, a phpunitRANDOM.xml file will be generetaded and passed to phpunit --configuration=. This generated file will contain all files inside the test directories.

          sonar.phpUnit.mainTestClass is still available. if no explicit phpunit.xml file was specified, and this option is present, it will be used. If this option is present, sonar.phpUnit.analyze.test.director is ignored.

          Show
          Akram Ben Aissi added a comment - sonar.phpUnit.ignore.configuration: if true, phpunit will ignore any present phpunit.xml file for launching unit tests. if not set, or false, phpunit will use any existing phpunit.xml file in the running directory. sonar.phpUnit.analyze.test.directory: if true or if not set, sonar php will append test directory to phpunit. This will make phpunit look for test cases inside this directory. If several directories are defined as test directories, a phpunitRANDOM.xml file will be generetaded and passed to phpunit --configuration=. This generated file will contain all files inside the test directories. sonar.phpUnit.mainTestClass is still available. if no explicit phpunit.xml file was specified, and this option is present, it will be used. If this option is present, sonar.phpUnit.analyze.test.director is ignored.

            People

            • Assignee:
              Akram Ben Aissi
              Reporter:
              Anonymous
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: