From c9c910afc6e715c0e6b712358c289b12410e08bd Mon Sep 17 00:00:00 2001 From: Vuong Minh Date: Sun, 27 May 2018 09:08:05 +0700 Subject: [PATCH] Init commit --- .editorconfig | 14 + .gitattributes | 10 + .gitignore | 29 + .scrutinizer.yml | 9 + .travis.yml | 23 + LICENSE | 29 + composer.json | 30 + phpunit.xml.dist | 19 + src/Bootstrap.php | 35 + src/DomainValidator.php | 58 ++ src/IdNumValidator.php | 77 ++ src/IpValidator.php | 50 ++ src/TelNumValidator.php | 212 ++++++ src/resource/ip-ranges.php | 1298 +++++++++++++++++++++++++++++++++ tests/DomainValidatorTest.php | 78 ++ tests/IdNumValidatorTest.php | 90 +++ tests/IpValidatorTest.php | 73 ++ tests/TelNumValidatorTest.php | 97 +++ tests/TestCase.php | 63 ++ tests/bootstrap.php | 12 + 20 files changed, 2306 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .gitignore create mode 100644 .scrutinizer.yml create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 composer.json create mode 100644 phpunit.xml.dist create mode 100644 src/Bootstrap.php create mode 100644 src/DomainValidator.php create mode 100644 src/IdNumValidator.php create mode 100644 src/IpValidator.php create mode 100644 src/TelNumValidator.php create mode 100644 src/resource/ip-ranges.php create mode 100644 tests/DomainValidatorTest.php create mode 100644 tests/IdNumValidatorTest.php create mode 100644 tests/IpValidatorTest.php create mode 100644 tests/TelNumValidatorTest.php create mode 100644 tests/TestCase.php create mode 100644 tests/bootstrap.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..aea5bd2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# editorconfig.org + +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..b77cfe0 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,10 @@ +# Ignore all test and documentation for archive +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.editorconfig export-ignore +/.scrutinizer.yml export-ignore +/.travis.yml export-ignore +/phpunit.xml.dist export-ignore +/tests export-ignore +/docs export-ignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2339c84 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# phpstorm project files +.idea + +# netbeans project files +nbproject + +# zend studio for eclipse project files +.buildpath +.project +.settings + +# windows thumbnail cache +Thumbs.db + +/composer.lock + +# composer vendor dir +/vendor + +# composer itself is not needed +composer.phar + +# Mac DS_Store Files +.DS_Store + +# phpunit itself is not needed +phpunit.phar +# local phpunit config +/phpunit.xml diff --git a/.scrutinizer.yml b/.scrutinizer.yml new file mode 100644 index 0000000..4d60661 --- /dev/null +++ b/.scrutinizer.yml @@ -0,0 +1,9 @@ +checks: + php: + code_rating: true + duplication: true +tools: + php_code_coverage: + enabled: true + external_code_coverage: + timeout: 600 diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..90e63ea --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +language: php + +php: + - 5.5 + - 5.6 + - 7.0 + - 7.1 + - 7.2 + +install: + - composer self-update + - composer install + +before_script: + - travis_retry composer self-update + - travis_retry composer install --no-interaction --prefer-source --dev + +script: + - phpunit --coverage-text --coverage-clover=coverage.clover + +after_script: + - wget https://scrutinizer-ci.com/ocular.phar + - php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1cf4998 --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2017, Yii Viet +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..7ccb069 --- /dev/null +++ b/composer.json @@ -0,0 +1,30 @@ +{ + "name": "yiiviet/yii2-validator", + "description": "Extension hổ trợ các validator dữ liệu đặc thù trong nước.", + "type": "yii2-extension", + "keywords": ["yii2","validator","Viet Nam validator"], + "license": "BSD-3-Clause", + "authors": [ + { + "name": "Vuong Minh", + "email": "vuongxuongminh@gmail.com" + } + ], + "require": { + "php":">=5.5", + "yiisoft/yii2": "~2.0.7", + "kdn/yii2-domain-validator": "*", + "fzaninotto/faker": "^1.7" + }, + "autoload": { + "psr-4": { + "yiiviet\\validator\\": "src" + } + }, + "repositories": [ + { + "type": "composer", + "url": "https://asset-packagist.org" + } + ] +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..c2f1fe9 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,19 @@ + + + + + ./tests + + + + + ./src/ + + + diff --git a/src/Bootstrap.php b/src/Bootstrap.php new file mode 100644 index 0000000..f0787da --- /dev/null +++ b/src/Bootstrap.php @@ -0,0 +1,35 @@ + + * @since 1.0 + */ +class Bootstrap implements BootstrapInterface +{ + + /** + * @inheritdoc + */ + public function bootstrap($app) + { + Validator::$builtInValidators = array_merge([ + 'ipvn' => IpValidator::class, + 'idnumvn' => IdNumValidator::class, + 'telnumvn' => TelNumValidator::class, + 'domainvn' => DomainValidator::class + ], Validator::$builtInValidators); + } + +} diff --git a/src/DomainValidator.php b/src/DomainValidator.php new file mode 100644 index 0000000..ab1495e --- /dev/null +++ b/src/DomainValidator.php @@ -0,0 +1,58 @@ + 'Tên miền không phải miền VN!'] + * ]; + * } + * ``` + * + * @author Vuong Minh + * @since 1.0 + */ +class DomainValidator extends BaseDomainValidator +{ + + /** + * @inheritdoc + * @throws \yii\base\InvalidConfigException + */ + public function init() + { + parent::init(); + + if (empty($this->message)) { + $this->message = '{attribute} is invalid `.vn` domain!'; + } + } + + /** + * @inheritdoc + * @throws \yii\base\NotSupportedException + */ + public function validateValue($value) + { + if ($result = parent::validateValue($value)) { + return $result; + } elseif (!preg_match('/\.vn$/', $value)) { + return [$this->message, []]; + } else { + return null; + } + } + +} diff --git a/src/IdNumValidator.php b/src/IdNumValidator.php new file mode 100644 index 0000000..e7a98be --- /dev/null +++ b/src/IdNumValidator.php @@ -0,0 +1,77 @@ + 'Chứng minh nhân dân không hợp lệ.'] + * ]; + * } + * ``` + * + * Nếu bạn chấp nhận luôn thẻ căn cước vừa mới ban hành thì: + * + * ```php + * public function rules() { + * return [ + * ['telAttr', 'idnumvn', 'message' => 'Chứng minh nhân dân hoặc thẻ căn cước không hợp lệ.', 'onlyId' => false] + * ]; + * } + * ``` + * + * @author Vuong Minh + * @since 1.0 + */ +class IdNumValidator extends RegularExpressionValidator +{ + + /** + * @var bool Thiết lập nếu như bạn chỉ muốn kiểm tra chứng minh thư (không bao gồm thẻ căn cước). + */ + public $onlyId = false; + + /** + * @var string Pattern của chứng minh thư cũ. + */ + public $id = '^((0[0-8]|1[0-9]|2[0-9]|3[0-8])\d{7})|((09[015]|23[01]|245|28[015])\d{6})$'; + + /** + * @var string Pattern của chứng minh thư mới. + */ + public $idNew = '^((0[0-8]|1[0-9]|2[0-9]|3[0-8])\d{10})|((09[015]|23[01]|245|28[015])\d{9})$'; + + /** + * @var string Pattern của căn cước công dân. + */ + public $cId = '^(0[012468]|1[0124579]|2[02]|2[4-7]|3[01]|3[3-8]|4[0245689]|5[12468]|6[024678]|7[024579]|8[0234679]|9[1-6])\d{10}$'; + + /** + * {@inheritdoc} + * @throws \yii\base\InvalidConfigException + */ + public function init() + { + $pattern = [$this->id, $this->idNew]; + + if (!$this->onlyId) { + $pattern[] = $this->cId; + } + + $this->pattern = "/(" . implode(")|(", $pattern) . ")/"; + + parent::init(); + } + +} diff --git a/src/IpValidator.php b/src/IpValidator.php new file mode 100644 index 0000000..c068e53 --- /dev/null +++ b/src/IpValidator.php @@ -0,0 +1,50 @@ + 'Ip phải là ip Việt Nam!'] + * ]; + * } + * ``` + * + * @author Vuong Minh + * @since 1.0 + */ +class IpValidator extends BaseIpValidator +{ + + /** + * @var array Thuộc tính hổ trợ cache range ip Việt Nam. + */ + private static $_ipRanges = []; + + /** + * @throws \yii\base\InvalidConfigException + */ + public function init() + { + parent::init(); + + if (!empty(self::$_ipRanges)) { + $this->setRanges(self::$_ipRanges); + } else { + $this->setRanges(self::$_ipRanges = require(__DIR__ . '/resource/ip-ranges.php')); + } + } + + +} diff --git a/src/TelNumValidator.php b/src/TelNumValidator.php new file mode 100644 index 0000000..3501379 --- /dev/null +++ b/src/TelNumValidator.php @@ -0,0 +1,212 @@ + 'Số điện thoại phải là số trong nước'] + * ]; + * } + * ``` + * + * Chỉ kiểm tra số di động (bỏ số bàn) + * + * ```php + * public function rules() { + * return [ + * ['telAttr', 'telnumvn', 'message' => 'Số điện thoại phải là số trong nước', 'mobileOnly' => true] + * ]; + * } + * ``` + * + * Chỉ kiểm tra số bàn (bỏ số di động) + * + * ```php + * public function rules() { + * return [ + * ['telAttr', 'telnumvn', 'message' => 'Số điện thoại phải là số trong nước', 'landLineOnly' => true] + * ]; + * } + * ``` + * + * Chi kiểm tra số điện thoại viettel + * + * ```php + * public function rules() { + * return [ + * ['telAttr', 'telnumvn', 'message' => 'Số điện thoại phải là số trong nước', 'pattern' => 'viettel'] + * ]; + * } + * ``` + * + * danh sách các nhà mạng (pattern) hổ trợ: mobi, vina, viettel, vnmobi, gmobile, beeline, vsat, indochina + * + * Sử dụng trong DynamicModel tương tự. + * + * @author Vuong Minh + * @since 1.0 + */ +class TelNumValidator extends RegularExpressionValidator +{ + /** + * @var array Mảng chứa tên các telco (nhà mạng). Các nhà mạng nằm trong mảng sẽ là kiểu ràng buộc của dữ liệu. + * Lưu ý nếu như tên telco cũng nằm ở mảng `exceptTelco` thì mặc định telco đó sẽ bị loại bỏ. + * + * Nếu mảng là rổng động nghĩa với dữ liệu kiểm tra chỉ cần là số điện thoại Việt Nam. + * + * @see exceptTelco + */ + public $onlyTelco = []; + + /** + * @var array Mảng chứa tên các telco (nhà mạng). Các nhà mạng nằm trong mảng sẽ được bỏ qua (không kiểm tra). + * @see onlyTelco + */ + public $exceptTelco = []; + + /** + * @var string Pattern kiểm tra số viettel. + */ + public $viettel = '^(84|0)?(9[6-8]|16[2-9]|86)\d{7}$'; + + /** + * @var string Pattern kiểm tra số vinaphone. + */ + public $vinaPhone = '^(84|0)?(9[14]|12[3-5]|12[79]|88)\d{7}$'; + + /** + * @var string Pattern kiểm tra số mobiphone. + */ + public $mobiFone = '^(84|0)?(9[03]|12[0-2]|12[68]|89)\d{7}$'; + + /** + * @var string Pattern kiểm tra số vnmobi. + */ + public $vietNamMobile = '^(84|0)?(92|18[68]|82)[\d]{7}$'; + + /** + * @var string Pattern kiểm tra số gmobile. + */ + public $gMobile = '^(84|0)?199[\d]{7}$'; + + /** + * @var string Pattern kiểm tra số beeline. + */ + public $beeline = '^(84|0)?99[3-7][\d]{7}$'; + + /** + * @var string Pattern kiểm tra số vsat. + */ + public $vsat = '^(84|0)?992[\d]{7}$'; + + /** + * @var string Pattern kiểm tra số indochina. + */ + public $indoChina = '^(84|0)?99[89][\d]{7}$'; + + /** + * @var string Pattern kiểm tra số điện thoại bàn. + */ + public $landLine = '^(84|0)?(((20[3-9]|21[0-6]|21[89]|22[0-2]|22[5-9]|23[2-9]|24[2-5]|248|25[12]|25[4-9]|26[0-3]|27[0-7]|28[2-5]|29([0-4]|[67])|299)\d{7})|((246[236]|247[13]|286[23]|287[13])\d{6}))$'; + + /** + * @var bool|string Thiết lập kiểu `format` di động thêm '0' sau khi thực thi kiểm tra hoàn tất (dữ liệu attr hợp lệ). + * Nó dùng để chuẩn hóa dữ liệu cho bạn. Mặc định `FALSE` sẽ không can thiệp đến dữ liệu của bạn. + */ + public $mobileFormat = false; + + /** + * @inheritdoc + * @throws InvalidConfigException + */ + public function init() + { + $this->onlyTelco = (array)$this->onlyTelco; + $this->exceptTelco = (array)$this->exceptTelco; + + $pattern = []; + foreach (['viettel', 'mobiFone', 'vinaPhone', 'indoChina', 'gMobile', 'beeline', 'vsat', 'landLine'] as $telco) { + if ($this->isUse($telco)) { + $pattern[] = $this->{$telco}; + } + } + + if (!empty($pattern)) { + $this->pattern = "/(" . implode(")|(", $pattern) . ")/"; + } else { + throw new InvalidConfigException('Your telco setup is not valid!'); + } + + parent::init(); + } + + + /** + * Phương thức kiểm tra telco (nhà mạng) có phải là thành phần cần kiểm tra hay không. + * + * @param string $telco Tên nhà mạng cần kiểm tra + * @return bool Trả về `TRUE` nếu như telco la thành phần kiểm tra. + */ + protected function isUse($telco) + { + if (empty($this->onlyTelco)) { + $only = true; + } else { + $only = false; + foreach ($this->onlyTelco as $expect) { + if ($telco === $expect) { + $only = true; + break; + } + } + } + + $except = false; + foreach ($this->exceptTelco as $expect) { + if ($telco === $expect) { + $except = true; + break; + } + } + + return $only && !$except; + } + + /** + * @inheritdoc + */ + public function validateAttribute($model, $attribute) + { + if (($result = parent::validateAttribute($model, $attribute)) === null) { + if ($this->mobileFormat) { + $model->{$attribute} = preg_replace('/^(84|0)?(\d+)$/', '0$2', $model->{$attribute}); + } + + return null; + } else { + return $result; + } + } + + public function validateValue($value) + { + $value = preg_replace('/[^0-9]/', '', $value); + + return parent::validateValue($value); + } +} diff --git a/src/resource/ip-ranges.php b/src/resource/ip-ranges.php new file mode 100644 index 0000000..ceb9078 --- /dev/null +++ b/src/resource/ip-ranges.php @@ -0,0 +1,1298 @@ + + * @since 1.0 + */ +class DomainValidatorTest extends TestCase +{ + + /** + * @dataProvider validDomainProvider + */ + public function testValidDomain($domain) + { + $model = DynamicModel::validateData([ + 'domain' => $domain + ], [ + ['domain', 'domainvn'] + ]); + + $this->assertFalse($model->hasErrors()); + } + + /** + * @dataProvider invalidDomainProvider + */ + public function testInvalidDomain($domain) + { + $model = DynamicModel::validateData([ + 'domain' => $domain + ], [ + ['domain', 'domainvn'] + ]); + + $this->assertTrue($model->hasErrors()); + } + + public function validDomainProvider() + { + return [ + ['yiiframework.vn'], + ['chinhphu.vn'], + ['edu.vn'], + ['fpt.edu.vn'], + ['zing.vn'], + ['mp3.zing.vn'], + ['gov.vn'], + ['google.com.vn'], + ['vnexpress.vn'], + ['momo.vn'] + ]; + } + + + public function invalidDomainProvider() + { + return [ + ['yiiframework.com'], + ['github.com'], + ['google.com'], + ['stackoverflow.com'], + ['blog.jetbrains.com'] + ]; + } + + +} diff --git a/tests/IdNumValidatorTest.php b/tests/IdNumValidatorTest.php new file mode 100644 index 0000000..d798d63 --- /dev/null +++ b/tests/IdNumValidatorTest.php @@ -0,0 +1,90 @@ + + * @since 1.0 + */ +class IdNumValidatorTest extends TestCase +{ + /** + * @dataProvider idNumValidProvider + */ + public function testValidIdNum($idOld, $idNew, $cId) + { + $model = DynamicModel::validateData([ + 'idOld' => $idOld, + 'idNew' => $idNew, + 'cId' => $cId + ], [ + [['idOld', 'idNew', 'cId'], 'idnumvn'] + ]); + + $this->assertFalse($model->hasErrors()); + } + + /** + * @dataProvider idNumValidProvider + */ + public function testValidIdNumExceptCID($idOld, $idNew, $cId) + { + $model = DynamicModel::validateData([ + 'idOld' => $idOld, + 'idNew' => $idNew, + 'cId' => $cId + ], [ + [['idOld', 'idNew', 'cId'], 'idnumvn', 'onlyId' => true] + ]); + + $this->assertTrue($model->hasErrors()); + } + + /** + * @dataProvider idNumInvalidProvider + */ + public function testInValidIdNum($idOld, $idNew, $cId) + { + $model = DynamicModel::validateData([ + 'idOld' => $idOld, + 'idNew' => $idNew, + 'cId' => $cId + ], [ + [['idOld', 'idNew', 'cId'], 'idnumvn'] + ]); + + $this->assertTrue($model->hasErrors()); + } + + public function idNumValidProvider() + { + return [ + ['293422825', '001089000098', '405071000030'], + ['025478996', '036087000067', '526099003096'], + ['017351686', '016509820190', '722099000144'], + ['293422825', '079301000099', '836200003212'], + ['293422825', '2934228250', '961302004651'], + ]; + } + + public function idNumInvalidProvider() + { + return [ + ['79a7sd9a7', '331089000098a', '415071000030'], + ['987845687', '836087000067e', '506099003096'], + ['465879754', '216509820190f', '782099000144'], + ['39979800e', '079301000099e', '816200003212'], + ['554979964', '2934228250fe', '981302004651'], + ]; + } + +} diff --git a/tests/IpValidatorTest.php b/tests/IpValidatorTest.php new file mode 100644 index 0000000..7ddafb6 --- /dev/null +++ b/tests/IpValidatorTest.php @@ -0,0 +1,73 @@ + + * @since 1.0 + */ +class IpValidatorTest extends TestCase +{ + + /** + * @dataProvider validIpProvider + */ + public function testValidIp($ip) + { + $model = DynamicModel::validateData(['ip' => $ip], [ + ['ip', 'ipvn'] + ]); + + $this->assertFalse($model->hasErrors()); + } + + /** + * @dataProvider invalidIpProvider + */ + public function testInvalidIp($ip) + { + $model = DynamicModel::validateData(['ip' => $ip], [ + ['ip', 'ipvn'] + ]); + + $this->assertTrue($model->hasErrors()); + } + + + public function validIpProvider() + { + return [ + ['113.161.173.10'], + ['171.255.199.129'], + ['118.70.187.126'], + ['115.78.225.211'], + ['2405:4800:102:1::3'], + ['2001:df0:66:40::16'] + ]; + } + + public function invalidIpProvider() + { + return [ + ['217.24.254.30'], + ['82.114.86.1'], + ['200.114.80.9'], + ['190.123.83.251'], + ['190.123.83.251'], + ['190.123.83.251'], + ['139.199.201.249'], + ['52.80.73.123'], + ['2a03:2880:f11f:83:face:b00c::25de'], + ['2a00:1450:4007:809::200e'] + ]; + } +} diff --git a/tests/TelNumValidatorTest.php b/tests/TelNumValidatorTest.php new file mode 100644 index 0000000..8bcc86f --- /dev/null +++ b/tests/TelNumValidatorTest.php @@ -0,0 +1,97 @@ + + * @since 1.0 + */ +class TelNumValidatorTest extends TestCase +{ + + /** + * @dataProvider telNumValidProvider + */ + public function testValidTelNum($phone) + { + $model = DynamicModel::validateData(['tel' => $phone], [ + ['tel', 'telnumvn'] + ]); + + $this->assertFalse($model->hasErrors()); + + $model = DynamicModel::validateData(['tel' => $phone], [ + ['tel', 'telnumvn', 'mobileFormat' => true] + ]); + + $this->assertFalse($model->hasErrors()); + $this->assertNotEquals($phone, $model['tel']); + $phone = $model['tel']; + + $model = DynamicModel::validateData(['tel' => $phone], [ + ['tel', 'telnumvn', 'mobileFormat' => true] + ]); + + $this->assertFalse($model->hasErrors()); + $this->assertEquals($phone, $model['tel']); + } + + /** + * @dataProvider telNumInvalidProvider + */ + public function testInvalidTelNum($phone) + { + $model = DynamicModel::validateData(['tel' => $phone], [ + ['tel', 'telnumvn'] + ]); + + $this->assertTrue($model->hasErrors()); + } + + public function testTelcoDetected() + { + $model = DynamicModel::validateData(['tel' => '0909113911'], [ + ['tel', 'telnumvn', 'onlyTelco' => ['landLine']] + ]); + + $this->assertTrue($model->hasErrors()); + + $model = DynamicModel::validateData(['tel' => '0909113911'], [ + ['tel', 'telnumvn', 'exceptTelco' => ['landLine']] + ]); + + $this->assertFalse($model->hasErrors()); + } + + public function telNumValidProvider() + { + return [ + ['84982527982'], + ['84973776072'], + ['84917749254'], + ['84904770053'], + ['842838564399'] + ]; + } + + public function telNumInvalidProvider() + { + return [ + ['asdasdasdasd1231a'], + ['!@#!@#1123123..123'], + ['09091139111'], + ['016485754635'], + ['0703366854'], + ['070336685a'] + ]; + } +} diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..bf80a80 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,63 @@ + + * @since 1.0 + */ +class TestCase extends BaseTestCase +{ + + + + public function setUp() + { + $this->mockApplication(); + + parent::setUp(); + } + + public function tearDown() + { + $this->destroyApplication(); + + parent::tearDown(); + } + + protected function mockApplication($config = [], $appClass = '\yii\console\Application') + { + new $appClass(ArrayHelper::merge([ + 'id' => 'testapp', + 'basePath' => __DIR__, + 'bootstrap' => [ + Bootstrap::class + ], + 'vendorPath' => dirname(__DIR__, 2) . '/vendor', + ], $config)); + } + + /** + * Destroys application in Yii::$app by setting it to null. + */ + protected function destroyApplication() + { + Yii::$app = null; + } + + +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..38c058c --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,12 @@ +