{"id":19553953,"url":"https://github.com/developeruz/yii-matcher","last_synced_at":"2025-04-26T21:31:24.922Z","repository":{"id":56966475,"uuid":"39336838","full_name":"developeruz/yii-matcher","owner":"developeruz","description":"Класс для легкого тестирования моделей в Yii2","archived":false,"fork":false,"pushed_at":"2015-07-20T08:11:20.000Z","size":136,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-04T18:04:18.314Z","etag":null,"topics":["testing","yii2"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/developeruz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-19T14:35:59.000Z","updated_at":"2025-03-15T20:58:01.000Z","dependencies_parsed_at":"2022-08-21T11:20:17.773Z","dependency_job_id":null,"html_url":"https://github.com/developeruz/yii-matcher","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developeruz%2Fyii-matcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developeruz%2Fyii-matcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developeruz%2Fyii-matcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/developeruz%2Fyii-matcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/developeruz","download_url":"https://codeload.github.com/developeruz/yii-matcher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251057329,"owners_count":21529638,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["testing","yii2"],"created_at":"2024-11-11T04:25:25.545Z","updated_at":"2025-04-26T21:31:24.644Z","avatar_url":"https://github.com/developeruz.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Класс для легкого тестирования моделей в Yii2\n============\n\n**Что и зачем тестировать?** Разработчики Yii-фреимворка протестировали и гарантируют правильную работу правил валидации.\nНо они не гарантируют, что вы незабыли их прописать в модели или позже не удалили некоторые из них. Поэтому важно писать unit-тесты\nдля моделей. Данный класс облегчит тестирование правил валидации ваших моделей.\n\n## Установка:##\n```bash\n$ php composer.phar require developeruz/yii-matcher \"*\"\n```\n\n## Пример использования:##\n\n```php\nuse developeruz\\yii_matcher\\ModelMatcher;\n\nclass ValidateTest extends TestCase {\n\n    public function testPhoneIsSafeOnlyInRegistration()\n    {\n         $userModel = new ModelMatcher('app\\models\\User');\n         $userModel-\u003eshouldBeSafe('phone', 'registration');\n         $userModel-\u003eshouldBeNotSafe('phone');\n    }\n    \n     public function testUserHasPostsRelation()\n     {\n         $userModel = new ModelMatcher('app\\models\\User');\n         $userModel-\u003ehasMany('posts', 'app\\models\\Post', ['user_id' =\u003e 'id']);\n     }\n     \n     public function testLoginLength()\n     {\n          $userModel = new ModelMatcher('app\\models\\User');\n          $userModel-\u003ematchLength('login', 3, 20);\n     }\n}\n```\n## Доступные методы: ##\n\n- **shouldBeSafe()** и **shouldBeNotSafe()** - проверка на возможность массового присвоения атрибута \n- **shouldBeRequired()** и **shouldBeNotRequired()** - проверка на обязательность заполнения параметра \n- **matchLength()**  - проверка на длинну строки. Для того, чтобы провести проверку только на  *min* или *max*, \nзадайте второй параметр как null.\n- **hasOne()** и **hasMany()**  - проверка на наличие связей \n\nВсе методы принимают в качестве параметра имя аттрибута и необязательный параметр - сценарий.\n\n*PS: С радостью приму pull-request с дополнительными matcher-ами. Или пишите в issue какие еще валидаторы стоит добавить*","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperuz%2Fyii-matcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeveloperuz%2Fyii-matcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeveloperuz%2Fyii-matcher/lists"}