Skip to content

v1.2.0 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
6695467
Add Test wrapper
wazabii8 Mar 25, 2025
20d4512
Merge branch 'bugfix/dto' into develop
wazabii8 Mar 25, 2025
5cd7418
Add mocking capabillities
wazabii8 Mar 30, 2025
9f9fd4b
Mocker and structure improvements
wazabii8 Apr 1, 2025
f3c05db
Prompt semantics
wazabii8 Apr 2, 2025
a1b38c9
Add mocking capabilities
wazabii8 Apr 13, 2025
b8a81d8
Add mock validations to method params
wazabii8 Apr 14, 2025
1543977
Code quality improvements
wazabii8 Apr 14, 2025
7ab63d6
Add more validations
wazabii8 Apr 15, 2025
fed2920
Add method parameter validation
wazabii8 Apr 17, 2025
06b5c48
Add default variable values to method generator
wazabii8 Apr 27, 2025
23ed4ba
Change validation class name
wazabii8 Apr 28, 2025
9f6cade
List validation error names collected from closure
wazabii8 Apr 30, 2025
725ea9b
Code quality improvements
wazabii8 May 1, 2025
19c373b
Code quality improvements
wazabii8 May 1, 2025
27d8dde
Code quality improvements
wazabii8 May 1, 2025
365ffb1
Code quality improvements
wazabii8 May 1, 2025
a9b89df
Add mocking improvements
wazabii8 May 2, 2025
1f240f1
Allow setting mock constructor args
wazabii8 May 2, 2025
eeb68e2
Fix validation count for mock
wazabii8 May 3, 2025
84fc6ea
Add Default data type mock
wazabii8 May 4, 2025
4c84d09
Improve mocking and error handling
wazabii8 May 4, 2025
9e8abaf
Add DTO traverse to value in validate
wazabii8 May 5, 2025
bbb5c12
Fix Mocking and MethodPool inheritance
wazabii8 May 7, 2025
8ba1ce9
refactor: replace function null checks with strict comparisons
wazabii8 May 9, 2025
2c811db
refactor: restructure project layout and improve file naming for clarity
wazabii8 May 14, 2025
9b1b242
Add assert support
wazabii8 May 17, 2025
7723592
refactor: remove closure binding from group
wazabii8 May 19, 2025
1f472d3
Add more dynamic test search
wazabii8 May 20, 2025
24f8a8a
Alow both absolute and relative argv path when root dir is present
wazabii8 May 20, 2025
555fd20
Improve CLI styling
wazabii8 May 21, 2025
702070f
Mock class identifiers
wazabii8 May 23, 2025
fea5132
Add unique mock identifier
wazabii8 May 23, 2025
0b3ab93
Pass meta data to mocked and keep orignial
wazabii8 May 25, 2025
26f8180
Add interface support for mocking
wazabii8 May 25, 2025
823c9d6
feat: Add argument check to mocker
wazabii8 May 25, 2025
289f38c
Add will throw method
wazabii8 May 27, 2025
2a67a48
Add throwable validations to Expect
wazabii8 May 29, 2025
636d3b6
bugfix: mocker method argument inheritance
wazabii8 May 29, 2025
e8d5a94
Data type and code quality improvements
wazabii8 May 30, 2025
97b4983
Code quality imporvements
wazabii8 May 30, 2025
50e89c7
Add comment block to files
wazabii8 May 30, 2025
5849439
Creating TestItem class
wazabii8 Jun 1, 2025
f058d7d
Structure improvements
wazabii8 Jun 1, 2025
b44c84d
Add test to test
wazabii8 Jun 1, 2025
cb9e455
Fix skip count
wazabii8 Jun 1, 2025
c448385
Testing mocking idea
wazabii8 Jun 6, 2025
465df4a
Minor refactoring
wazabii8 Jun 8, 2025
66a2003
Add warning if trying to mock final methods
wazabii8 Jun 8, 2025
364bc20
Adjust test
wazabii8 Jun 8, 2025
391e778
Add more descriptive code commments
wazabii8 Jun 15, 2025
bd0b6b1
feat: Start building code coverage functionality
wazabii8 Jun 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
384 changes: 99 additions & 285 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bin/unitary
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use MaplePHP\Http\Environment;
use MaplePHP\Http\ServerRequest;
use MaplePHP\Http\Uri;
use MaplePHP\Prompts\Command;
use MaplePHP\Unitary\FileIterator;
use MaplePHP\Unitary\Utils\FileIterator;

