Skip to content

Commit 8d6330e

Browse files
committedJan 7, 2024
fix(test): fail on php errors
1 parent a60ff02 commit 8d6330e

27 files changed

+127
-44
lines changed
 

‎.github/workflows/continuous-integration.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ jobs:
2828
services:
2929
memcached:
3030
image: "memcached:${{ matrix.memcached-version }}"
31+
ports:
32+
- 11211:11211
3133

3234
steps:
3335
- name: Checkout
@@ -40,7 +42,7 @@ jobs:
4042
with:
4143
php-version: "${{ matrix.php-version }}"
4244
extensions: apcu
43-
ini-values: apc.enable_cli=1
45+
ini-values: error_reporting=5111,apc.enable_cli=on,apc.use_request_time=off,memory_limit=-1,short_open_tag=off,magic_quotes_gpc=off,date.timezone="UTC"
4446

4547
- name: Get composer cache directory
4648
id: composer-cache

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/lib/*/doctrine/*/base/
55
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/cache/
66
lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/
7+
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/data/*.sqlite*
78
/vendor
89
/composer.lock
910
.php-cs-fixer.cache

‎docker-compose.yml

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ services:
2828
{
2929
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
3030
echo 'memory_limit = -1'
31+
echo 'error_reporting = '`
32+
php -r 'echo (E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE;'
33+
`
3134
echo 'short_open_tag = off'
3235
echo 'magic_quotes_gpc = off'
3336
echo 'date.timezone = "UTC"'
@@ -57,6 +60,9 @@ services:
5760
{
5861
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
5962
echo 'memory_limit = -1'
63+
echo 'error_reporting = '`
64+
php -r 'echo (E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE;'
65+
`
6066
echo 'short_open_tag = off'
6167
echo 'magic_quotes_gpc = off'
6268
echo 'date.timezone = "UTC"'

‎lib/autoload/sfCoreAutoload.class.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ class sfCoreAutoload
194194
'sfwebdebuglogger' => 'log/sfWebDebugLogger.class.php',
195195
'sfmailer' => 'mailer/sfMailer.class.php',
196196
'sfmailermessageloggerplugin' => 'mailer/sfMailerMessageLoggerPlugin.class.php',
197+
'sfmailerswiftmessage' => 'mailer/sfMailerSwiftMessage.php',
197198
'sfnomailer' => 'mailer/sfNoMailer.class.php',
198199
'sfpearconfig' => 'plugin/sfPearConfig.class.php',
199200
'sfpeardownloader' => 'plugin/sfPearDownloader.class.php',
@@ -373,8 +374,8 @@ class sfCoreAutoload
373374
'sfwidgetforminput' => 'widget/sfWidgetFormInput.class.php',
374375
'sfwidgetforminputcheckbox' => 'widget/sfWidgetFormInputCheckbox.class.php',
375376
'sfwidgetforminputfile' => 'widget/sfWidgetFormInputFile.class.php',
376-
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
377377
'sfwidgetforminputfileeditable' => 'widget/sfWidgetFormInputFileEditable.class.php',
378+
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
378379
'sfwidgetforminputhidden' => 'widget/sfWidgetFormInputHidden.class.php',
379380
'sfwidgetforminputpassword' => 'widget/sfWidgetFormInputPassword.class.php',
380381
'sfwidgetforminputread' => 'widget/sfWidgetFormInputRead.class.php',
@@ -521,11 +522,11 @@ public static function make()
521522
if (false !== stripos($contents, 'class '.$class)
522523
|| false !== stripos($contents, 'interface '.$class)
523524
|| false !== stripos($contents, 'trait '.$class)) {
524-
$classes .= sprintf(" '%s' => '%s',\n", strtolower($class), substr(str_replace($libDir, '', $file), 1));
525+
$classes .= sprintf(" '%s' => '%s',\n", strtolower($class), substr(str_replace($libDir, '', $file), 1));
525526
}
526527
}
527528

528-
$content = preg_replace('/protected \$classes = array *\(.*?\);/s', sprintf("protected \$classes = array(\n%s );", $classes), file_get_contents(__FILE__));
529+
$content = preg_replace('/protected \$classes = array *\(.*?\);/s', sprintf("protected \$classes = array(\n%s );", $classes), file_get_contents(__FILE__));
529530

530531
file_put_contents(__FILE__, $content);
531532
}

‎lib/config/autoload/swift.php

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
3+
if (!class_exists('Swift')) {
4+
$swift_dir = sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib';
5+
require_once $swift_dir.'/swift_required.php';
6+
}

‎lib/config/sfFactoryConfigHandler.class.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,7 @@ public function execute($configFiles)
224224

225225
case 'mailer':
226226
$instances[] = sprintf(
227-
"if (!class_exists('Swift')) {\n".
228-
" \$swift_dir = sfConfig::get('sf_swiftmailer_dir', sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib');\n".
229-
" require_once \$swift_dir.'/swift_required.php';\n".
230-
"}\n".
227+
preg_replace('/<\?php\s*/', '', file_get_contents(__DIR__.'/autoload/swift.php')).
231228
"\$this->setMailerConfiguration(array_merge(array('class' => sfConfig::get('sf_factory_mailer', '%s')), sfConfig::get('sf_factory_mailer_parameters', %s)));\n",
232229
$class,
233230
var_export($parameters, true)

