Skip to content

Commit

Permalink
model matcher like shoulda matchers for Yii 2.x
Browse files Browse the repository at this point in the history
  • Loading branch information
developeruz committed Jul 19, 2015
1 parent 4859149 commit ef6004e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ModelMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@ public function __construct($class)
$this->class = $class;
}

public function mustBeSafe($attribute, $onScenario = Model::SCENARIO_DEFAULT)
public function shouldBeSafe($attribute, $onScenario = Model::SCENARIO_DEFAULT)
{
$model = $this->getModel($onScenario);
$this->assertTrue($model->isAttributeSafe($attribute));
}

public function mustBeNotSafe($attribute, $onScenario = Model::SCENARIO_DEFAULT)
public function shouldBeNotSafe($attribute, $onScenario = Model::SCENARIO_DEFAULT)
{
$model = $this->getModel($onScenario);
$this->assertFalse($model->isAttributeSafe($attribute));
}

public function mustBeRequired($attribute, $onScenario = Model::SCENARIO_DEFAULT)
public function shouldBeRequired($attribute, $onScenario = Model::SCENARIO_DEFAULT)
{
$model = $this->getModel($onScenario);
$this->assertTrue($model->isAttributeRequired($attribute));
}

public function mustBeNotRequired($attribute, $onScenario = Model::SCENARIO_DEFAULT)
public function shouldBeNotRequired($attribute, $onScenario = Model::SCENARIO_DEFAULT)
{
$model = $this->getModel($onScenario);
$this->assertFalse($model->isAttributeRequired($attribute));
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class ValidateTest extends TestCase {
public function testPhoneIsSafeOnlyInRegistration()
{
$userModel = new ModelMatcher('app\models\User');
$userModel->mustBeSafe('phone', 'registration');
$userModel->mustBeNotSafe('phone');
$userModel->shouldBeSafe('phone', 'registration');
$userModel->shouldBeNotSafe('phone');
}

public function testUserHasPostsRelation()
Expand All @@ -39,8 +39,8 @@ class ValidateTest extends TestCase {
```
## Доступные методы: ##

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

0 comments on commit ef6004e

Please sign in to comment.