Skip to content

Commit 7d1a05b

Browse files
committed
Merge branch 'develop'
2 parents 4ea8b07 + 25364ea commit 7d1a05b

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Unitary will, by default, find all files prefixed with "unitary-" recursively fr
3838

3939
Start by creating a test file with a name that starts with "unitary-", e.g., "unitary-lib-name.php". You can place the file inside `tests/unitary-lib-name.php` for example.
4040

41-
**Note: All of your library classes should be automatically be autoloaded when used in test file!**
41+
**Note: All of your library classes should be automatically be autoloaded if you are using composers autoloader inside your test file!**
4242

4343
```php
4444
<?php
@@ -74,14 +74,14 @@ $unit->add("Checking data type", function($inst) {
7474

7575
$unit->execute();
7676
```
77-
The example above uses both built-in validation and custom validation (see below for all built-in validation options).
77+
The example above uses both built-in validation and custom validation (see below for all built-in validation options).
7878

7979
### 2. Run the Tests
8080

8181
Now you are ready to execute the tests. Open your command line of choice, navigate (cd) to your project's root directory (where your `composer.json` file exists), and execute the following command:
8282

8383
```bash
84-
./vendor/bin/unitary
84+
php vendor/bin/unitary
8585
```
8686

8787
And that is it. Your tests have been successfully executed.
@@ -97,15 +97,15 @@ You can change the default root testing path and exclude files or whole director
9797
The path argument takes both absolute and relative paths. The command below will find all tests recursively from the "tests" directory.
9898

9999
```bash
100-
./vendor/bin/unitary --path="./tests/"
100+
php vendor/bin/unitary --path="./tests/"
101101
```
102102

103103
#### 2. Exclude Specific Files or Directories
104104

105105
The exclude argument will always be a relative path from the `--path` argument's path.
106106

107107
```bash
108-
./vendor/bin/unitary --exclude="./tests/unitary-query-php, tests/otherTests/*, */extras/*"
108+
php vendor/bin/unitary --exclude="./tests/unitary-query-php, tests/otherTests/*, */extras/*"
109109
```
110110

111111
## Example Breakdown

Unit.php

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ public function execute(): void
9595
}
9696
if(count($this->error) > 0) {
9797
foreach($this->error as $error) {
98-
$tests = [];
98+
//$tests = [];
9999
$this->command->title("\n{$error['message']}");
100100
foreach($error['error'] as $row) {
101-
$tests[] = $row['method'];
101+
//$tests[] = $row['method'];
102102
$this->command->error("Test-value {$row['readableValue']}");
103103
$this->command->error("{$row['message']}\n");
104104
}
@@ -150,7 +150,7 @@ private function findFiles($dir): array
150150
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
151151
foreach ($iterator as $file) {
152152
if (fnmatch(static::PATTERN, $file->getFilename()) &&
153-
(isset($this->args['path']) || !str_contains($file->getPathname(), "vendor/"))) {
153+
(isset($this->args['path']) || !str_contains($file->getPathname(), DIRECTORY_SEPARATOR . "vendor" . DIRECTORY_SEPARATOR ))) {
154154
if(!$this->findExcluded($this->exclude(), $dir, $file->getPathname())) {
155155
$files[] = $file->getPathname();
156156
}
@@ -169,9 +169,10 @@ function exclude(): array
169169
if(isset($this->args['exclude'])) {
170170
$exclude = explode(',', $this->args['exclude']);
171171
foreach ($exclude as $file) {
172+
$file = str_replace(['"', "'"], "", $file);
172173
$new = trim($file);
173174
$lastChar = substr($new, -1);
174-
if($lastChar === "/") {
175+
if($lastChar === DIRECTORY_SEPARATOR) {
175176
$new .= "*";
176177
}
177178
$excl[] = trim($new);
@@ -180,13 +181,32 @@ function exclude(): array
180181
return $excl;
181182
}
182183

184+
/**
185+
* Validate a exclude path
186+
* @param array $exclArr
187+
* @param string $relativeDir
188+
* @param string $file
189+
* @return bool
190+
*/
183191
function findExcluded(array $exclArr, string $relativeDir, string $file): bool
184192
{
193+
$file = $this->getNaturalPath($file);
185194
foreach ($exclArr as $excl) {
186-
if(fnmatch($relativeDir . "/". $excl, $file)) {
187-
return true;
195+
$relativeExclPath = $this->getNaturalPath($relativeDir . DIRECTORY_SEPARATOR . $excl);
196+
if(fnmatch($relativeExclPath, $file)) {
197+
return true;
188198
}
189199
}
190200
return false;
191201
}
192-
}
202+
203+
/**
204+
* Get path as natural path
205+
* @param string $path
206+
* @return string
207+
*/
208+
function getNaturalPath(string $path): string
209+
{
210+
return str_replace("\\", "/", $path);
211+
}
212+
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "maplephp/unitary",
33
"type": "library",
4-
"version": "v1.0.5",
4+
"version": "v1.0.6",
55
"description": "PHP Unitary is a lightweight PHP testing library designed to simplify the process of writing and running tests for your PHP code.",
66
"keywords": [
77
"php",

0 commit comments

Comments
 (0)