$command = new Command();
$env = new Environment();
Expand All @@ -33,7 +33,7 @@ try {
throw new Exception("Test directory '$testDir' does not exist");
}
$unit = new FileIterator($data);
$unit->executeAll($testDir);
$unit->executeAll($testDir, $defaultPath);

} catch (Exception $e) {
$command->error($e->getMessage());
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
"maplephp/prompts": "^1.0"
},
"autoload": {
"files": [
"src/Setup/assert-polyfill.php"
],
"psr-4": {
"MaplePHP\\Unitary\\": "src"
}
Expand Down
197 changes: 197 additions & 0 deletions src/Expect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
<?php
/**
* Expect — Part of the MaplePHP Unitary Testing Library
*
* @package: MaplePHP\Unitary
* @author: Daniel Ronkainen
* @licence: Apache-2.0 license, Copyright © Daniel Ronkainen
* Don't delete this comment, it's part of the license.
*/
declare(strict_types=1);

namespace MaplePHP\Unitary;

use Exception;
use Throwable;
use MaplePHP\Validate\ValidationChain;

/**
* @api
*/
class Expect extends ValidationChain
{

protected mixed $initValue = null;
protected Throwable|false|null $except = null;

/**
* Validate exception instance
*
* @param string|object|callable $compare
* @return $this
* @throws Exception
*/
public function isThrowable(string|object|callable $compare): self
{
if($except = $this->getException()) {
$this->setValue($except);
}
/** @psalm-suppress PossiblyInvalidCast */
$this->validateExcept(__METHOD__, $compare, fn() => $this->isClass((string)$compare));
return $this;
}

/**
* Validate exception message
*
* @param string|callable $compare
* @return $this
* @throws Exception
*/
public function hasThrowableMessage(string|callable $compare): self
{
if($except = $this->getException()) {
$this->setValue($except->getMessage());
}
/** @psalm-suppress PossiblyInvalidCast */
$this->validateExcept(__METHOD__, $compare, fn() => $this->isEqualTo($compare));
return $this;
}

/**
* Validate exception code
*
* @param int|callable $compare
* @return $this
* @throws Exception
*/
public function hasThrowableCode(int|callable $compare): self
{
if($except = $this->getException()) {
$this->setValue($except->getCode());
}
/** @psalm-suppress PossiblyInvalidCast */
$this->validateExcept(__METHOD__, $compare, fn() => $this->isEqualTo($compare));
return $this;
}

/**
* Validate exception Severity
*
* @param int|callable $compare
* @return $this
* @throws Exception
*/
public function hasThrowableSeverity(int|callable $compare): self
{
if($except = $this->getException()) {
$value = method_exists($except, 'getSeverity') ? $except->getSeverity() : 0;
$this->setValue($value);
}
/** @psalm-suppress PossiblyInvalidCast */
$this->validateExcept(__METHOD__, $compare, fn() => $this->isEqualTo($compare));
return $this;
}

/**
* Validate exception file
*
* @param string|callable $compare
* @return $this
* @throws Exception
*/
public function hasThrowableFile(string|callable $compare): self
{
if($except = $this->getException()) {
$this->setValue($except->getFile());
}
/** @psalm-suppress PossiblyInvalidCast */
$this->validateExcept(__METHOD__, $compare, fn() => $this->isEqualTo($compare));
return $this;
}

/**
* Validate exception line
*
* @param int|callable $compare
* @return $this
* @throws Exception
*/
public function hasThrowableLine(int|callable $compare): self
{
if($except = $this->getException()) {
$this->setValue($except->getLine());
}
/** @psalm-suppress PossiblyInvalidCast */
$this->validateExcept(__METHOD__, $compare, fn() => $this->isEqualTo($compare));
return $this;
}

/**
* Helper to validate the exception instance against the provided callable.
*
* @param string $name
* @param string|int|object|callable $compare
* @param callable $fall
* @return self
*/
protected function validateExcept(string $name, int|string|object|callable $compare, callable $fall): self
{
$pos = strrpos($name, '::');
$name = ($pos !== false) ? substr($name, $pos + 2) : $name;
$this->mapErrorValidationName($name);
if(is_callable($compare)) {
$compare($this);
} else {
$fall($this);
}

if(is_null($this->initValue)) {
$this->initValue = $this->getValue();
}

if($this->except === false) {
$this->setValue(null);
}
return $this;
}

/**
* Used to get the first value before any validation is performed and
* any changes to the value are made.
*
* @return mixed
*/
public function getInitValue(): mixed
{
return $this->initValue;
}

/**
* Retrieves the exception instance if one has been caught,
* otherwise attempts to invoke a callable value to detect any exception.
*
* @return Throwable|false Returns the caught exception if available, or false if no exception occurs.
* @throws Exception Throws an exception if the provided value is not callable.
*/
protected function getException(): Throwable|false
{
if (!is_null($this->except)) {
return $this->except;
}

$expect = $this->getValue();
if(!is_callable($expect)) {
throw new Exception("Except method only accepts callable");
}
try {
$expect();
$this->except = false;
} catch (Throwable $exception) {
$this->except = $exception;
return $this->except;
}
return false;

}
}
14 changes: 12 additions & 2 deletions src/Handlers/FileHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* FileHandler — Part of the MaplePHP Unitary Testing Library
*
* @package: MaplePHP\Unitary
* @author: Daniel Ronkainen
* @licence: Apache-2.0 license, Copyright © Daniel Ronkainen
* Don't delete this comment, it's part of the license.
*/
declare(strict_types=1);

namespace MaplePHP\Unitary\Handlers;
Expand All @@ -8,7 +15,7 @@
use MaplePHP\Http\UploadedFile;
use MaplePHP\Prompts\Command;

class FileHandler implements HandlerInterface
final class FileHandler implements HandlerInterface
{
private string $file;
private Stream $stream;
Expand All @@ -17,6 +24,7 @@ class FileHandler implements HandlerInterface
/**
* Construct the file handler
* The handler will pass stream to a file
*
* @param string $file
*/
public function __construct(string $file)
Expand All @@ -29,6 +37,7 @@ public function __construct(string $file)

/**
* Access the command stream
*
* @return Command
*/
public function getCommand(): Command
Expand All @@ -39,6 +48,7 @@ public function getCommand(): Command
/**
* Execute the handler
* This will automatically be called inside the Unit execution
*
* @return void
*/
public function execute(): void
Expand Down
9 changes: 8 additions & 1 deletion src/Handlers/HandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?php

/**
* HandlerInterface — Part of the MaplePHP Unitary Testing Library
*
* @package: MaplePHP\Unitary
* @author: Daniel Ronkainen
* @licence: Apache-2.0 license, Copyright © Daniel Ronkainen
* Don't delete this comment, it's part of the license.
*/
declare(strict_types=1);

namespace MaplePHP\Unitary\Handlers;
Expand Down
11 changes: 9 additions & 2 deletions src/Handlers/HtmlHandler.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
<?php

/**
* HtmlHandler — Part of the MaplePHP Unitary Testing Library
*
* @package: MaplePHP\Unitary
* @author: Daniel Ronkainen
* @licence: Apache-2.0 license, Copyright © Daniel Ronkainen
* Don't delete this comment, it's part of the license.
*/
declare(strict_types=1);

namespace MaplePHP\Unitary\Handlers;

use MaplePHP\Http\Stream;
use MaplePHP\Prompts\Command;

class HtmlHandler implements HandlerInterface
final class HtmlHandler implements HandlerInterface
{
private Stream $stream;
private Command $command;
Expand Down
Loading