‎lib/mailer/sfMailer.class.php

100755100644
+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct(sfEventDispatcher $dispatcher, $options)
5858
'logging' => false,
5959
'delivery_strategy' => self::REALTIME,
6060
'transport' => array(
61-
'class' => 'Swift_MailTransport',
61+
'class' => class_exists('Swift_MailTransport') ? 'Swift_MailTransport' : 'Swift_SmtpTransport',
6262
'param' => array(),
6363
),
6464
), $options);
@@ -262,7 +262,7 @@ public function sendNextImmediately()
262262
*
263263
* @return false|int The number of sent emails
264264
*/
265-
public function send($message, &$failedRecipients = null)
265+
public function send(sfMailerSwiftMessage $message, &$failedRecipients = null)
266266
{
267267
if ($this->force) {
268268
$this->force = false;

‎lib/mailer/sfMailerSwiftMessage.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the symfony package.
5+
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
11+
class_exists('Swift');
12+
13+
if (version_compare(Swift::VERSION, '6.0.0') >= 0) {
14+
class_alias('Swift_Mime_SimpleMessage', 'sfMailerSwiftMessage');
15+
} else {
16+
class_alias('Swift_Mime_Message', 'sfMailerSwiftMessage');
17+
}

‎lib/plugins/sfDoctrinePlugin/lib/mailer/Swift_DoctrineSpool.class.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,9 @@ public function stop()
6969
/**
7070
* Stores a message in the queue.
7171
*
72-
* @param Swift_Mime_Message $message The message to store
72+
* @param Swift_Mime_Message|Swift_Mime_SimpleMessage $message The message to store
7373
*/
74-
public function queueMessage(Swift_Mime_Message $message)
74+
public function queueMessage(sfMailerSwiftMessage $message)
7575
{
7676
$object = new $this->model();
7777

‎lib/plugins/sfDoctrinePlugin/test/functional/fixtures/apps/backend/config/settings.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dev:
1313

1414
test:
1515
.settings:
16-
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
16+
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
1717
cache: false
1818
web_debug: false
1919
no_script_name: false

‎lib/plugins/sfDoctrinePlugin/test/functional/fixtures/apps/frontend/config/settings.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dev:
1313

1414
test:
1515
.settings:
16-
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
16+
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
1717
cache: false
1818
web_debug: false
1919
no_script_name: false

‎lib/storage/sfCacheSessionStorage.class.php

+14-9
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,7 @@ public function initialize($options = array())
9999
}
100100

101101
if (empty($this->id)) {
102-
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'localhost';
103-
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';
104-
105-
// generate new id based on random # / ip / user agent / secret
106-
$this->id = md5(mt_rand(0, 999999).$ip.$ua.$this->options['session_cookie_secret']);
102+
$this->id = $this->generateId();
107103

108104
if (sfConfig::get('sf_logging_enabled')) {
109105
$this->dispatcher->notify(new sfEvent($this, 'application.log', array('New session created')));
@@ -224,10 +220,7 @@ public function regenerate($destroy = false)
224220
$this->cache->remove($this->id);
225221
}
226222

227-
// generate session id
228-
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';
229-
230-
$this->id = md5(mt_rand(0, 999999).$_SERVER['REMOTE_ADDR'].$ua.$this->options['session_cookie_secret']);
223+
$this->id = $this->generateId();
231224

232225
// save data to cache
233226
$this->cache->set($this->id, serialize($this->data));
@@ -275,4 +268,16 @@ public function shutdown()
275268
}
276269
}
277270
}
271+
272+
/**
273+
* @return string
274+
*/
275+
private function generateId()
276+
{
277+
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'localhost';
278+
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';
279+
280+
// generate new id based on random # / ip / user agent / secret
281+
return md5(mt_rand(0, 999999).$ip.$ua.$this->options['session_cookie_secret']);
282+
}
278283
}

