PHPUnit and Software Metrics

Sebastian Bergmann » 03 August 2007 » in New Features » 0 Comments

The upcoming 3.2 release of PHPUnit adds a couple of software metrics to the data that is stored in PHPUnit's test database. Below is a list of the metrics that are calculated and collected:The example below shows how you can access, for instance, the Cyclomatic Complexity information for all methods of a project.
sb@vmware trunk % sqlite3 /home/sb/ezcWorkflow.db
SQLite version 3.3.13
Enter ".help" for instructions
sqlite>   SELECT code_class.code_class_name   AS className,
sqlite>          code_method.code_method_name AS methodName,
sqlite>          code_method.code_method_ccn  AS complexity
sqlite>     FROM code_class, code_method
sqlite>    WHERE code_class.code_class_id = code_method.code_class_id
sqlite> ORDER BY complexity desc;

className                                 methodName                 complexity
----------------------------------------  -------------------------  ----------
ezcWorkflowDefinitionStorageXml           loadByName                 28
ezcWorkflowDefinitionStorageXml           save                       23
ezcWorkflowDefinitionStorageXml           conditionToXml             13
ezcWorkflowDefinitionStorageXml           xmlToCondition             13
ezcWorkflow                               __set                      12
ezcWorkflowDefinitionStorageXml           xmlToVariable              10
ezcWorkflowDatabaseDefinitionStorage      loadById                   9
ezcWorkflow                               __get                      8
ezcWorkflow                               __isset                    8
ezcWorkflowNodeArithmeticBase             execute                    8
ezcWorkflowExecution                      execute                    8
ezcWorkflowVisitorVisualization           visit                      8
ezcWorkflowDefinitionStorageXml           variableToXml              7
ezcWorkflowVisitorVerification            visit                      7
ezcWorkflowExecution                      resume                     7
ezcWorkflowUtil                           variableToString           6
ezcWorkflowNodeInput                      __construct                6
ezcWorkflowNodeConditionalBranch          execute                    6
ezcWorkflowNodeSubWorkflow                execute                    6
ezcWorkflowNode                           verify                     5
ezcWorkflowExecution                      __set                      5
ezcWorkflowDatabaseDefinitionStorage      save                       5
ezcWorkflowDatabaseExecution              loadExecution              5
ezcWorkflowVisitorNodeCollector           visit                      4
ezcWorkflowNodeInput                      execute                    4
ezcWorkflowNodeConditionalBranch          getCondition               4
ezcWorkflowNodeAction                     createObject               4
ezcWorkflowConditionXor                   evaluate                   4
ezcWorkflowExecution                      activate                   4
ezcWorkflowVisitorVisualization           __toString                 4
ezcWorkflowNode                           addInNode                  3
ezcWorkflowNode                           removeInNode               3
ezcWorkflowNode                           addOutNode                 3
ezcWorkflowNode                           removeOutNode              3
ezcWorkflowNode                           accept                     3
ezcWorkflowNode                           activate                   3
ezcWorkflowNode                           __toString                 3
ezcWorkflow                               __construct                3
ezcWorkflow                               isInteractive              3
ezcWorkflow                               hasSubWorkflows            3
ezcWorkflow                               addVariableHandler         3
ezcWorkflowUtil                           findObject                 3
ezcWorkflowNodeVariableUnset              __construct                3
ezcWorkflowNodeMerge                      prepareActivate            3
ezcWorkflowNodeAction                     __construct                3
ezcWorkflowNodeAction                     __toString                 3
ezcWorkflowConditionOr                    evaluate                   3
ezcWorkflowConditionBooleanSet            __construct                3
ezcWorkflowConditionBooleanSet            __toString                 3
ezcWorkflowConditionAnd                   evaluate                   3
ezcWorkflowNodeDiscriminator              activate                   3
ezcWorkflowExecution                      __get                      3
ezcWorkflowExecution                      __isset                    3
ezcWorkflowExecution                      start                      3
ezcWorkflowExecution                      suspend                    3
ezcWorkflowExecution                      getSubExecution            3
ezcWorkflowExecution                      saveToVariableHandlers     3
ezcWorkflowDatabaseDefinitionStorage      loadByName                 3
ezcWorkflowNode                           setActivationState         2
ezcWorkflow                               removeVariableHandler      2
ezcWorkflow                               setVariableHandlers        2
ezcWorkflowDefinitionStorageXml           getCurrentVersion          2
ezcWorkflowNodeVariableSet                __construct                2
ezcWorkflowNodeVariableSet                execute                    2
ezcWorkflowNodeVariableSet                __toString                 2
ezcWorkflowNodeVariableUnset              execute                    2
ezcWorkflowNodeBranch                     activateOutgoingNodes      2
ezcWorkflowNodeConditionalBranch          verify                     2
ezcWorkflowConditionVariable              evaluate                   2
ezcWorkflowNodeMerge                      doMerge                    2
ezcWorkflowNodeSynchronization            activate                   2
ezcWorkflowNodeAction                     execute                    2
ezcWorkflowNodeSimpleMerge                activate                   2
ezcWorkflowExecution                      addWaitingFor              2
ezcWorkflowExecution                      endThread                  2
ezcWorkflowExecution                      getNumSiblingThreads       2
ezcWorkflowExecution                      getParentThreadId          2
ezcWorkflowExecution                      addListener                2
ezcWorkflowExecution                      removeListener             2
ezcWorkflowExecution                      notifyListeners            2
ezcWorkflowExecution                      getVariable                2
ezcWorkflowExecution                      setVariables               2
ezcWorkflowExecution                      unsetVariable              2
ezcWorkflowExecution                      loadFromVariableHandlers   2
ezcWorkflowExecutionNonInteractive        __set                      2
ezcWorkflowInvalidInputException          __construct                2
ezcWorkflowInvalidInputException          __get                      2
ezcWorkflowInvalidInputException          __set                      2
ezcWorkflowInvalidInputException          __isset                    2
ezcWorkflowDatabaseUtil                   serialize                  2
ezcWorkflowDatabaseUtil                   unserialize                2
ezcWorkflowDatabaseDefinitionStorage      getCurrentVersionNumber    2
ezcWorkflowDatabaseExecution              __construct                2
ezcWorkflowDatabaseExecution              doSuspend                  2
ezcWorkflowNodeStart                      execute                    1
ezcWorkflowNode                           __construct                1
ezcWorkflowNode                           getId                      1
ezcWorkflowNode                           setId                      1
ezcWorkflowNode                           getInNodes                 1
ezcWorkflowNode                           getOutNodes                1
ezcWorkflowNode                           getConfiguration           1
ezcWorkflowNode                           getState                   1
ezcWorkflowNode                           setState                   1
ezcWorkflowNode                           getActivatedFrom           1
ezcWorkflowNode                           setActivatedFrom           1
ezcWorkflowNode                           getThreadId                1
ezcWorkflowNode                           setThreadId                1
ezcWorkflowNode                           activateNode               1
ezcWorkflowNode                           isExecutable               1
ezcWorkflowNode                           execute                    1
ezcWorkflowNode                           initState                  1
ezcWorkflowVisitor                        visit                      1
ezcWorkflow                               verify                     1
ezcWorkflow                               accept                     1
ezcWorkflow                               getVariableHandlers        1
ezcWorkflowNodeEnd                        execute                    1
ezcWorkflowVisitorNodeCollector           __construct                1
ezcWorkflowVisitorNodeCollector           getNodes                   1
ezcWorkflowDefinitionStorage              loadByName                 1
ezcWorkflowDefinitionStorage              save                       1
ezcWorkflowDefinitionStorageXml           __construct                1
ezcWorkflowDefinitionStorageXml           getFilename                1
ezcWorkflowDefinitionStorageXml           getFilesystemWorkflowNam   1
ezcWorkflowVisitable                      accept                     1
ezcWorkflowConditionIsString              evaluate                   1
ezcWorkflowConditionIsString              __toString                 1
ezcWorkflowCondition                      evaluate                   1
ezcWorkflowCondition                      __toString                 1
ezcWorkflowNodeVariableUnset              __toString                 1
ezcWorkflowNodeArithmeticBase             __construct                1
ezcWorkflowNodeArithmeticBase             doExecute                  1
ezcWorkflowNodeConditionalBranch          addConditionalOutNode      1
ezcWorkflowConditionComparison            __construct                1
ezcWorkflowConditionComparison            getValue                   1
ezcWorkflowConditionIsLessThan            evaluate                   1
ezcWorkflowConditionIsLessThan            __toString                 1
ezcWorkflowConditionVariable              __construct                1
ezcWorkflowConditionVariable              __toString                 1
ezcWorkflowConditionVariable              getVariableName            1
ezcWorkflowConditionVariable              getCondition               1
ezcWorkflowConditionIsEqual               evaluate                   1
ezcWorkflowConditionIsEqual               __toString                 1
ezcWorkflowNodeVariableIncrement          doExecute                  1
ezcWorkflowNodeVariableIncrement          __toString                 1
ezcWorkflowConditionIsGreaterThan         evaluate                   1
ezcWorkflowConditionIsGreaterThan         __toString                 1
ezcWorkflowNodeVariableDecrement          doExecute                  1
ezcWorkflowNodeVariableDecrement          __toString                 1
ezcWorkflowNodeVariableDiv                doExecute                  1
ezcWorkflowNodeVariableDiv                __toString                 1
ezcWorkflowNodeVariableMul                doExecute                  1
ezcWorkflowNodeVariableMul                __toString                 1
ezcWorkflowNodeVariableAdd                doExecute                  1
ezcWorkflowNodeVariableAdd                __toString                 1
ezcWorkflowNodeVariableSub                doExecute                  1
ezcWorkflowNodeVariableSub                __toString                 1
ezcWorkflowNodeMerge                      initState                  1
ezcWorkflowNodeParallelSplit              execute                    1
ezcWorkflowNodeSynchronization            execute                    1
ezcWorkflowConditionNot                   __construct                1
ezcWorkflowConditionNot                   evaluate                   1
ezcWorkflowConditionNot                   getCondition               1
ezcWorkflowConditionNot                   __toString                 1
ezcWorkflowConditionBooleanSet            getConditions              1
ezcWorkflowNodeDiscriminator              execute                    1
ezcWorkflowConditionIsTrue                evaluate                   1
ezcWorkflowConditionIsTrue                __toString                 1
ezcWorkflowConditionIsFalse               evaluate                   1
ezcWorkflowConditionIsFalse               __toString                 1
ezcWorkflowNodeSimpleMerge                execute                    1
ezcWorkflowNodeSubWorkflow                __construct                1
ezcWorkflowNodeSubWorkflow                __toString                 1
ezcWorkflowExecution                      end                        1
ezcWorkflowExecution                      getWaitingFor              1
ezcWorkflowExecution                      startThread                1
ezcWorkflowExecution                      getId                      1
ezcWorkflowExecution                      getVariables               1
ezcWorkflowExecution                      hasVariable                1
ezcWorkflowExecution                      setVariable                1
ezcWorkflowExecution                      hasEnded                   1
ezcWorkflowExecution                      isResumed                  1
ezcWorkflowExecution                      isSuspended                1
ezcWorkflowExecution                      doStart                    1
ezcWorkflowExecution                      doSuspend                  1
ezcWorkflowExecution                      doResume                   1
ezcWorkflowExecution                      doEnd                      1
ezcWorkflowExecution                      doGetSubExecution          1
ezcWorkflowConditionIsBool                evaluate                   1
ezcWorkflowConditionIsBool                __toString                 1
ezcWorkflowExecutionNonInteractive        doStart                    1
ezcWorkflowExecutionNonInteractive        doSuspend                  1
ezcWorkflowExecutionNonInteractive        doResume                   1
ezcWorkflowExecutionNonInteractive        doEnd                      1
ezcWorkflowExecutionNonInteractive        doGetSubExecution          1
ezcWorkflowExecutionListener              notify                     1
ezcWorkflowConditionIsAnything            evaluate                   1
ezcWorkflowConditionIsAnything            __toString                 1
ezcWorkflowConditionIsArray               evaluate                   1
ezcWorkflowConditionIsArray               __toString                 1
ezcWorkflowConditionIsFloat               evaluate                   1
ezcWorkflowConditionIsFloat               __toString                 1
ezcWorkflowConditionIsInteger             evaluate                   1
ezcWorkflowConditionIsInteger             __toString                 1
ezcWorkflowConditionIsObject              evaluate                   1
ezcWorkflowConditionIsObject              __toString                 1
ezcWorkflowConditionIsNotEqual            evaluate                   1
ezcWorkflowConditionIsNotEqual            __toString                 1
ezcWorkflowConditionIsEqualOrGreaterThan  evaluate                   1
ezcWorkflowConditionIsEqualOrGreaterThan  __toString                 1
ezcWorkflowConditionIsEqualOrLessThan     evaluate                   1
ezcWorkflowConditionIsEqualOrLessThan     __toString                 1
ezcWorkflowDatabaseDefinitionStorage      __construct                1
ezcWorkflowDatabaseExecution              doStart                    1
ezcWorkflowDatabaseExecution              doResume                   1
ezcWorkflowDatabaseExecution              doEnd                      1
ezcWorkflowDatabaseExecution              doGetSubExecution          1
ezcWorkflowDatabaseExecution              cleanupTable               1
ezcWorkflowEventLogListener               __construct                1
ezcWorkflowEventLogListener               notify                     1
Defined tags for this entry: , , , ,

