Work around test provider running before setUp()
authorBryan Davis <bd808@wikimedia.org>
Thu, 13 Nov 2014 20:18:08 +0000 (13:18 -0700)
committerBryan Davis <bd808@wikimedia.org>
Thu, 13 Nov 2014 20:18:08 +0000 (13:18 -0700)
If the xhprof extension is not present we skip running the test, but
phpunit runs the test provider function before that check so we need to
guard against missing constants to avoid spurious warnings in the test
output.

Change-Id: I5541a062ff0c47ca8802315554b3f32dfd01dcd0

tests/phpunit/includes/libs/XhprofTest.php

index e0e68e0..cc81aba 100644 (file)
@@ -69,14 +69,23 @@ class XhprofTest extends PHPUnit_Framework_TestCase {
        }
 
        public function provideRawData() {
-               return array(
+               $tests = array(
                        array( 0, array( 'ct', 'wt' ) ),
-                       array( XHPROF_FLAGS_MEMORY, array( 'ct', 'wt', 'mu', 'pmu' ) ),
-                       array( XHPROF_FLAGS_CPU, array( 'ct', 'wt', 'cpu' ) ),
-                       array( XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU, array(
-                               'ct', 'wt', 'mu', 'pmu', 'cpu',
-                       ) ),
                );
+
+               if ( defined( 'XHPROF_FLAGS_CPU' ) && defined( 'XHPROF_FLAGS_CPU' ) ) {
+                       $tests[] = array( XHPROF_FLAGS_MEMORY, array(
+                               'ct', 'wt', 'mu', 'pmu',
+                       ) );
+                       $tests[] = array( XHPROF_FLAGS_CPU, array(
+                               'ct', 'wt', 'cpu',
+                       ) );
+                       $tests[] = array( XHPROF_FLAGS_MEMORY | XHPROF_FLAGS_CPU, array(
+                                       'ct', 'wt', 'mu', 'pmu', 'cpu',
+                               ) );
+               }
+
+               return $tests;
        }
 
        /**