PHPackages                             mascame/katina - 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. mascame/katina

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

mascame/katina
==============

Test helper class that validates any kind of output based on the rules passed. Useful to test API reponses or data that changes over time.

v2.0.0(9y ago)13.6k1MITPHP

Since Jul 7Pushed 9y ago1 watchersCompare

[ Source](https://github.com/marcmascarell/katina)[ Packagist](https://packagist.org/packages/mascame/katina)[ RSS](/packages/mascame-katina/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (1)Versions (3)Used By (1)

Katina - The PHP Output Validator
=================================

[](#katina---the-php-output-validator)

[![Latest Version](https://camo.githubusercontent.com/6c75309faa66c600b3bc8bf61a2dc87ce14f9d4c6dc4de3c44fb3dbe74b19c32/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f6d6172636d6173636172656c6c2f6b6174696e612e7376673f7374796c653d666c61742d737175617265)](https://github.com/marcmascarell/katina/releases)[![Travis](https://camo.githubusercontent.com/0078e0a9a2166970d4d482bca087020b3358dd6785beadc48178ee8bbc0ae0e4/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6d6172636d6173636172656c6c2f6b6174696e612e7376673f6d61784167653d323539323030303f7374796c653d666c61742d737175617265)](https://travis-ci.org/marcmascarell/katina)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Test helper class that **validates any kind of output based on the passed rules**. Useful to test API reponses or data that changes over time.

A modernized version of [ptrofimov/matchmaker](https://github.com/ptrofimov/matchmaker) package.

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

[](#installation)

`composer require mascame/katina --dev`

Basic usage
-----------

[](#basic-usage)

```
$data = [
    'name' => 'John Doe',
    'count' => 123,
];

$validator = new \Mascame\Katina\Validator(['name' => ':string', 'count' => ':int']);

$validator->check($data); // true
```

Advanced usage
--------------

[](#advanced-usage)

```
$data = [
    'name' => 'John Doe',
    'count' => 145,
    'list' => [
        'emptyList' => false,
        'nested-list' => [
            1, 2, 3
        ]
    ],
    'books' => [
        [
            'type' => 'book',
            'title' => 'Geography book',
            'chapters' => [
                'eu' => ['title' => 'Europe', 'interesting' => true],
                'as' => ['title' => 'America', 'interesting' => false]
            ]
        ],
        [
            'type' => 'book',
            'title' => 'Foreign languages book',
            'chapters' => [
                'de' => ['title' => 'Deutsch']
            ]
        ]
    ]
];

$requiredFields = [
    'name' => ':string',
    'count' => ':int',
    'list' => [
        'emptyList' => ':bool',
        'nested-list' => [
            ':int'
        ]
    ],
    'books' => [
        '*' => [
            'type' => 'book',
            'title' => ':string contains(book)',
            'chapters' => [
                ':string length(2) {1,3}' => [
                    'title' => ':string',
                    'interesting?' => ':bool',
                ]
            ]
        ]
    ]
];

$optionalFields = [
    'something' => 'boolean'
];

$validator = new \Mascame\Katina\Validator($requiredFields, $optionalFields);

$validator->check($data); // true
```

### Adding rules

[](#adding-rules)

```
$data = [
    'my-birthday' => '1980-01-01'
];

$requiredFields = ['my-birthday' => ':birthdayValidator'];

$validator = new \Mascame\Katina\Validator($requiredFields);

// You can add or override rules
\Mascame\Katina\Rules::setRules(['birthdayValidator' => function($value) {
    return ($value == '1980-01-01');
}]);

$validator->check($data); // true
```

Matching rules
--------------

[](#matching-rules)

Matching rules are strings that start with ':'. You can use multiple matchers joined with space.

Matcher could be any callable (name of function or closure). You can add your own rules or replace standard ones.

- **General**
- empty
- nonempty
- required
- in(a, b, ...)
- mixed
- any
- **Types**
- array
- bool
- boolean
- callable
- double
- float
- int
- integer
- long
- numeric
- number
- object
- real
- resource
- scalar
- string
- **Numbers**
- gt(n)
- gte(n)
- lt(n)
- lte(n)
- negative
- positive
- between(a, b)
- **Strings**
- alnum
- alpha
- cntrl
- digit
- graph
- lower
- print
- punct
- space
- upper
- xdigit
- regexp(pattern)
- email
- url
- ip
- length(n)
- min(n)
- max(n)
- contains(needle)
- starts(s)
- ends(s)
- json
- date
- **Arrays**
- count(n)
- keys(key1, key2, ...)
- **Objects**
- instance(class)
- property(name, value)
- method(name, value)

For more details [click here](https://github.com/marcmascarell/katina/blob/master/src/Rules.php)

Quantifiers for keys
--------------------

[](#quantifiers-for-keys)

- ! - one key required (default)
- ? - optional key
- - - any count of keys
- {3} - strict count of keys
- {1,5} - range

For matchers (i.e. ':string') default quantifier is \*

Using Matcher as standalone
---------------------------

[](#using-matcher-as-standalone)

You can directly use Matcher:

```
\Mascame\Katina\Matcher::matches(['test' => true], ['test' => ':bool']); // true
```

Contributing
------------

[](#contributing)

Thank you for considering contributing! You can contribute at any time forking the project and making a pull request.

Support
-------

[](#support)

If you need help or any kind of support, please send an e-mail to Marc Mascarell at .

License
-------

[](#license)

Credit to [Petr Trofimov](https://github.com/ptrofimov) for his package [ptrofimov/matchmaker](https://github.com/ptrofimov/matchmaker) which this package is heavily based on.

MIT

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

3645d ago

Major Versions

v1.0.0 → v2.0.02016-07-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/9570e08dbb97ee61a22ae78624fd6b86ce62e0a89120fe40b5bde23d4a22eb6d?d=identicon)[marcmascarell](/maintainers/marcmascarell)

---

Top Contributors

[![marcmascarell](https://avatars.githubusercontent.com/u/642299?v=4)](https://github.com/marcmascarell "marcmascarell (15 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mascame-katina/health.svg)

```
[![Health](https://phpackages.com/badges/mascame-katina/health.svg)](https://phpackages.com/packages/mascame-katina)
```

###  Alternatives

[dms/phpunit-arraysubset-asserts

This package provides ArraySubset and related asserts once deprecated in PHPUnit 8

14228.7M346](/packages/dms-phpunit-arraysubset-asserts)[phpbenchmark/phpbenchmark

Easy to use benchmark toolkit for your PHP-application. This library contains classes for comparing algorithms as well as benchmarking application responses

8011.5k2](/packages/phpbenchmark-phpbenchmark)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