‎lib/task/sfCommandApplicationTask.class.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,7 @@ protected function getMailer()
142142
*/
143143
protected function initializeMailer()
144144
{
145-
if (!class_exists('Swift')) {
146-
$swift_dir = sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib';
147-
148-
require_once $swift_dir.'/swift_required.php';
149-
}
145+
require_once sfConfig::get('sf_symfony_lib_dir').'/config/autoload/swift.php';
150146

151147
$config = $this->getFactoryConfiguration();
152148

‎lib/validator/sfValidatorFile.class.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,14 @@ protected function configure($options = array(), $messages = array())
9696
*/
9797
protected function doClean($value)
9898
{
99-
if (!is_array($value) || !isset($value['tmp_name'])) {
99+
if (!is_array($value)) {
100100
throw new sfValidatorError($this, 'invalid', array('value' => (string) $value));
101101
}
102102

103+
if (!isset($value['tmp_name'])) {
104+
throw new sfValidatorError($this, 'invalid', array('value' => 'Array'));
105+
}
106+
103107
if (!isset($value['name'])) {
104108
$value['name'] = '';
105109
}

‎lib/validator/sfValidatorSchema.class.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ public function clean($values)
8989
*/
9090
public function preClean($values)
9191
{
92-
if (null === $validator = $this->getPreValidator()) {
92+
$validator = $this->getPreValidator();
93+
94+
if (null === $validator) {
9395
return $values;
9496
}
9597

@@ -110,7 +112,9 @@ public function preClean($values)
110112
*/
111113
public function postClean($values)
112114
{
113-
if (null === $validator = $this->getPostValidator()) {
115+
$validator = $this->getPostValidator();
116+
117+
if (null === $validator) {
114118
return $values;
115119
}
116120

@@ -355,8 +359,14 @@ protected function doClean($values)
355359
protected function getBytes($value)
356360
{
357361
$value = trim($value);
362+
$length = strlen($value);
363+
364+
if (0 === $length) {
365+
return 0.0;
366+
}
367+
358368
$number = (float) $value;
359-
$modifier = strtolower($value[strlen($value) - 1]);
369+
$modifier = strtolower($value[$length - 1]);
360370

361371
$exp_by_modifier = array(
362372
'k' => 1,

‎lib/vendor/lime/lime.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function __construct($plan = null, $options = array())
4242
'force_colors' => false,
4343
'output' => null,
4444
'verbose' => false,
45-
'error_reporting' => false,
45+
'error_reporting' => true,
4646
), $options);
4747

4848
$this->output = $this->options['output'] ? $this->options['output'] : new lime_output($this->options['force_colors']);
@@ -140,6 +140,7 @@ public function __destruct()
140140
$plan = $this->results['stats']['plan'];
141141
$passed = count($this->results['stats']['passed']);
142142
$failed = count($this->results['stats']['failed']);
143+
$errors = count($this->results['stats']['errors']);
143144
$total = $this->results['stats']['total'];
144145
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan));
145146

@@ -156,6 +157,10 @@ public function __destruct()
156157
{
157158
$this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed));
158159
}
160+
else if ($errors)
161+
{
162+
$this->output->red_bar(sprintf("# Looks like test pass but with %d errors.", $errors));
163+
}
159164
else if ($total == $plan)
160165
{
161166
$this->output->green_bar("# Looks like everything went fine.");
@@ -174,10 +179,11 @@ private function getExitCode()
174179
{
175180
$plan = $this->results['stats']['plan'];
176181
$failed = count($this->results['stats']['failed']);
182+
$errors = count($this->results['stats']['errors']);
177183
$total = $this->results['stats']['total'];
178184
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan));
179185

180-
if ($failed)
186+
if ($failed || $errors)
181187
{
182188
return 1;
183189
}
@@ -608,6 +614,12 @@ public function handle_error($code, $message, $file, $line, $context = null)
608614
case E_WARNING:
609615
$type = 'Warning';
610616
break;
617+
case E_STRICT:
618+
$type = 'Strict';
619+
break;
620+
case E_DEPRECATED:
621+
$type = 'Deprecated';
622+
break;
611623
default:
612624
$type = 'Notice';
613625
break;

‎require_for_php8.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
swiftmailer/swiftmailer:^5.4.6
2+
egulias/email-validator:^2.1.10

‎test/bootstrap/functional.php

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* file that was distributed with this source code.
99
*/
1010

11+
if (!defined('SF_TEST_WITHOUT_COMPOSER')) {
12+
require_once __DIR__.'/../../vendor/autoload.php';
13+
}
14+
1115
// setup expected test environment (per check_configuration.php)
1216
ini_set('magic_quotes_runtime', 'off');
1317
ini_set('session.auto_start', 'off');

‎test/bootstrap/unit.php

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* file that was distributed with this source code.
99
*/
1010

11+
if (!defined('SF_TEST_WITHOUT_COMPOSER')) {
12+
require_once __DIR__.'/../../vendor/autoload.php';
13+
}
14+
1115
// setup expected test environment (per check_configuration.php)
1216
ini_set('magic_quotes_runtime', 'off');
1317
ini_set('session.auto_start', 'off');

‎test/functional/fixtures/apps/cache/config/settings.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@ prod:
55

66
dev:
77
.settings:
8-
# E_ALL | E_STRICT = 4095
9-
error_reporting: 4095
8+
error_reporting: <?php echo (E_ALL | E_STRICT)."\n" ?>
109
web_debug: true
1110
cache: true
1211
no_script_name: false
1312
etag: true
1413

1514
test:
1615
.settings:
17-
# E_ALL | E_STRICT = 4095
18-
error_reporting: 4095
16+
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
1917
web_debug: false
2018
cache: true
2119
no_script_name: false

‎test/functional/fixtures/apps/frontend/config/settings.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dev:
1313

1414
test:
1515
.settings:
16-
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
16+
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
1717
cache: false
1818
web_debug: false
1919
no_script_name: false

‎test/functional/fixtures/apps/i18n/config/settings.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ dev:
1313

1414
test:
1515
.settings:
16-
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
16+
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
1717
cache: false
1818
web_debug: false
1919
no_script_name: false

‎test/unit/mailer/fixtures/TestMailMessage.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
class TestMailMessage
1111
{
12-
public function setMessage(Swift_Mime_Message $message)
12+
public function setMessage(sfMailerSwiftMessage $message)
1313
{
1414
}
1515

0 commit comments

Comments
 (0)