PHPackages                             beberlei/assert - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. beberlei/assert

ActiveLibrary[Testing &amp; Quality](/categories/testing)

beberlei/assert
===============

Thin assertion library for input validation in business models.

v3.3.3(1y ago)2.4k96.9M—5.6%186[29 issues](https://github.com/beberlei/assert/issues)[18 PRs](https://github.com/beberlei/assert/pulls)20BSD-2-ClausePHPPHP ^7.1 || ^8.0CI passing

Since May 20Pushed 7mo ago53 watchersCompare

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

READMEChangelog (10)Dependencies (4)Versions (65)Used By (20)

Assert
======

[](#assert)

[![Build Status](https://camo.githubusercontent.com/25f68e996d25572868e8d5ccee597d0adaa578b8c84ff4453e9e884722b5ca00/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d747261766973)](https://travis-ci.org/beberlei/assert)[![Code Coverage](https://camo.githubusercontent.com/6c636dbfade404c16aa67f2c90377d913948943db09799cf444c01576672834b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d7363727574696e697a6572)](https://scrutinizer-ci.com/g/beberlei/assert/)[![GitHub issues](https://camo.githubusercontent.com/922476844ee99e153595d7ffc2d82bb9bba2a4fcda5387717f3ddb2b862a8933/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6f676f3d676974687562)](https://github.com/beberlei/assert/issues)

[![PHP Version](https://camo.githubusercontent.com/007feb4484ea5e80f781bca844799f033e116e044c46d361e0be8711368b1d71/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/beberlei/assert)[![Stable Version](https://camo.githubusercontent.com/e575f1b53f353817316531638b2efd470c594ec633fbdfa84f4ea9b58fb6d004/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d4c6174657374)](https://packagist.org/packages/beberlei/assert)

[![Total Downloads](https://camo.githubusercontent.com/b5cf53721a845011d3cc036340c4361cb7b8283a8c872086ecc486b85a0756da/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d546f74616c2b646f776e6c6f616473)](https://packagist.org/packages/beberlei/assert)[![Monthly Downloads](https://camo.githubusercontent.com/87b4a8941b42ecb368ede0d007f3146ee4337151aa232164053ec03cd8e758ee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d4d6f6e74686c792b646f776e6c6f616473)](https://packagist.org/packages/beberlei/assert)[![Daily Downloads](https://camo.githubusercontent.com/be5bab3e4756bad1cdec12af54b162645feb7418ed196fb2c31d93800c583ad8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f62656265726c65692f6173736572742e7376673f7374796c653d666f722d7468652d6261646765266c6162656c3d4461696c792b646f776e6c6f616473)](https://packagist.org/packages/beberlei/assert)

A simple php library which contains assertions and guard methods for input validation (not filtering!) in business-model, libraries and application low-level code. The library can be used to implement pre-/post-conditions on input data.

Idea is to reduce the amount of code for implementing assertions in your model and also simplify the code paths to implement assertions. When assertions fail, an exception is thrown, removing the necessity for if-clauses in your code.

The library is not using Symfony or Zend Validators for a reason: The checks have to be low-level, fast, non-object-oriented code to be used everywhere necessary. Using any of the two libraries requires instantiation of several objects, using a locale component, translations, you name it. Its too much bloat.

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

[](#installation)

Using Composer:

```
composer require beberlei/assert
```

Example usages
--------------

[](#example-usages)

```