Trackback specific URI for this entry

0 Comments to "PHPUnit and Software Metrics"

Display comments as (Linear | Threaded)
  1. No comments

6 Trackbacks to "PHPUnit and Software Metrics"

  1. Sebastian Bergmann 09/08/2007 at 19:59
    PMD, also known as Project Mess Detector, is a popular tool in the Java world that scans Java source code and looks for potential problems. It is well integrated with other tools such as Eclipse or CruiseControl, making the collected information available
  2. Manuel Pichler 27/10/2007 at 20:26
    I am using CruiseControl for some time now, to run all Unit Tests for a project continuous after each commit. Since Sebastian Bergmann started the development of PHPUnit 3.2 he added support for software metrics and PMD to PHPUnit, that give you further
  3. Sebastian Bergmann 28/10/2007 at 18:29
    I have just released a first release candidate for PHPUnit 3.2, the next major version of the xUnit testing framework for PHP. Highlights of this new release include software metrics, project mess detection, copy-and-paste detection, improvements to Se
  4. Sebastian Bergmann 12/11/2007 at 10:21
    I have just released a second release candidate for PHPUnit 3.2, the next major version of the xUnit testing framework for PHP. Highlights of this new release include software metrics, project mess detection, copy-and-paste detection, improvements to S
  5. Sebastian Bergmann 19/11/2007 at 12:06
    Sebastian Bergmann and his contributors are proud to announce the immediate availability of PHPUnit 3.2. This release is a major improvement to the popular open source testing solution for PHP applications. It includes new features and bug fixes. High
  6. Sebastian Bergmann 06/02/2008 at 19:26
    Manuel Pichler's recent blog entry on PHP_Depend propmpted me to write about my opinion on the future of software metrics and project mess detection in PHPUnit. When I started to work on these projects, there was no other place for me then to develop t

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.