PHPackages                             phpsure/phpsure - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. phpsure/phpsure

ActiveLibrary

phpsure/phpsure
===============

00PHPCI passing

Since Feb 2Pushed 3mo agoCompare

[ Source](https://github.com/phpsure/phpsure)[ Packagist](https://packagist.org/packages/phpsure/phpsure)[ RSS](/packages/phpsure-phpsure/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHPSure
=======

[](#phpsure)

[![Build Status](https://github.com/phpsure/phpsure/workflows/CI/badge.svg)](https://github.com/phpsure/phpsure/actions?query=workflow%3ACI)

\[PRE-ALPHA\] Not yet ready for general use; use for experimentation and feedback only.

An automated contract testing framework for PHP that validates your code's type contracts at runtime.

What is PHPSure?
----------------

[](#what-is-phpsure)

PHPSure automatically tests your functions and methods to ensure they honour their type declarations. It bridges the gap between static type checking and unit testing by:

- **Automatically generating test inputs** for your functions and methods based on their type hints
- **Validating return types** match their declarations
- **Testing with custom scenarios** using PHP attributes to define specific test cases
- **Catching type contract violations** before they become runtime bugs

Think of it as automated contract testing that ensures your code does what its type signatures promise.

Installation
------------

[](#installation)

```
composer require --dev phpsure/phpsure
```

Command Line Usage
------------------

[](#command-line-usage)

### Scan a directory or file

[](#scan-a-directory-or-file)

```
vendor/bin/phpsure scan
```

**Examples:**

```
# Scan an entire directory
vendor/bin/phpsure scan src/

# Scan a specific file
vendor/bin/phpsure scan src/MyClass.php
```

The `scan` command will:

1. Discover all functions and classes in the specified path
2. Generate test inputs based on type hints
3. Execute each function/method with the generated inputs
4. Verify that return values match their declared types and optionally expected return values
5. Report any type contract violations

### Exit Codes

[](#exit-codes)

- `0` - All tests passed
- `1` - Configuration error or invalid usage
- `3` - One or more test failures detected

How It Works
------------

[](#how-it-works)

PHPSure uses PHP's Reflection API to discover your code and automatically test it:

### Basic Type Checking

[](#basic-type-checking)

For functions and methods without explicit test scenarios, PHPSure automatically generates appropriate inputs based on parameter types and validates the return type:

```
