Download the PHP package maplephp/unitary without Composer
On this page you can find all versions of the php package maplephp/unitary. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download maplephp/unitary
More information about maplephp/unitary
Files in maplephp/unitary
Package unitary
Short Description PHP Unitary is a user-friendly and robust unit testing library designed to make writing and running tests for your PHP code easy.
License Apache-2.0
Homepage https://wazabii.se
Rated 5.00 based on 1 reviews
Informations about the package unitary
MaplePHP - Unitary
PHP Unitary is a user-friendly and robust unit testing library designed to make writing and running tests for your PHP code easy. With an intuitive CLI interface that works on all platforms and robust validation options, Unitary makes it easy for you as a developer to ensure your code is reliable and functions as intended.
Syntax You Will Love
Documentation
The documentation is divided into several sections:
- Installation
- Guide
- 1. Create a Test File
- 2. Create a Test Case
- 3. Run the Tests
- Configurations
- Validation List
- Data Type Checks
- Equality and Length Checks
- Numeric Range Checks
- String and Pattern Checks
- Required and Boolean-Like Checks
- Date and Time Checks
- Version Checks
- Logical Checks
Installation
To install MaplePHP Unitary, run the following command:
Guide
1. Create a Test File
Unitary will, by default, find all files prefixed with "unitary-" recursively from your project's root directory (where your "composer.json" file exists). The vendor directory will be excluded by default.
Start by creating a test file with a name that starts with "unitary-", e.g., "unitary-request.php". You can place the file inside your library directory, for example like this: tests/unitary-request.php
.
Note: All of your library classes will automatically be autoloaded through Composer's autoloader inside your test file!
2. Create a Test Case
Now that we have created a test file, e.g., tests/unitary-request.php
, we will need to add our test cases and tests. I will create a test for one of my other libraries below, which is MaplePHP/HTTP, specifically the Request library that has full PSR-7 support.
I will show you three different ways to test your application below.
The example above uses both built-in validation and custom validation (see below for all built-in validation options).
3. Run the Tests
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:
The Output:
And that is it! Your tests have been successfully executed!
With that, you are ready to create your own tests!
Configurations
Select a Test File to Run
After each test, a hash key is shown, allowing you to run specific tests instead of all.
Run Test Case Manually
You can also mark a test case to run manually, excluding it from the main test batch.
And this will only run the manual test:
Change Test Path
The path argument takes both absolute and relative paths. The command below will find all tests recursively from the "tests" directory.
Note: The vendor
directory will be excluded from tests by default. However, if you change the --path
, you will need to manually exclude the vendor
directory.
Exclude Files or Directories
The exclude argument will always be a relative path from the --path
argument's path.
Validation List
Each prompt can have validation rules and custom error messages. Validation can be defined using built-in rules (e.g., length, email) or custom functions. Errors can be specified as static messages or dynamic functions based on the error type.
Data Type Checks
-
isString
- Description: Checks if the value is a string.
- Usage:
"isString" => []
-
isInt
- Description: Checks if the value is an integer.
- Usage:
"isInt" => []
-
isFloat
- Description: Checks if the value is a float.
- Usage:
"isFloat" => []
-
isBool
- Description: Checks if the value is a boolean.
- Usage:
"isBool" => []
-
isArray
- Description: Checks if the value is an array.
- Usage:
"isArray" => []
-
isObject
- Description: Checks if the value is an object.
- Usage:
"isObject" => []
-
isFile
- Description: Checks if the value is a valid file.
- Usage:
"isFile" => []
-
isDir
- Description: Checks if the value is a valid directory.
- Usage:
"isDir" => []
-
isResource
- Description: Checks if the value is a valid resource.
- Usage:
"isResource" => []
- number
- Description: Checks if the value is numeric.
- Usage:
"number" => []
Equality and Length Checks
-
equal
- Description: Checks if the value is equal to a specified value.
- Usage:
"equal" => ["someValue"]
-
notEqual
- Description: Checks if the value is not equal to a specified value.
- Usage:
"notEqual" => ["someValue"]
-
length
- Description: Checks if the string length is between a specified start and end length.
- Usage:
"length" => [1, 200]
- equalLength
- Description: Checks if the string length is equal to a specified length.
- Usage:
"equalLength" => [10]
Numeric Range Checks
-
min
- Description: Checks if the value is greater than or equal to a specified minimum.
- Usage:
"min" => [10]
-
max
- Description: Checks if the value is less than or equal to a specified maximum.
- Usage:
"max" => [100]
-
positive
- Description: Checks if the value is a positive number.
- Usage:
"positive" => []
- negative
- Description: Checks if the value is a negative number.
- Usage:
"negative" => []
String and Pattern Checks
-
pregMatch
- Description: Validates if the value matches a given regular expression pattern.
- Usage:
"pregMatch" => ["a-zA-Z"]
-
atoZ (lower and upper)
- Description: Checks if the value consists of characters between
a-z
orA-Z
. - Usage:
"atoZ" => []
- Description: Checks if the value consists of characters between
-
lowerAtoZ
- Description: Checks if the value consists of lowercase characters between
a-z
. - Usage:
"lowerAtoZ" => []
- Description: Checks if the value consists of lowercase characters between
-
upperAtoZ
- Description: Checks if the value consists of uppercase characters between
A-Z
. - Usage:
"upperAtoZ" => []
- Description: Checks if the value consists of uppercase characters between
-
hex
- Description: Checks if the value is a valid hex color code.
- Usage:
"hex" => []
-
email
- Description: Validates email addresses.
- Usage:
"email" => []
-
url
- Description: Checks if the value is a valid URL (http|https is required).
- Usage:
"url" => []
-
phone
- Description: Validates phone numbers.
- Usage:
"phone" => []
-
zip
- Description: Validates ZIP codes within a specified length range.
- Usage:
"zip" => [5, 9]
-
domain
- Description: Checks if the value is a valid domain.
- Usage:
"domain" => [true]
-
dns
- Description: Checks if the host/domain has a valid DNS record (A, AAAA, MX).
- Usage:
"dns" => []
-
matchDNS
- Description: Matches DNS records by searching for a specific type and value.
- Usage:
"matchDNS" => [DNS_A]
-
lossyPassword
- Description: Validates a password with allowed characters
[a-zA-Z\d$@$!%*?&]
and a minimum length. - Usage:
"lossyPassword" => [8]
- Description: Validates a password with allowed characters
- strictPassword
- Description: Validates a strict password with specific character requirements and a minimum length.
- Usage:
"strictPassword" => [8]
Required and Boolean-Like Checks
-
required
- Description: Checks if the value is not empty (e.g., not
""
,0
,NULL
). - Usage:
"required" => []
- Description: Checks if the value is not empty (e.g., not
-
isBoolVal
- Description: Checks if the value is a boolean-like value (e.g., "on", "yes", "1", "true").
- Usage:
"isBoolVal" => []
-
hasValue
- Description: Checks if the value itself is interpreted as having value (e.g., 0 is valid).
- Usage:
"hasValue" => []
- isNull
- Description: Checks if the value is null.
- Usage:
"isNull" => []
Date and Time Checks
-
date
- Description: Checks if the value is a valid date with the specified format.
- Usage:
"date" => ["Y-m-d"]
-
dateTime
- Description: Checks if the value is a valid date and time with the specified format.
- Usage:
"dateTime" => ["Y-m-d H:i"]
-
time
- Description: Checks if the value is a valid time with the specified format.
- Usage:
"time" => ["H:i"]
- age
- Description: Checks if the value represents an age equal to or greater than the specified minimum.
- Usage:
"age" => [18]
Version Checks
-
validVersion
- Description: Checks if the value is a valid version number.
- Usage:
"validVersion" => [true]
- versionCompare
- Description: Validates and compares if a version is equal/more/equalMore/less than a specified version.
- Usage:
"versionCompare" => ["1.0.0", ">="]
Logical Checks
-
oneOf
- Description: Validates if one of the provided conditions is met.
- Usage:
"oneOf" => [["length", [1, 200]], "email"]
- allOf
- Description: Validates if all the provided conditions are met.
- Usage:
"allOf" => [["length", [1, 200]], "email"]
Additional Validations
-
creditCard
- Description: Validates credit card numbers.
- Usage:
"creditCard" => []
- vatNumber
- Description: Validates Swedish VAT numbers.
- Usage:
"vatNumber" => []
All versions of unitary with dependencies
maplephp/blunder Version ^1.0
maplephp/dto Version ^3.0
maplephp/http Version ^1.0
maplephp/validate Version ^1.0
maplephp/prompts Version ^1.0