Skip to content

Commit 5f4dd74

Browse files
committed
Merge branch 'develop'
2 parents 97cb0ad + 4fd426e commit 5f4dd74

File tree

5 files changed

+88
-47
lines changed

5 files changed

+88
-47
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: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
{
2-
"name": "maplephp/unitary",
3-
"type": "library",
4-
"description": "PHP Unitary is a lightweight PHP testing library designed to simplify the process of writing and running tests for your PHP code.",
5-
"keywords": ["php", "cli", "command line", "test", "testing"],
6-
"homepage": "https://wazabii.se",
7-
"license": "Apache-2.0",
8-
"authors": [
9-
{
10-
"name": "Daniel Ronkainen",
11-
"email": "daniel.ronkainen@wazabii.se"
12-
},
13-
{
14-
"name": "MaplePHP",
15-
"homepage": "https://wazabii.se"
16-
}
17-
],
18-
"require": {
19-
"php": ">=8.0",
20-
"maplephp/dto": "*",
21-
"maplephp/http": "*",
22-
"maplephp/validate": "*",
23-
"maplephp/prompts": "*"
2+
"name": "maplephp/unitary",
3+
"type": "library",
4+
"version": "v1.0.4",
5+
"description": "PHP Unitary is a lightweight PHP testing library designed to simplify the process of writing and running tests for your PHP code.",
6+
"keywords": [
7+
"php",
8+
"cli",
9+
"command line",
10+
"test",
11+
"testing"
12+
],
13+
"homepage": "https://wazabii.se",
14+
"license": "Apache-2.0",
15+
"authors": [
16+
{
17+
"name": "Daniel Ronkainen",
18+
"email": "daniel.ronkainen@wazabii.se"
2419
},
25-
"autoload": {
26-
"psr-4": {
27-
"MaplePHP\\Unitary\\": ""
28-
}
29-
},
30-
"minimum-stability": "dev"
31-
}
20+
{
21+
"name": "MaplePHP",
22+
"homepage": "https://wazabii.se"
23+
}
24+
],
25+
"require": {
26+
"php": ">=8.0",
27+
"maplephp/dto": "^1.0",
28+
"maplephp/http": "^1.0",
29+
"maplephp/validate": "^1.0",
30+
"maplephp/prompts": "^1.0"
31+
},
32+
"autoload": {
33+
"psr-4": {
34+
"MaplePHP\\Unitary\\": ""
35+
}
36+
},
37+
"bin": [
38+
"bin/unitary"
39+
],
40+
"minimum-stability": "dev"
41+
}

0 commit comments

Comments
 (0)