yii2: Model validate some attribute error

What steps will reproduce the problem?

I have two scripts:

<?php

namespace idarex\pingppyii2;

class OrderForm extends \yii\base\Model
{
    public $order_no;
    public $subject;

    public function rules()
    {
        return [
            [['order_no', 'subject'], 'required'],
        ];
    }
}
<?php

class OrderFormTest extends PHPUnit_Framework_TestCase
{
    public function testValidate()
    {
        $form = new \idarex\pingppyii2\OrderForm();
        $form->order_no = '1234';
        $this->assertTrue($form->validate('order_no'), 'order_no is not empty');
    }
}

And runs phpunit tests/OrderFormTest.php

What is the expected result?

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

.

Time: 58 ms, Memory: 6.25Mb

OK (1 test, 1 assertion)

What do you get instead?

PHPUnit 4.8.24 by Sebastian Bergmann and contributors.

F

Time: 62 ms, Memory: 6.25Mb

There was 1 failure:

1) OrderFormTest::testValidate
order_no is not empty
Failed asserting that false is true.

/Users/bob/Documents/idarex/pingpp-yii2/tests/OrderFormTest.php:11
/Users/bob/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:149
/Users/bob/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:100

FAILURES!

Additional info

Q A
Yii version 2.0.7
PHP version PHP 5.5.30 (cli)
Operating system OS X 10.11.3 (15D21)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (17 by maintainers)

Commits related to this issue

Most upvoted comments