@@ -17,75 +17,51 @@ public function __construct()
1717 $ this ->longOptions ['seed= ' ] = 'seedHandler ' ;
1818 $ this ->longOptions ['order= ' ] = 'orderHandler ' ;
1919 $ this ->seed = rand (0 , 9999 );
20+ $ this ->order = 'defined ' ;
2021 }
2122
2223 public static function main ($ exit = TRUE )
2324 {
2425 return parent ::main ($ exit );
2526 }
2627
27- protected function orderHandler ( $ order_parameter )
28+ private function setSeedToPrinter ( $ seed )
2829 {
29- if (!is_string ($ order_parameter )) {
30- $ this ->showError (
31- sprintf ('Could not use "%s" as order. ' , $ order_parameter )
32- );
33- }
34-
35- $ order_parts = explode (': ' , $ order_parameter , 2 );
36- if (count ($ order_parts ) < 2 ) {
37- $ this ->order = $ order_parts [0 ];
38- $ this ->arguments ['order ' ] = $ this ->order ;
39- if ($ this ->order !== 'defined ' ) {
40- $ this ->arguments ['seed ' ] = $ this ->seed ;
41- if (isset ($ this ->arguments ['printer ' ]) && $ this ->arguments ['printer ' ] instanceof ResultPrinter )
42- {
43- $ this ->arguments ['printer ' ]->setSeed ($ this ->seed );
44- }
45- }
46-
47- return ;
48- }
49-
50- list ($ order , $ seed ) = $ order_parts ;
51- if ($ order !== 'defined ' && is_int ($ seed )) {
52- $ this ->showError (
53- sprintf ('Could not use "%s" as order. ' , $ order_parameter )
54- );
55- }
56-
57- $ this ->order = $ order ;
58- $ this ->arguments ['order ' ] = $ this ->order ;
59- $ this ->seed = $ seed ;
60- $ this ->arguments ['seed ' ] = $ this ->seed ;
61-
6230 if (isset ($ this ->arguments ['printer ' ]) && $ this ->arguments ['printer ' ] instanceof ResultPrinter )
6331 {
64- $ this ->arguments ['printer ' ]->setSeed ($ this -> seed );
32+ $ this ->arguments ['printer ' ]->setSeed ($ seed );
6533 }
6634 }
6735
68- protected function seedHandler ($ seed )
36+ /**
37+ * Parses arguments to know if random order is desired, and if seed was chosen.
38+ *
39+ * @param string $order String from command line parameter.
40+ * @return array
41+ */
42+ private function getOrderAndSeed ($ order )
6943 {
70- if (! is_numeric ( $ seed )) {
71- $ this -> showError (
72- sprintf ( ' Could not use "%s" as seed. ' , $ seed )
73- ) ;
44+ @ list ( $ order , $ seed ) = explode ( ' : ' , $ order , 2 );
45+
46+ if ( empty ( $ seed )) {
47+ $ seed = $ this -> seed ;
7448 }
7549
76- if (isset ($ this ->arguments ['order ' ])) {
77- $ this ->showError (
78- sprintf ('You can \'t use the \'order \' and \'seed \' arguments together ' )
79- );
50+ if (!is_numeric ($ seed )) {
51+ $ this ->showError ("Could not use ' $ seed' as seed. " );
8052 }
8153
82- $ this -> seed = intval ( $ seed );
83- $ this -> arguments [ ' seed ' ] = $ this -> seed ;
54+ return array ( $ order , $ seed );
55+ }
8456
85- if (isset ($ this ->arguments ['printer ' ]) && $ this ->arguments ['printer ' ] instanceof ResultPrinter )
86- {
87- $ this ->arguments ['printer ' ]->setSeed ($ this ->seed );
88- }
57+ protected function orderHandler ($ order_parameter )
58+ {
59+ list ($ order , $ seed ) = $ this ->getOrderAndSeed ($ order_parameter );
60+ $ this ->order = $ order ;
61+ $ this ->arguments ['order ' ] = $ order ;
62+ $ this ->seed = $ seed ;
63+ $ this ->arguments ['seed ' ] = $ seed ;
64+ $ this ->setSeedToPrinter ($ this ->seed );
8965 }
9066
9167 protected function createRunner ()
@@ -99,7 +75,7 @@ public function showHelp()
9975
10076 print <<<EOT
10177
102- --seed < seed> Seed the randomizer with a specific seed .
78+ --order <rand[: seed] > Randomize the order of the tests. Optionally you can pass a seed to run a specific order .
10379
10480EOT ;
10581 }
0 commit comments