<commit_before><?php

namespace Phalcon\Mvc\Model\Validator;

use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model\Metadata\Files;
use Phalcon\DI;
use Phalcon\Mvc\Model\Validator\resources\TestCardNumberModel;

class CardNumberTest extends \PHPUnit_Framework_TestCase
{

    public function dataCards()
    {
        return array(
            array(
                CardNumber::VISA,
                4929351569693804,
                true
            ),
            array(
                CardNumber::VISA,
                4485767360254767,
                true
            ),
            array(
                CardNumber::VISA,
                4830875747689951,
                true
            ),
            array(
                CardNumber::VISA,
                4916181688876351,
                true
            ),
            array(
                CardNumber::VISA,
                1539277838295521,
                false
            ),
            array(
                CardNumber::MASTERCARD,
                5489650355340390,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                5252467588261052,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                5320263975322138,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                5177135503698847,
                true
            ),
            array(
                null,
                5177135503698847,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                1270338206812535,
                false
            ),
            array(
                CardNumber::MASTERCARD,
                12,
                false
            ),
            array(
                CardNumber::MASTERCARD,
                null,
                false
            ),
            array(
                null,
                1270338206812535,
                false
            )
        );
    }

    /**
     * @dataProvider dataCards
     */
    public function testValidate($type, $cardnumber, $willReturn)
    {
        $di = New DI();
        $di->set('modelsManager', new Manager());

        require_once(__DIR__ . '/resources/TestCardNumberModel.php');

        $obj = new \TestCardNumberModel();

        $obj->cardnumber = $cardnumber;
        if ($type) {
            $obj->type = $type;
        }
        $this->assertEquals($willReturn, $obj->validation());
    }
}<commit_msg>Tests for instance validation (Phalcon\Mvc\ModelInterface)<commit_after><?php

namespace Phalcon\Mvc\Model\Validator;

use Phalcon\Mvc\Model\Manager;
use Phalcon\Mvc\Model\Metadata\Files;
use Phalcon\DI;
use Phalcon\Mvc\Model\Validator\resources\TestCardNumberModel;

class CardNumberTest extends \PHPUnit_Framework_TestCase
{

    public function dataCards()
    {
        return array(
            array(
                CardNumber::VISA,
                4929351569693804,
                true
            ),
            array(
                CardNumber::VISA,
                4485767360254767,
                true
            ),
            array(
                CardNumber::VISA,
                4830875747689951,
                true
            ),
            array(
                CardNumber::VISA,
                4916181688876351,
                true
            ),
            array(
                CardNumber::VISA,
                1539277838295521,
                false
            ),
            array(
                CardNumber::MASTERCARD,
                5489650355340390,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                5252467588261052,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                5320263975322138,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                5177135503698847,
                true
            ),
            array(
                null,
                5177135503698847,
                true
            ),
            array(
                CardNumber::MASTERCARD,
                1270338206812535,
                false
            ),
            array(
                CardNumber::MASTERCARD,
                12,
                false
            ),
            array(
                CardNumber::MASTERCARD,
                null,
                false
            ),
            array(
                null,
                1270338206812535,
                false
            )
        );
    }

    /**
     * @dataProvider dataCards
     */
    public function testValidate($type, $cardnumber, $willReturn)
    {
        $di = New DI();
        $di->set('modelsManager', new Manager());

        require_once(__DIR__ . '/resources/TestCardNumberModel.php');

        $obj = new \TestCardNumberModel();

        $obj->cardnumber = $cardnumber;
        if ($type) {
            $obj->type = $type;
        }
        $this->assertEquals($willReturn, $obj->validation());
    }

    public function testValidateInstanceOfModel()
    {
        $di = New DI();
        $di->set('modelsManager', new Manager());

        require_once(__DIR__ . '/resources/TestCardNumberModel.php');

        $obj = new \TestCardNumberModel();

        $this->assertInstanceOf('Phalcon\Mvc\ModelInterface', $obj);
        $this->assertNotInstanceOf('Phalcon\Mvc\CollectionInterface', $obj);
    }
}
{'fraction_non_alphanumeric': 0.08537023723939612, 'fraction_numerical': 0.06973400431344356, 'mean_word_length': 1.0459558823529411, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1081696', 'n_tokens_mistral': 1693, 'n_tokens_neox': 1420, 'n_words': 226}