Yii2 framework backup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

207 lines
7.3 KiB

<?php
Added php-cs-fixer coding standards validation to Travis CI (#14100) * php-cs-fixer: PSR2 rule. * php-cs-fixer: PSR2 rule - fix views. * Travis setup refactoring. * Add php-cs-fixer to travis cs tests. * Fix tests on hhvm-3.12 * improve travis config * composer update * revert composer update * improve travis config * Fix CS. * Extract config to separate classes. * Extract config to separate classes. * Add file header. * Force short array syntax. * binary_operator_spaces fixer * Fix broken tests * cast_spaces fixer * concat_space fixer * dir_constant fixer * ereg_to_preg fixer * function_typehint_space fixer * hash_to_slash_comment fixer * is_null fixer * linebreak_after_opening_tag fixer * lowercase_cast fixer * magic_constant_casing fixer * modernize_types_casting fixer * native_function_casing fixer * new_with_braces fixer * no_alias_functions fixer * no_blank_lines_after_class_opening fixer * no_blank_lines_after_phpdoc fixer * no_empty_comment fixer * no_empty_phpdoc fixer * no_empty_statement fixer * no_extra_consecutive_blank_lines fixer * no_leading_import_slash fixer * no_leading_namespace_whitespace fixer * no_mixed_echo_print fixer * no_multiline_whitespace_around_double_arrow fixer * no_multiline_whitespace_before_semicolons fixer * no_php4_constructor fixer * no_short_bool_cast fixer * no_singleline_whitespace_before_semicolons fixer * no_spaces_around_offset fixer * no_trailing_comma_in_list_call fixer * no_trailing_comma_in_singleline_array fixer * no_unneeded_control_parentheses fixer * no_unused_imports fixer * no_useless_return fixer * no_whitespace_before_comma_in_array fixer * no_whitespace_in_blank_line fixer * not_operator_with_successor_space fixer * object_operator_without_whitespace fixer * ordered_imports fixer * php_unit_construct fixer * php_unit_dedicate_assert fixer * php_unit_fqcn_annotation fixer * phpdoc_indent fixer * phpdoc_no_access fixer * phpdoc_no_empty_return fixer * phpdoc_no_package fixer * phpdoc_no_useless_inheritdoc fixer * Fix broken tests * phpdoc_return_self_reference fixer * phpdoc_single_line_var_spacing fixer * phpdoc_single_line_var_spacing fixer * phpdoc_to_comment fixer * phpdoc_trim fixer * phpdoc_var_without_name fixer * psr4 fixer * self_accessor fixer * short_scalar_cast fixer * single_blank_line_before_namespace fixer * single_quote fixer * standardize_not_equals fixer * ternary_operator_spaces fixer * trailing_comma_in_multiline_array fixer * trim_array_spaces fixer * protected_to_private fixer * unary_operator_spaces fixer * whitespace_after_comma_in_array fixer * `parent::setRules()` -> `$this->setRules()` * blank_line_after_opening_tag fixer * Update finder config. * Revert changes for YiiRequirementChecker. * Fix array formatting. * Add missing import. * Fix CS for new code merged from master. * Fix some indentation issues.
7 years ago
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
require_once __DIR__ . '/../../../framework/requirements/YiiRequirementChecker.php';
use yiiunit\TestCase;
/**
* Test case for [[YiiRequirementChecker]].
* @see YiiRequirementChecker
* @group requirements
*/
class YiiRequirementCheckerTest extends TestCase
{
public function testCheck()
{
$requirementsChecker = new YiiRequirementChecker();
$requirements = [
'requirementPass' => [
'name' => 'Requirement 1',
'mandatory' => true,
'condition' => true,
'by' => 'Requirement 1',
'memo' => 'Requirement 1',
],
'requirementError' => [
'name' => 'Requirement 2',
'mandatory' => true,
'condition' => false,
'by' => 'Requirement 2',
'memo' => 'Requirement 2',
],
'requirementWarning' => [
'name' => 'Requirement 3',
'mandatory' => false,
'condition' => false,
'by' => 'Requirement 3',
'memo' => 'Requirement 3',
],
];
$checkResult = $requirementsChecker->check($requirements)->getResult();
$summary = $checkResult['summary'];
$this->assertCount($summary['total'], $requirements, 'Wrong summary total!');
$this->assertEquals(1, $summary['errors'], 'Wrong summary errors!');
$this->assertEquals(1, $summary['warnings'], 'Wrong summary warnings!');
$checkedRequirements = $checkResult['requirements'];
$requirementsKeys = array_flip(array_keys($requirements));
$this->assertFalse($checkedRequirements[$requirementsKeys['requirementPass']]['error'], 'Passed requirement has an error!');
$this->assertFalse($checkedRequirements[$requirementsKeys['requirementPass']]['warning'], 'Passed requirement has a warning!');
$this->assertTrue($checkedRequirements[$requirementsKeys['requirementError']]['error'], 'Error requirement has no error!');
$this->assertFalse($checkedRequirements[$requirementsKeys['requirementWarning']]['error'], 'Error requirement has an error!');
$this->assertTrue($checkedRequirements[$requirementsKeys['requirementWarning']]['warning'], 'Error requirement has no warning!');
}
/**
* @depends testCheck
*/
public function testCheckEval()
{
$requirementsChecker = new YiiRequirementChecker();
$requirements = [
'requirementPass' => [
'name' => 'Requirement 1',
'mandatory' => true,
'condition' => 'eval:2>1',
'by' => 'Requirement 1',
'memo' => 'Requirement 1',
],
'requirementError' => [
'name' => 'Requirement 2',
'mandatory' => true,
'condition' => 'eval:2<1',
'by' => 'Requirement 2',
'memo' => 'Requirement 2',
],
];
$checkResult = $requirementsChecker->check($requirements)->getResult();
$checkedRequirements = $checkResult['requirements'];
$requirementsKeys = array_flip(array_keys($requirements));
$this->assertFalse($checkedRequirements[$requirementsKeys['requirementPass']]['error'], 'Passed requirement has an error!');
$this->assertFalse($checkedRequirements[$requirementsKeys['requirementPass']]['warning'], 'Passed requirement has a warning!');
$this->assertTrue($checkedRequirements[$requirementsKeys['requirementError']]['error'], 'Error requirement has no error!');
}
/**
* @depends testCheck
*/
public function testCheckChained()
{
$requirementsChecker = new YiiRequirementChecker();
$requirements1 = [
[
'name' => 'Requirement 1',
'mandatory' => true,
'condition' => true,
'by' => 'Requirement 1',
'memo' => 'Requirement 1',
],
];
$requirements2 = [
[
'name' => 'Requirement 2',
'mandatory' => true,
'condition' => true,
'by' => 'Requirement 2',
'memo' => 'Requirement 2',
],
];
$checkResult = $requirementsChecker->check($requirements1)->check($requirements2)->getResult();
$mergedRequirements = array_merge($requirements1, $requirements2);
$this->assertCount($checkResult['summary']['total'], $mergedRequirements, 'Wrong total checks count!');
foreach ($mergedRequirements as $key => $mergedRequirement) {
$this->assertEquals($mergedRequirement['name'], $checkResult['requirements'][$key]['name'], 'Wrong requirements list!');
}
}
public function testCheckPhpExtensionVersion()
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped('Can not test this on HHVM.');
}
$requirementsChecker = new YiiRequirementChecker();
$this->assertFalse($requirementsChecker->checkPhpExtensionVersion('some_unexisting_php_extension', '0.1'), 'No fail while checking unexisting extension!');
$this->assertTrue($requirementsChecker->checkPhpExtensionVersion('pdo', '1.0'), 'Unable to check PDO version!');
}
/**
* Data provider for [[testGetByteSize()]].
* @return array
*/
public function dataProviderGetByteSize()
{
return [
['456', 456],
Added php-cs-fixer coding standards validation to Travis CI (#14100) * php-cs-fixer: PSR2 rule. * php-cs-fixer: PSR2 rule - fix views. * Travis setup refactoring. * Add php-cs-fixer to travis cs tests. * Fix tests on hhvm-3.12 * improve travis config * composer update * revert composer update * improve travis config * Fix CS. * Extract config to separate classes. * Extract config to separate classes. * Add file header. * Force short array syntax. * binary_operator_spaces fixer * Fix broken tests * cast_spaces fixer * concat_space fixer * dir_constant fixer * ereg_to_preg fixer * function_typehint_space fixer * hash_to_slash_comment fixer * is_null fixer * linebreak_after_opening_tag fixer * lowercase_cast fixer * magic_constant_casing fixer * modernize_types_casting fixer * native_function_casing fixer * new_with_braces fixer * no_alias_functions fixer * no_blank_lines_after_class_opening fixer * no_blank_lines_after_phpdoc fixer * no_empty_comment fixer * no_empty_phpdoc fixer * no_empty_statement fixer * no_extra_consecutive_blank_lines fixer * no_leading_import_slash fixer * no_leading_namespace_whitespace fixer * no_mixed_echo_print fixer * no_multiline_whitespace_around_double_arrow fixer * no_multiline_whitespace_before_semicolons fixer * no_php4_constructor fixer * no_short_bool_cast fixer * no_singleline_whitespace_before_semicolons fixer * no_spaces_around_offset fixer * no_trailing_comma_in_list_call fixer * no_trailing_comma_in_singleline_array fixer * no_unneeded_control_parentheses fixer * no_unused_imports fixer * no_useless_return fixer * no_whitespace_before_comma_in_array fixer * no_whitespace_in_blank_line fixer * not_operator_with_successor_space fixer * object_operator_without_whitespace fixer * ordered_imports fixer * php_unit_construct fixer * php_unit_dedicate_assert fixer * php_unit_fqcn_annotation fixer * phpdoc_indent fixer * phpdoc_no_access fixer * phpdoc_no_empty_return fixer * phpdoc_no_package fixer * phpdoc_no_useless_inheritdoc fixer * Fix broken tests * phpdoc_return_self_reference fixer * phpdoc_single_line_var_spacing fixer * phpdoc_single_line_var_spacing fixer * phpdoc_to_comment fixer * phpdoc_trim fixer * phpdoc_var_without_name fixer * psr4 fixer * self_accessor fixer * short_scalar_cast fixer * single_blank_line_before_namespace fixer * single_quote fixer * standardize_not_equals fixer * ternary_operator_spaces fixer * trailing_comma_in_multiline_array fixer * trim_array_spaces fixer * protected_to_private fixer * unary_operator_spaces fixer * whitespace_after_comma_in_array fixer * `parent::setRules()` -> `$this->setRules()` * blank_line_after_opening_tag fixer * Update finder config. * Revert changes for YiiRequirementChecker. * Fix array formatting. * Add missing import. * Fix CS for new code merged from master. * Fix some indentation issues.
7 years ago
['5K', 5 * 1024],
['16KB', 16 * 1024],
['4M', 4 * 1024 * 1024],
['14MB', 14 * 1024 * 1024],
['7G', 7 * 1024 * 1024 * 1024],
['12GB', 12 * 1024 * 1024 * 1024],
];
}
/**
* @dataProvider dataProviderGetByteSize
*
* @param string $verboseValue verbose value.
* @param int $expectedByteSize expected byte size.
*/
public function testGetByteSize($verboseValue, $expectedByteSize)
{
$requirementsChecker = new YiiRequirementChecker();
$this->assertEquals($expectedByteSize, $requirementsChecker->getByteSize($verboseValue), "Wrong byte size for '{$verboseValue}'!");
}
/**
* Data provider for [[testCompareByteSize()]]
* @return array
*/
public function dataProviderCompareByteSize()
{
return [
['2M', '2K', '>', true],
['2M', '2K', '>=', true],
['1K', '1024', '==', true],
['10M', '11M', '<', true],
['10M', '11M', '<=', true],
];
}
/**
* @depends testGetByteSize
* @dataProvider dataProviderCompareByteSize
*
* @param string $a first value.
* @param string $b second value.
* @param string $compare comparison.
* @param bool $expectedComparisonResult expected comparison result.
*/
public function testCompareByteSize($a, $b, $compare, $expectedComparisonResult)
{
$requirementsChecker = new YiiRequirementChecker();
$this->assertEquals($expectedComparisonResult, $requirementsChecker->compareByteSize($a, $b, $compare), "Wrong compare '{$a}{$compare}{$b}'");
}
}