Version 1
[yaffs-website] / vendor / drush / drush / tests / xhUnitTest.php
1 <?php
2
3 namespace Unish;
4
5 /**
6  * Unit tests for xh.drush.inc.
7  *
8  * @group base
9  */
10 class xhUnitCase extends UnitUnishTestCase {
11
12   /**
13    * Test various combinations of XHProf flag options.
14    *
15    * @dataProvider xhOptionProvider
16    */
17   public function testFlags($name, $options, $expected) {
18     drush_preflight();
19     foreach ($options as $option_name => $option_value) {
20       drush_set_option($option_name, $option_value);
21     }
22     $this->assertEquals($expected, xh_flags(), $name);
23   }
24
25   /**
26    * Provides drush XHProf options and the results we expect from xh_flags().
27    */
28   public function xhOptionProvider() {
29
30     if (!defined('XHPROF_FLAGS_NO_BUILTINS')) {
31       define('XHPROF_FLAGS_NO_BUILTINS', 1);
32       define('XHPROF_FLAGS_CPU', 2);
33       define('XHPROF_FLAGS_MEMORY', 3);
34     }
35
36     return array(
37       array(
38         'name' => 'No flag options provided (default)',
39         'options' => array(),
40         'expected' => 0,
41       ),
42       array(
43         'name' => 'Default flag options explicitly provided',
44         'options' => array(
45           'xh-profile-builtins' => TRUE,
46           'xh-profile-cpu' => FALSE,
47           'xh-profile-memory' => FALSE,
48         ),
49         'expected' => 0,
50       ),
51       array(
52         'name' => 'Disable profiling of built-ins',
53         'options' => array(
54           'xh-profile-builtins' => FALSE,
55           'xh-profile-cpu' => FALSE,
56           'xh-profile-memory' => FALSE,
57         ),
58         'expected' => XHPROF_FLAGS_NO_BUILTINS,
59       ),
60       array(
61         'name' => 'Enable profiling of CPU',
62         'options' => array(
63           'xh-profile-builtins' => TRUE,
64           'xh-profile-cpu' => TRUE,
65           'xh-profile-memory' => FALSE,
66         ),
67         'expected' => XHPROF_FLAGS_CPU,
68       ),
69       array(
70         'name' => 'Enable profiling of CPU, without builtins',
71         'options' => array(
72           'xh-profile-builtins' => FALSE,
73           'xh-profile-cpu' => TRUE,
74           'xh-profile-memory' => FALSE,
75         ),
76         'expected' => XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU,
77       ),
78       array(
79         'name' => 'Enable profiling of Memory',
80         'options' => array(
81           'xh-profile-builtins' => TRUE,
82           'xh-profile-cpu' => FALSE,
83           'xh-profile-memory' => TRUE,
84         ),
85         'expected' => XHPROF_FLAGS_MEMORY,
86       ),
87       array(
88         'name' => 'Enable profiling of Memory, without builtins',
89         'options' => array(
90           'xh-profile-builtins' => FALSE,
91           'xh-profile-cpu' => FALSE,
92           'xh-profile-memory' => TRUE,
93         ),
94         'expected' => XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_MEMORY,
95       ),
96       array(
97         'name' => 'Enable profiling of CPU & Memory',
98         'options' => array(
99           'xh-profile-builtins' => TRUE,
100           'xh-profile-cpu' => TRUE,
101           'xh-profile-memory' => TRUE,
102         ),
103         'expected' => XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY,
104       ),
105     );
106   }
107
108 }