PHPackages                             developeruz/yii-matcher - 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. developeruz/yii-matcher

ActiveYii2-extension[Testing &amp; Quality](/categories/testing)

developeruz/yii-matcher
=======================

Test case like shoulda matchers for Yii 2.x

0.0.3(10y ago)3192MITPHP

Since Jul 19Pushed 10y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (4)Used By (0)

Класс для легкого тестирования моделей в Yii2
=============================================

[](#класс-для-легкого-тестирования-моделей-в-yii2)

**Что и зачем тестировать?** Разработчики Yii-фреимворка протестировали и гарантируют правильную работу правил валидации. Но они не гарантируют, что вы незабыли их прописать в модели или позже не удалили некоторые из них. Поэтому важно писать unit-тесты для моделей. Данный класс облегчит тестирование правил валидации ваших моделей.

Установка:##
------------

[](#установка)

```
$ php composer.phar require developeruz/yii-matcher "*"
```

Пример использования:##
-----------------------

[](#пример-использования)

```
use developeruz\yii_matcher\ModelMatcher;

class ValidateTest extends TestCase {

    public function testPhoneIsSafeOnlyInRegistration()
    {
         $userModel = new ModelMatcher('app\models\User');
         $userModel->shouldBeSafe('phone', 'registration');
         $userModel->shouldBeNotSafe('phone');
    }

     public function testUserHasPostsRelation()
     {
         $userModel = new ModelMatcher('app\models\User');
         $userModel->hasMany('posts', 'app\models\Post', ['user_id' => 'id']);
     }

     public function testLoginLength()
     {
          $userModel = new ModelMatcher('app\models\User');
          $userModel->matchLength('login', 3, 20);
     }
}
```

Доступные методы:
-----------------

[](#доступные-методы)

- **shouldBeSafe()** и **shouldBeNotSafe()** - проверка на возможность массового присвоения атрибута
- **shouldBeRequired()** и **shouldBeNotRequired()** - проверка на обязательность заполнения параметра
- **matchLength()** - проверка на длинну строки. Для того, чтобы провести проверку только на *min* или *max*, задайте второй параметр как null.
- **hasOne()** и **hasMany()** - проверка на наличие связей

Все методы принимают в качестве параметра имя аттрибута и необязательный параметр - сценарий.

*PS: С радостью приму pull-request с дополнительными matcher-ами. Или пишите в issue какие еще валидаторы стоит добавить*

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 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

3

Last Release

3956d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2b19e4f376a7fc95ccaf38274dc7768c7216d419b75b5a6da5d935c5d8521db3?d=identicon)[DeveloperUz](/maintainers/DeveloperUz)

---

Top Contributors

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

---

Tags

testingyii2yiiunit test

### Embed Badge

![Health badge](/badges/developeruz-yii-matcher/health.svg)

```
[![Health](https://phpackages.com/badges/developeruz-yii-matcher/health.svg)](https://phpackages.com/packages/developeruz-yii-matcher)
```

###  Alternatives

[kahlan/kahlan

The PHP Test Framework for Freedom, Truth and Justice.

1.2k1.2M247](/packages/kahlan-kahlan)[simpletest/simpletest

SimpleTest is a framework for unit testing, web site testing and mock objects for PHP.

149355.5k32](/packages/simpletest-simpletest)[yidas/codeigniter-phpunit

CodeIgniter 3 PHPUnit Test extension library

1692.9k2](/packages/yidas-codeigniter-phpunit)

PHPackages © 2026

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