Skip to content

Commit 61c117b

Browse files
committed
Add bin support
1 parent e04775c commit 61c117b

File tree

5 files changed

+56
-22
lines changed

5 files changed

+56
-22
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Each prompt can have validation rules and custom error messages. Validation can
105105
- **Description**: Checks if the value is a valid date and time with the specified format.
106106
- **Usage**: `"dateTime" => ["Y-m-d H:i"]`
107107

108-
11. **bool**
108+
11. **isBool**
109109
- **Description**: Checks if the value is a boolean.
110110
- **Usage**: `"bool" => []`
111111

@@ -117,11 +117,11 @@ Each prompt can have validation rules and custom error messages. Validation can
117117
- **Description**: Validates if all of the provided conditions are met.
118118
- **Usage**: `"allOf" => [["length", [1, 200]], "email"]`
119119

120-
14. **float**
120+
14. **isFloat**
121121
- **Description**: Checks if the value is a float.
122122
- **Usage**: `"float" => []`
123123

124-
15. **int**
124+
15. **isInt**
125125
- **Description**: Checks if the value is an integer.
126126
- **Usage**: `"int" => []`
127127

@@ -173,7 +173,7 @@ Each prompt can have validation rules and custom error messages. Validation can
173173
- **Description**: Checks if the value is not equal to a specified value.
174174
- **Usage**: `"notEqual" => ["someValue"]`
175175

176-
28. **string**
176+
28. **isString**
177177
- **Description**: Checks if the value is a string.
178178
- **Usage**: `"string" => []`
179179

@@ -213,6 +213,6 @@ Each prompt can have validation rules and custom error messages. Validation can
213213
- **Description**: Checks if the value is an object.
214214
- **Usage**: `"isObject" => []`
215215

216-
38. **boolVal**
216+
38. **isBoolVal**
217217
- **Description**: Checks if the value is a boolean-like value (e.g., "on", "yes", "1", "true").
218218
- **Usage**: `"boolVal" => []`

Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function add(mixed $value, array $validation, ?string $message = null): s
3838
}
3939

4040
$readableValue = $this->getReadableValue($value);
41-
$message = (is_string($message)) ? $message : "Validation-error: %s";
41+
$msg = (is_string($message)) ? ", ($message)" : "";
4242
$this->test[] = [
4343
"method" => $method,
4444
"args" => $args,
4545
"test" => $bool,
46-
"message" => sprintf($message, $method),
46+
"message" => sprintf("Validation-error: %s", $method) . $msg,
4747
"readableValue" => $readableValue,
4848
];
4949
}

Unit.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,10 @@ public function execute(): void
9595
}
9696
if(count($this->error) > 0) {
9797
foreach($this->error as $error) {
98+
$tests = [];
9899
$this->command->title("\n{$error['message']}");
99100
foreach($error['error'] as $row) {
101+
$tests[] = $row['method'];
100102
$this->command->error("Test-value {$row['readableValue']}");
101103
$this->command->error("{$row['message']}\n");
102104
}
@@ -149,9 +151,42 @@ private function findFiles($dir): array
149151
foreach ($iterator as $file) {
150152
if (fnmatch(static::PATTERN, $file->getFilename()) &&
151153
(isset($this->args['path']) || !str_contains($file->getPathname(), "vendor/"))) {
152-
$files[] = $file->getPathname();
154+
if(!$this->findExcluded($this->exclude(), $dir, $file->getPathname())) {
155+
$files[] = $file->getPathname();
156+
}
153157
}
154158
}
155159
return $files;
156160
}
161+
162+
/**
163+
* Get exclude parameter
164+
* @return array
165+
*/
166+
function exclude(): array
167+
{
168+
$excl = array();
169+
if(isset($this->args['exclude'])) {
170+
$exclude = explode(',', $this->args['exclude']);
171+
foreach ($exclude as $file) {
172+
$new = trim($file);
173+
$lastChar = substr($new, -1);
174+
if($lastChar === "/") {
175+
$new .= "*";
176+
}
177+
$excl[] = trim($new);
178+
}
179+
}
180+
return $excl;
181+
}
182+
183+
function findExcluded(array $exclArr, string $relativeDir, string $file): bool
184+
{
185+
foreach ($exclArr as $excl) {
186+
if(fnmatch($relativeDir . "/". $excl, $file)) {
187+
return true;
188+
}
189+
}
190+
return false;
191+
}
157192
}

unitary renamed to bin/unitary

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
#!/usr/bin/env php
22
<?php
3+
/**
4+
* MaplePHP Unitary unit testing library
5+
* @example php unitary --path=fullDirPath --exclude="dir1/dir2/
6+
*/
7+
require __DIR__ . '/../vendor/autoload.php';
8+
39
use MaplePHP\Http\Environment;
410
use MaplePHP\Http\ServerRequest;
511
use MaplePHP\Http\Uri;
612
use MaplePHP\Prompts\Command;
713
use MaplePHP\Unitary\Unit;
814

9-
if (!class_exists(Unit::class)) {
10-
$dir = realpath(__DIR__ . "/../../");
11-
$alFile = (defined("UNITARY_AUTOLOAD_FILE") ? UNITARY_AUTOLOAD_FILE : "$dir/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-
1915
$unit = new Unit();
2016
$command = new Command();
2117
$env = new Environment();

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717
],
1818
"require": {
1919
"php": ">=8.0",
20-
"maplephp/dto": "*",
21-
"maplephp/http": "*",
22-
"maplephp/validate": "*",
23-
"maplephp/prompts": "*"
20+
"maplephp/dto": "^1.0",
21+
"maplephp/http": "^1.0",
22+
"maplephp/validate": "^1.0",
23+
"maplephp/prompts": "^1.0"
2424
},
2525
"autoload": {
2626
"psr-4": {
2727
"MaplePHP\\Unitary\\": ""
2828
}
2929
},
30+
"bin": [
31+
"bin/unitary"
32+
],
3033
"minimum-stability": "dev"
3134
}

0 commit comments

Comments
 (0)