1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* Hhvm ini_get/ini_set compatibility test
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*
*/
namespace Magento\Test\Integrity;
use Magento\Framework\App\Utility\Files;
class HhvmCompatibilityTest extends \PHPUnit\Framework\TestCase
{
/**
* @var array
*/
protected $allowedDirectives = [
'session.cookie_secure',
'session.cookie_httponly',
'session.use_cookies',
'session.use_only_cookies',
'session.referer_check',
'session.save_path',
'session.save_handler',
'session.cookie_lifetime',
'session.cookie_secure',
'date.timezone',
'memory_limit',
'max_execution_time',
'short_open_tag',
'disable_functions',
'asp_tags',
'apc.enabled',
'eaccelerator.enable',
'mime_magic.magicfile',
'display_errors',
'default_socket_timeout',
'pcre.recursion_limit',
'default_charset',
/*
There is not way to specify calculation/serialization precision in hhvm.
Adding to whitelist in order to align precisions in php.
*/
'precision',
'serialize_precision',
];
/**
* Whitelist of variables allowed in files.
*
* @var array
*/
private $whitelistVarsInFiles = [
'max_input_vars' => [
'integration/testsuite/Magento/Swatches/Controller/Adminhtml/Product/AttributeTest.php',
'integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/AttributeTest.php',
]
];
/**
* Test allowed directives.
*
* @SuppressWarnings(PHPMD.NPathComplexity)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function testAllowedIniGetSetDirectives()
{
$deniedDirectives = [];
foreach ($this->getFiles() as $file) {
$fileDirectives = $this->parseDirectives($file);
if ($fileDirectives) {
$fileDeniedDirectives = array_diff($fileDirectives, $this->allowedDirectives);
if ($fileDeniedDirectives) {
$deniedDirectivesInFile = array_unique($fileDeniedDirectives);
foreach ($deniedDirectivesInFile as $key => $deniedDirective) {
if (isset($this->whitelistVarsInFiles[$deniedDirective])) {
foreach ($this->whitelistVarsInFiles[$deniedDirective] as $whitelistFile) {
if (strpos($file, $whitelistFile) !== false) {
unset($deniedDirectivesInFile[$key]);
}
}
}
}
if ($deniedDirectivesInFile) {
$deniedDirectives[$file] = $deniedDirectivesInFile;
}
}
}
}
if ($deniedDirectives) {
$this->fail($this->createMessage($deniedDirectives));
}
}
/**
* @return array
*/
protected function getFiles()
{
return \array_merge(
Files::init()->getPhpFiles(
Files::INCLUDE_APP_CODE
| Files::INCLUDE_PUB_CODE
| Files::INCLUDE_LIBS
| Files::INCLUDE_TEMPLATES
| Files::INCLUDE_TESTS
| Files::INCLUDE_NON_CLASSES
),
Files::init()->getPhtmlFiles(false, false),
Files::init()->getFiles([BP . '/dev/'], '*.php')
);
}
/**
* @param string $file
* @return null|array
*/
protected function parseDirectives($file)
{
$content = file_get_contents($file);
$pattern = '/ini_[g|s]et\(\s*[\'|"]([\w\._]+?)[\'|"][\s\w,\'"]*\)/';
preg_match_all($pattern, $content, $matches);
return $matches ? $matches[1] : null;
}
/**
* @param array $deniedDirectives
* @return string
*/
protected function createMessage($deniedDirectives)
{
$message = 'HHVM-incompatible ini_get/ini_set options were found:';
foreach ($deniedDirectives as $file => $fileDeniedDirectives) {
$message .= "\n" . $file . ': [' . implode(', ', $fileDeniedDirectives) . ']';
}
return $message;
}
}