mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Fixes for PHP 7.2 compatibility (#14959)
This commit is contained in:

committed by
Alexander Makarov

parent
d49ec7b8be
commit
64d8af61a6
12
.travis.yml
12
.travis.yml
@ -55,9 +55,9 @@ addons:
|
|||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
include:
|
include:
|
||||||
# run tests coverage on PHP 7.1
|
|
||||||
- php: 7.2
|
- php: 7.2
|
||||||
|
|
||||||
|
# run tests coverage on PHP 7.1
|
||||||
- php: 7.1
|
- php: 7.1
|
||||||
env: TASK_TESTS_COVERAGE=1
|
env: TASK_TESTS_COVERAGE=1
|
||||||
|
|
||||||
@ -110,7 +110,6 @@ matrix:
|
|||||||
|
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- php: nightly
|
- php: nightly
|
||||||
- php: 7.2
|
|
||||||
|
|
||||||
install:
|
install:
|
||||||
- |
|
- |
|
||||||
@ -178,6 +177,15 @@ before_script:
|
|||||||
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
|
PHPUNIT_FLAGS="--coverage-clover=coverage.clover"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Disable DEPRECATE messages during PHPUnit initialization on PHP 7.2. To fix them, PHPUnit should be updated to 6.*
|
||||||
|
# For Yii2 tests, messages will be enabled by tests/bootstrap.php
|
||||||
|
- |
|
||||||
|
if [ $TRAVIS_PHP_VERSION == 7.2 ]; then
|
||||||
|
echo 'Disabled DEPRECATED notifications for PHP 7.2';
|
||||||
|
echo 'error_reporting = E_ALL & ~E_DEPRECATED' >> /tmp/php-config.ini;
|
||||||
|
phpenv config-add /tmp/php-config.ini;
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# PHP tests
|
# PHP tests
|
||||||
|
@ -759,7 +759,9 @@ class ActiveQuery extends Query implements ActiveQueryInterface
|
|||||||
*/
|
*/
|
||||||
public function viaTable($tableName, $link, callable $callable = null)
|
public function viaTable($tableName, $link, callable $callable = null)
|
||||||
{
|
{
|
||||||
$relation = new self(get_class($this->primaryModel), [
|
$modelClass = $this->primaryModel !== null ? get_class($this->primaryModel) : get_class();
|
||||||
|
|
||||||
|
$relation = new self($modelClass, [
|
||||||
'from' => [$tableName],
|
'from' => [$tableName],
|
||||||
'link' => $link,
|
'link' => $link,
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
|
@ -624,7 +624,7 @@ class Container extends Component
|
|||||||
public function setDefinitions(array $definitions)
|
public function setDefinitions(array $definitions)
|
||||||
{
|
{
|
||||||
foreach ($definitions as $class => $definition) {
|
foreach ($definitions as $class => $definition) {
|
||||||
if (count($definition) === 2 && array_values($definition) === $definition) {
|
if (is_array($definition) && count($definition) === 2 && array_values($definition) === $definition) {
|
||||||
$this->set($class, $definition[0], $definition[1]);
|
$this->set($class, $definition[0], $definition[1]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -646,7 +646,7 @@ class Container extends Component
|
|||||||
public function setSingletons(array $singletons)
|
public function setSingletons(array $singletons)
|
||||||
{
|
{
|
||||||
foreach ($singletons as $class => $definition) {
|
foreach ($singletons as $class => $definition) {
|
||||||
if (count($definition) === 2 && array_values($definition) === $definition) {
|
if (is_array($definition) && count($definition) === 2 && array_values($definition) === $definition) {
|
||||||
$this->setSingleton($class, $definition[0], $definition[1]);
|
$this->setSingleton($class, $definition[0], $definition[1]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1529,7 +1529,14 @@ class Formatter extends Component
|
|||||||
|
|
||||||
$multipliers = array_values($this->measureUnits[$unitType][$unitSystem]);
|
$multipliers = array_values($this->measureUnits[$unitType][$unitSystem]);
|
||||||
|
|
||||||
list($params, $position) = $this->formatNumber($value * $baseUnit, $decimals, null, $multipliers, $options, $textOptions);
|
list($params, $position) = $this->formatNumber(
|
||||||
|
$this->normalizeNumericValue($value) * $baseUnit,
|
||||||
|
$decimals,
|
||||||
|
null,
|
||||||
|
$multipliers,
|
||||||
|
$options,
|
||||||
|
$textOptions
|
||||||
|
);
|
||||||
|
|
||||||
$message = $this->getUnitMessage($unitType, $unitFormat, $unitSystem, $position);
|
$message = $this->getUnitMessage($unitType, $unitFormat, $unitSystem, $position);
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ class EmailValidator extends Validator
|
|||||||
$valid = false;
|
$valid = false;
|
||||||
} else {
|
} else {
|
||||||
if ($this->enableIDN) {
|
if ($this->enableIDN) {
|
||||||
$matches['local'] = idn_to_ascii($matches['local']);
|
$matches['local'] = $this->idnToAscii($matches['local']);
|
||||||
$matches['domain'] = idn_to_ascii($matches['domain']);
|
$matches['domain'] = $this->idnToAscii($matches['domain']);
|
||||||
$value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];
|
$value = $matches['name'] . $matches['open'] . $matches['local'] . '@' . $matches['domain'] . $matches['close'];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,6 +104,17 @@ class EmailValidator extends Validator
|
|||||||
return $valid ? null : [$this->message, []];
|
return $valid ? null : [$this->message, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function idnToAscii($idn)
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50600) {
|
||||||
|
// TODO: drop old PHP versions support
|
||||||
|
return idn_to_ascii($idn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
@ -132,7 +132,7 @@ class UniqueValidator extends Validator
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->modelExists($targetClass, $conditions, $model)) {
|
if ($this->modelExists($targetClass, $conditions, $model)) {
|
||||||
if (count($targetAttribute) > 1) {
|
if (is_array($targetAttribute) && count($targetAttribute) > 1) {
|
||||||
$this->addComboNotUniqueError($model, $attribute);
|
$this->addComboNotUniqueError($model, $attribute);
|
||||||
} else {
|
} else {
|
||||||
$this->addError($model, $attribute, $this->message);
|
$this->addError($model, $attribute, $this->message);
|
||||||
|
@ -96,7 +96,7 @@ class UrlValidator extends Validator
|
|||||||
|
|
||||||
if ($this->enableIDN) {
|
if ($this->enableIDN) {
|
||||||
$value = preg_replace_callback('/:\/\/([^\/]+)/', function ($matches) {
|
$value = preg_replace_callback('/:\/\/([^\/]+)/', function ($matches) {
|
||||||
return '://' . idn_to_ascii($matches[1]);
|
return '://' . $this->idnToAscii($matches[1]);
|
||||||
}, $value);
|
}, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +108,16 @@ class UrlValidator extends Validator
|
|||||||
return [$this->message, []];
|
return [$this->message, []];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function idnToAscii($idn)
|
||||||
|
{
|
||||||
|
if (PHP_VERSION_ID < 50600) {
|
||||||
|
// TODO: drop old PHP versions support
|
||||||
|
return idn_to_ascii($idn);
|
||||||
|
}
|
||||||
|
|
||||||
|
return idn_to_ascii($idn, 0, INTL_IDNA_VARIANT_UTS46);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritdoc
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
@ -561,7 +561,7 @@ class User extends Component
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$data = json_decode($value, true);
|
$data = json_decode($value, true);
|
||||||
if (count($data) == 3) {
|
if (is_array($data) && count($data) == 3) {
|
||||||
list($id, $authKey, $duration) = $data;
|
list($id, $authKey, $duration) = $data;
|
||||||
/* @var $class IdentityInterface */
|
/* @var $class IdentityInterface */
|
||||||
$class = $this->identityClass;
|
$class = $this->identityClass;
|
||||||
|
@ -5,7 +5,8 @@
|
|||||||
convertErrorsToExceptions="true"
|
convertErrorsToExceptions="true"
|
||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
stopOnFailure="false">
|
stopOnFailure="false"
|
||||||
|
printerClass="yiiunit\ResultPrinter">
|
||||||
<testsuites>
|
<testsuites>
|
||||||
<testsuite name="Yii Test Suite">
|
<testsuite name="Yii Test Suite">
|
||||||
<directory>./tests</directory>
|
<directory>./tests</directory>
|
||||||
|
38
tests/ResultPrinter.php
Normal file
38
tests/ResultPrinter.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* @link http://www.yiiframework.com/
|
||||||
|
* @copyright Copyright (c) 2008 Yii Software LLC
|
||||||
|
* @license http://www.yiiframework.com/license/
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace yiiunit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ResultPrinter overrides \PHPUnit\TextUI\ResultPrinter constructor
|
||||||
|
* to change default output to STDOUT and prevent some tests from fail when
|
||||||
|
* they can not be executed after headers have been sent.
|
||||||
|
*/
|
||||||
|
class ResultPrinter extends \PHPUnit\TextUI\ResultPrinter
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
$out = null,
|
||||||
|
$verbose = false,
|
||||||
|
$colors = \PHPUnit\TextUI\ResultPrinter::COLOR_DEFAULT,
|
||||||
|
$debug = false,
|
||||||
|
$numberOfColumns = 80,
|
||||||
|
$reverse = false
|
||||||
|
) {
|
||||||
|
if ($out === null) {
|
||||||
|
$out = STDOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function flush()
|
||||||
|
{
|
||||||
|
if ($this->out !== STDOUT) {
|
||||||
|
parent::flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,10 +17,26 @@ namespace PHPUnit\Framework\Constraint {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace PHPUnit\TextUI {
|
||||||
|
if (!class_exists('\PHPUnit\TextUI\ResultPrinter') && class_exists('PHPUnit_TextUI_ResultPrinter')) {
|
||||||
|
class ResultPrinter extends \PHPUnit_TextUI_ResultPrinter
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PHPUnit\Framework\Error {
|
||||||
|
if (!class_exists('PHPUnit\Framework\Error\Notice') && class_exists('PHPUnit_Framework_Error_Notice')) {
|
||||||
|
class Notice extends \PHPUnit_Framework_Error_Notice
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace PHPUnit\Framework {
|
namespace PHPUnit\Framework {
|
||||||
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) {
|
if (!class_exists('PHPUnit\Framework\TestCase') && class_exists('PHPUnit_Framework_TestCase')) {
|
||||||
echo "Applying compatibility patch for PHPUnit 6...\n";
|
|
||||||
|
|
||||||
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
abstract class TestCase extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -84,8 +84,7 @@ trait ActiveRecordTestTrait
|
|||||||
$customer = $customerClass::findOne(5);
|
$customer = $customerClass::findOne(5);
|
||||||
$this->assertNull($customer);
|
$this->assertNull($customer);
|
||||||
$customer = $customerClass::findOne(['id' => [5, 6, 1]]);
|
$customer = $customerClass::findOne(['id' => [5, 6, 1]]);
|
||||||
// can't use assertCount() here since it will count model attributes instead
|
$this->assertInstanceOf($customerClass, $customer);
|
||||||
$this->assertEquals(1, count($customer));
|
|
||||||
$customer = $customerClass::find()->where(['id' => [5, 6, 1]])->one();
|
$customer = $customerClass::find()->where(['id' => [5, 6, 1]])->one();
|
||||||
$this->assertNotNull($customer);
|
$this->assertNotNull($customer);
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ trait GetTablesAliasTestTrait
|
|||||||
$query = $this->createQuery();
|
$query = $this->createQuery();
|
||||||
$query->from = new \stdClass();
|
$query->from = new \stdClass();
|
||||||
|
|
||||||
$this->setExpectedException('\yii\base\InvalidConfigException');
|
$this->expectException('\yii\base\InvalidConfigException');
|
||||||
|
|
||||||
$query->getTablesUsedInFrom();
|
$query->getTablesUsedInFrom();
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,8 @@ PHP
|
|||||||
|
|
||||||
public function testExceptionInvalidDataTypeInArray()
|
public function testExceptionInvalidDataTypeInArray()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('yii\base\InvalidConfigException', 'Invalid data type: yii\db\Connection. yii\base\Widget is expected.');
|
$this->expectException('yii\base\InvalidConfigException');
|
||||||
|
$this->expectExceptionMessage('Invalid data type: yii\db\Connection. yii\base\Widget is expected.');
|
||||||
Instance::ensure([
|
Instance::ensure([
|
||||||
'class' => Connection::className(),
|
'class' => Connection::className(),
|
||||||
], 'yii\base\Widget');
|
], 'yii\base\Widget');
|
||||||
|
@ -166,7 +166,7 @@ class PageCacheTest extends TestCase
|
|||||||
Yii::$app->response->cookies->add(new Cookie([
|
Yii::$app->response->cookies->add(new Cookie([
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'value' => $value,
|
'value' => $value,
|
||||||
'expire' => PHP_INT_MAX,
|
'expire' => strtotime('now +1 year'),
|
||||||
]));
|
]));
|
||||||
$cookies[$name] = $value;
|
$cookies[$name] = $value;
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ use yii\web\Request;
|
|||||||
use yii\web\Response;
|
use yii\web\Response;
|
||||||
use yii\web\User;
|
use yii\web\User;
|
||||||
use yiiunit\framework\filters\stubs\RateLimit;
|
use yiiunit\framework\filters\stubs\RateLimit;
|
||||||
|
use yiiunit\framework\filters\stubs\UserIdentity;
|
||||||
use yiiunit\TestCase;
|
use yiiunit\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -117,7 +118,7 @@ class RateLimiterTest extends TestCase
|
|||||||
->setAllowance([1, time() + 2]);
|
->setAllowance([1, time() + 2]);
|
||||||
$rateLimiter = new RateLimiter();
|
$rateLimiter = new RateLimiter();
|
||||||
|
|
||||||
$this->setExpectedException('yii\web\TooManyRequestsHttpException');
|
$this->expectException('yii\web\TooManyRequestsHttpException');
|
||||||
$rateLimiter->checkRateLimit($rateLimit, Yii::$app->request, Yii::$app->response, 'testAction');
|
$rateLimiter->checkRateLimit($rateLimit, Yii::$app->request, Yii::$app->response, 'testAction');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ class ArrayHelperTest extends TestCase
|
|||||||
|
|
||||||
public function testToArray()
|
public function testToArray()
|
||||||
{
|
{
|
||||||
$dataArrayable = $this->getMock('yii\\base\\Arrayable');
|
$dataArrayable = $this->getMockBuilder('yii\\base\\Arrayable')->getMock();
|
||||||
$dataArrayable->method('toArray')->willReturn([]);
|
$dataArrayable->method('toArray')->willReturn([]);
|
||||||
$this->assertEquals([], ArrayHelper::toArray($dataArrayable));
|
$this->assertEquals([], ArrayHelper::toArray($dataArrayable));
|
||||||
$this->assertEquals(['foo'], ArrayHelper::toArray('foo'));
|
$this->assertEquals(['foo'], ArrayHelper::toArray('foo'));
|
||||||
@ -810,20 +810,22 @@ class ArrayHelperTest extends TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This is expected to result in a PHP error.
|
* This is expected to result in a PHP error.
|
||||||
* @expectedException \PHPUnit_Framework_Error
|
* @requires PHPUnit 6.0
|
||||||
*/
|
*/
|
||||||
public function testGetValueNonexistingProperties1()
|
public function testGetValueNonexistingProperties1()
|
||||||
{
|
{
|
||||||
|
$this->expectException('PHPUnit\Framework\Error\Notice');
|
||||||
$object = new Post1();
|
$object = new Post1();
|
||||||
$this->assertEquals(null, ArrayHelper::getValue($object, 'nonExisting'));
|
$this->assertEquals(null, ArrayHelper::getValue($object, 'nonExisting'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is expected to result in a PHP error.
|
* This is expected to result in a PHP error.
|
||||||
* @expectedException \PHPUnit_Framework_Error
|
* @requires PHPUnit 6.0
|
||||||
*/
|
*/
|
||||||
public function testGetValueNonexistingProperties2()
|
public function testGetValueNonexistingProperties2()
|
||||||
{
|
{
|
||||||
|
$this->expectException('PHPUnit\Framework\Error\Notice');
|
||||||
$arrayObject = new \ArrayObject(['id' => 23], \ArrayObject::ARRAY_AS_PROPS);
|
$arrayObject = new \ArrayObject(['id' => 23], \ArrayObject::ARRAY_AS_PROPS);
|
||||||
$this->assertEquals(23, ArrayHelper::getValue($arrayObject, 'nonExisting'));
|
$this->assertEquals(23, ArrayHelper::getValue($arrayObject, 'nonExisting'));
|
||||||
}
|
}
|
||||||
|
@ -140,12 +140,17 @@ class HtmlTest extends TestCase
|
|||||||
|
|
||||||
public function testCsrfMetaTagsEnableCsrfValidationWithoutCookieValidationKey()
|
public function testCsrfMetaTagsEnableCsrfValidationWithoutCookieValidationKey()
|
||||||
{
|
{
|
||||||
$request = $this->getMock('yii\\web\\Request');
|
$this->mockApplication([
|
||||||
$request->method('enableCsrfValidation')->willReturn(true);
|
'components' => [
|
||||||
Yii::$app->set('request', $request);
|
'request' => [
|
||||||
$pattern = '<meta name="csrf-param" content="_csrf">%A<meta name="csrf-token">';
|
'class' => 'yii\web\Request',
|
||||||
$actual = Html::csrfMetaTags();
|
'enableCsrfValidation' => true,
|
||||||
$this->assertStringMatchesFormat($pattern, $actual);
|
]
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
$this->expectException('yii\base\InvalidConfigException');
|
||||||
|
$this->expectExceptionMessage('yii\web\Request::cookieValidationKey must be configured with a secret key.');
|
||||||
|
Html::csrfMetaTags();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1458,7 +1463,7 @@ EOD;
|
|||||||
$actual = Html::getAttributeValue($model, 'types');
|
$actual = Html::getAttributeValue($model, 'types');
|
||||||
$this->assertSame($expected, $actual);
|
$this->assertSame($expected, $actual);
|
||||||
|
|
||||||
$activeRecord = $this->getMock('yii\\db\\ActiveRecordInterface');
|
$activeRecord = $this->getMockBuilder('yii\\db\\ActiveRecordInterface')->getMock();
|
||||||
$activeRecord->method('getPrimaryKey')->willReturn(1);
|
$activeRecord->method('getPrimaryKey')->willReturn(1);
|
||||||
$model->types = $activeRecord;
|
$model->types = $activeRecord;
|
||||||
|
|
||||||
@ -1491,14 +1496,14 @@ EOD;
|
|||||||
*/
|
*/
|
||||||
public function testGetInputNameInvalidParamExceptionFormName()
|
public function testGetInputNameInvalidParamExceptionFormName()
|
||||||
{
|
{
|
||||||
$model = $this->getMock('yii\\base\\Model');
|
$model = $this->getMockBuilder('yii\\base\\Model')->getMock();
|
||||||
$model->method('formName')->willReturn('');
|
$model->method('formName')->willReturn('');
|
||||||
Html::getInputName($model, '[foo]bar');
|
Html::getInputName($model, '[foo]bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetInputName()
|
public function testGetInputName()
|
||||||
{
|
{
|
||||||
$model = $this->getMock('yii\\base\\Model');
|
$model = $this->getMockBuilder('yii\\base\\Model')->getMock();
|
||||||
$model->method('formName')->willReturn('');
|
$model->method('formName')->willReturn('');
|
||||||
$expected = 'types';
|
$expected = 'types';
|
||||||
$actual = Html::getInputName($model, 'types');
|
$actual = Html::getInputName($model, 'types');
|
||||||
|
@ -30,7 +30,7 @@ class JsonTest extends TestCase
|
|||||||
public function testEncode()
|
public function testEncode()
|
||||||
{
|
{
|
||||||
// Arrayable data encoding
|
// Arrayable data encoding
|
||||||
$dataArrayable = $this->getMock('yii\\base\\Arrayable');
|
$dataArrayable = $this->getMockBuilder('yii\\base\\Arrayable')->getMock();
|
||||||
$dataArrayable->method('toArray')->willReturn([]);
|
$dataArrayable->method('toArray')->willReturn([]);
|
||||||
$actual = Json::encode($dataArrayable);
|
$actual = Json::encode($dataArrayable);
|
||||||
$this->assertSame('{}', $actual);
|
$this->assertSame('{}', $actual);
|
||||||
|
@ -237,7 +237,8 @@ class FormatterTest extends TestCase
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Wrong value is casted properly',
|
'Wrong value is casted properly',
|
||||||
['NaN'], '0 millimeters', '0 mm'
|
['NaN'], '0 millimeters', '0 mm',
|
||||||
|
['yii\base\InvalidParamException', "'NaN' is not a numeric value"]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Negative value works',
|
'Negative value works',
|
||||||
@ -293,18 +294,26 @@ class FormatterTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider lengthDataProvider
|
* @dataProvider lengthDataProvider
|
||||||
*/
|
*/
|
||||||
public function testIntlAsLength($message, $arguments, $expected)
|
public function testIntlAsLength($message, $arguments, $expected, $_shortLength, $expectedException = [])
|
||||||
{
|
{
|
||||||
$this->ensureIntlUnitDataIsAvailable();
|
$this->ensureIntlUnitDataIsAvailable();
|
||||||
|
if ($expectedException !== []) {
|
||||||
|
$this->expectException($expectedException[0]);
|
||||||
|
$this->expectExceptionMessage($expectedException[1]);
|
||||||
|
}
|
||||||
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asLength'], $arguments), 'Failed asserting that ' . $message);
|
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asLength'], $arguments), 'Failed asserting that ' . $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider lengthDataProvider
|
* @dataProvider lengthDataProvider
|
||||||
*/
|
*/
|
||||||
public function testIntlAsShortLength($message, $arguments, $_, $expected)
|
public function testIntlAsShortLength($message, $arguments, $_length, $expected, $expectedException = [])
|
||||||
{
|
{
|
||||||
$this->ensureIntlUnitDataIsAvailable();
|
$this->ensureIntlUnitDataIsAvailable();
|
||||||
|
if ($expectedException !== []) {
|
||||||
|
$this->expectException($expectedException[0]);
|
||||||
|
$this->expectExceptionMessage($expectedException[1]);
|
||||||
|
}
|
||||||
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asShortLength'], $arguments), 'Failed asserting that ' . $message);
|
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asShortLength'], $arguments), 'Failed asserting that ' . $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +326,8 @@ class FormatterTest extends TestCase
|
|||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Wrong value is casted properly',
|
'Wrong value is casted properly',
|
||||||
['NaN'], '0 grams', '0 g'
|
['NaN'], '0 grams', '0 g',
|
||||||
|
['yii\base\InvalidParamException', "'NaN' is not a numeric value"]
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Negative value works',
|
'Negative value works',
|
||||||
@ -373,18 +383,26 @@ class FormatterTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @dataProvider weightDataProvider
|
* @dataProvider weightDataProvider
|
||||||
*/
|
*/
|
||||||
public function testIntlAsWeight($message, $arguments, $expected)
|
public function testIntlAsWeight($message, $arguments, $expected, $_shortWeight, $expectedException = [])
|
||||||
{
|
{
|
||||||
$this->ensureIntlUnitDataIsAvailable();
|
$this->ensureIntlUnitDataIsAvailable();
|
||||||
|
if ($expectedException !== []) {
|
||||||
|
$this->expectException($expectedException[0]);
|
||||||
|
$this->expectExceptionMessage($expectedException[1]);
|
||||||
|
}
|
||||||
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asWeight'], $arguments), 'Failed asserting that ' . $message);
|
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asWeight'], $arguments), 'Failed asserting that ' . $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dataProvider weightDataProvider
|
* @dataProvider weightDataProvider
|
||||||
*/
|
*/
|
||||||
public function testIntlAsShortWeight($message, $arguments, $_, $expected)
|
public function testIntlAsShortWeight($message, $arguments, $_weight, $expected, $expectedException = [])
|
||||||
{
|
{
|
||||||
$this->ensureIntlUnitDataIsAvailable();
|
$this->ensureIntlUnitDataIsAvailable();
|
||||||
|
if ($expectedException !== []) {
|
||||||
|
$this->expectException($expectedException[0]);
|
||||||
|
$this->expectExceptionMessage($expectedException[1]);
|
||||||
|
}
|
||||||
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asShortWeight'], $arguments), 'Failed asserting that ' . $message);
|
$this->assertSame($expected, call_user_func_array([$this->formatter, 'asShortWeight'], $arguments), 'Failed asserting that ' . $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,18 @@ namespace yiiunit\framework\i18n {
|
|||||||
{
|
{
|
||||||
static::$enableIntl = null;
|
static::$enableIntl = null;
|
||||||
if (strncmp($test->getName(false), 'testIntl', 8) === 0) {
|
if (strncmp($test->getName(false), 'testIntl', 8) === 0) {
|
||||||
|
static::$enableIntl = true;
|
||||||
|
|
||||||
|
if (version_compare(PHP_VERSION, '7.2.0.RC.1', '>=') && version_compare(PHP_VERSION, '7.2.0.RC.3', '<=')) {
|
||||||
|
// IntlDateFormatter::parse() is broken in PHP 7.2. Disabled INTL tests until regression is fixed:
|
||||||
|
// https://bugs.php.net/bug.php?id=75378
|
||||||
|
$test->markTestSkipped('intl extension is broken in PHP 7.2');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!extension_loaded('intl')) {
|
if (!extension_loaded('intl')) {
|
||||||
$test->markTestSkipped('intl extension is not installed.');
|
$test->markTestSkipped('intl extension is not installed.');
|
||||||
}
|
}
|
||||||
static::$enableIntl = true;
|
|
||||||
} else {
|
} else {
|
||||||
static::$enableIntl = false;
|
static::$enableIntl = false;
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class DataFilterTest extends TestCase
|
|||||||
$model = $builder->getSearchModel();
|
$model = $builder->getSearchModel();
|
||||||
$this->assertTrue($model instanceof DynamicModel);
|
$this->assertTrue($model instanceof DynamicModel);
|
||||||
|
|
||||||
$this->setExpectedException('yii\base\InvalidConfigException');
|
$this->expectException('yii\base\InvalidConfigException');
|
||||||
$builder->setSearchModel(new \stdClass());
|
$builder->setSearchModel(new \stdClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -388,15 +388,19 @@ class FileValidatorTest extends TestCase
|
|||||||
|
|
||||||
public function validMimeTypes()
|
public function validMimeTypes()
|
||||||
{
|
{
|
||||||
return [
|
return array_filter([
|
||||||
['test.svg', 'image/*', 'svg'],
|
['test.svg', 'image/*', 'svg'],
|
||||||
['test.jpg', 'image/*', 'jpg'],
|
['test.jpg', 'image/*', 'jpg'],
|
||||||
['test.png', 'image/*', 'png'],
|
['test.png', 'image/*', 'png'],
|
||||||
['test.png', 'IMAGE/*', 'png'],
|
['test.png', 'IMAGE/*', 'png'],
|
||||||
['test.txt', 'text/*', 'txt'],
|
['test.txt', 'text/*', 'txt'],
|
||||||
['test.xml', '*/xml', 'xml'],
|
// Disabled for PHP 7.2 RC because of regression:
|
||||||
|
// https://bugs.php.net/bug.php?id=75380
|
||||||
|
version_compare(PHP_VERSION, '7.2.0.RC.1', '>=') && version_compare(PHP_VERSION, '7.2.0.RC.3', '<=')
|
||||||
|
? null
|
||||||
|
: ['test.xml', '*/xml', 'xml'],
|
||||||
['test.odt', 'application/vnd*', 'odt'],
|
['test.odt', 'application/vnd*', 'odt'],
|
||||||
];
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function invalidMimeTypes()
|
public function invalidMimeTypes()
|
||||||
|
@ -1,2 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<tag></tag>
|
<application>
|
||||||
|
<message>
|
||||||
|
<from>SilverFire</from>
|
||||||
|
<to>World</to>
|
||||||
|
<body>Hello, world!</body>
|
||||||
|
</message>
|
||||||
|
</application>
|
||||||
|
@ -116,7 +116,7 @@ HTML
|
|||||||
$model = new DynamicModel(['name']);
|
$model = new DynamicModel(['name']);
|
||||||
$model->addRule(['name'], 'required');
|
$model->addRule(['name'], 'required');
|
||||||
|
|
||||||
$view = $this->getMock(View::className());
|
$view = $this->getMockBuilder(View::className())->getMock();
|
||||||
$view->method('registerJs')->with($this->matches("jQuery('#w0').yiiActiveForm([], {\"validateOnSubmit\":false});"));
|
$view->method('registerJs')->with($this->matches("jQuery('#w0').yiiActiveForm([], {\"validateOnSubmit\":false});"));
|
||||||
$view->method('registerAssetBundle')->willReturn(true);
|
$view->method('registerAssetBundle')->willReturn(true);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user