File tree Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Expand file tree Collapse file tree 4 files changed +78
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ class Unit
14
14
private Command $ command ;
15
15
private bool $ quite ;
16
16
private ?string $ title ;
17
+ private array $ args = [];
17
18
private array $ units ;
18
19
private int $ index = 0 ;
19
20
private array $ error ;
@@ -24,10 +25,35 @@ public function __construct(bool $quite = false)
24
25
$ this ->quite = $ quite ;
25
26
}
26
27
28
+ /**
29
+ * Add title to the test (optional)
30
+ * @param string $title
31
+ * @return void
32
+ */
27
33
public function addTitle (string $ title ): void
28
34
{
29
35
$ this ->title = $ title ;
30
36
}
37
+
38
+ /**
39
+ * Pass arguments to the testing script (optional)
40
+ * @param array $args
41
+ * @return void
42
+ */
43
+ public function setArgs (array $ args ): void
44
+ {
45
+ $ this ->args = $ args ;
46
+ }
47
+
48
+ /**
49
+ * Get passed arguments in the testing script
50
+ * @return array
51
+ */
52
+ public function getArgs (): array
53
+ {
54
+ return $ this ->args ;
55
+ }
56
+
31
57
/**
32
58
* Add a test unit/group
33
59
* @param string $message
@@ -94,6 +120,7 @@ public function executeAll(string $directory): void
94
120
throw new Exception ("No files found matching the pattern \"" . static ::PATTERN . "\" in directory \"$ directory \" " );
95
121
} else {
96
122
foreach ($ files as $ file ) {
123
+ extract ($ this ->args , EXTR_PREFIX_SAME , "wddx " );
97
124
require_once ($ file );
98
125
}
99
126
}
Original file line number Diff line number Diff line change 22
22
"maplephp/validate" : " ^1.0" ,
23
23
"maplephp/prompts" : " ^1.0"
24
24
},
25
+ "replace" : {
26
+ "maplephp/dto" : " self.version" ,
27
+ "maplephp/http" : " self.version" ,
28
+ "maplephp/validate" : " self.version" ,
29
+ "maplephp/prompts" : " self.version"
30
+ },
25
31
"autoload" : {
26
32
"psr-4" : {
27
33
"MaplePHP\\ Unitary\\ " : " "
Original file line number Diff line number Diff line change 17
17
18
18
// If you add true to Unit it will run in quite mode
19
19
// and only report if it finds any errors!
20
- $ unit = new Unit (true );
20
+ $ unit = new Unit ();
21
21
22
22
// Add a title to your tests (not required)
23
23
$ unit ->addTitle ("Testing MaplePHP Unitary library! " );
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env php
2
+ <?php
3
+ use MaplePHP \Http \Environment ;
4
+ use MaplePHP \Http \ServerRequest ;
5
+ use MaplePHP \Http \Uri ;
6
+ use MaplePHP \Prompts \Command ;
7
+ use MaplePHP \Unitary \Unit ;
8
+
9
+ if (!class_exists (Unit::class)) {
10
+ $ dir = realpath (__DIR__ . "/../../../ " );
11
+ $ alFile = (defined ("UNITARY_AUTOLOAD_FILE " ) ? UNITARY_AUTOLOAD_FILE : "$ dir/vendor/autoload.php " );
12
+ if (is_file ($ alFile )) {
13
+ require_once ($ alFile );
14
+ } else {
15
+ die ("Please run 'composer install' before running the example test suite " );
16
+ }
17
+ }
18
+
19
+ $ unit = new Unit ();
20
+ $ command = new Command ();
21
+ $ env = new Environment ();
22
+ $ request = new ServerRequest (new Uri ($ env ->getUriParts ([
23
+ "argv " => $ argv
24
+ ])), $ env );
25
+
26
+ $ data = $ request ->getCliArgs ();
27
+ $ defaultPath = (defined ("UNITARY_PATH " ) ? UNITARY_PATH : null );
28
+
29
+ try {
30
+ $ path = ($ data ['path ' ] ?? $ defaultPath );
31
+ if (!isset ($ path )) {
32
+ throw new Exception ("Path not specified: --path=path/to/dir " );
33
+ }
34
+
35
+ $ testDir = realpath ($ data ['path ' ]);
36
+ if (!is_dir ($ testDir )) {
37
+ throw new Exception ("Test directory ' $ testDir' does not exist " );
38
+ }
39
+ $ unit ->setArgs ($ data );
40
+ $ unit ->executeAll ($ testDir );
41
+
42
+ } catch (Exception $ e ) {
43
+ $ command ->error ($ e ->getMessage ());
44
+ }
You can’t perform that action at this time.
0 commit comments