Skip to content

Commit b8b25b3

Browse files
committed
fix(test): fail on php errors
1 parent 136b3c1 commit b8b25b3

27 files changed

+127
-44
lines changed

.github/workflows/continuous-integration.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
services:
2828
memcached:
2929
image: "memcached:${{ matrix.memcached-version }}"
30+
ports:
31+
- 11211:11211
3032

3133
steps:
3234
- name: Checkout
@@ -39,7 +41,7 @@ jobs:
3941
with:
4042
php-version: "${{ matrix.php-version }}"
4143
extensions: apcu
42-
ini-values: apc.enable_cli=1
44+
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"
4345

4446
- name: Get composer cache directory
4547
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
@@ -192,6 +192,7 @@ class sfCoreAutoload
192192
'sfwebdebuglogger' => 'log/sfWebDebugLogger.class.php',
193193
'sfmailer' => 'mailer/sfMailer.class.php',
194194
'sfmailermessageloggerplugin' => 'mailer/sfMailerMessageLoggerPlugin.class.php',
195+
'sfmailerswiftmessage' => 'mailer/sfMailerSwiftMessage.php',
195196
'sfnomailer' => 'mailer/sfNoMailer.class.php',
196197
'sfpearconfig' => 'plugin/sfPearConfig.class.php',
197198
'sfpeardownloader' => 'plugin/sfPearDownloader.class.php',
@@ -371,8 +372,8 @@ class sfCoreAutoload
371372
'sfwidgetforminput' => 'widget/sfWidgetFormInput.class.php',
372373
'sfwidgetforminputcheckbox' => 'widget/sfWidgetFormInputCheckbox.class.php',
373374
'sfwidgetforminputfile' => 'widget/sfWidgetFormInputFile.class.php',
374-
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
375375
'sfwidgetforminputfileeditable' => 'widget/sfWidgetFormInputFileEditable.class.php',
376+
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
376377
'sfwidgetforminputhidden' => 'widget/sfWidgetFormInputHidden.class.php',
377378
'sfwidgetforminputpassword' => 'widget/sfWidgetFormInputPassword.class.php',
378379
'sfwidgetforminputread' => 'widget/sfWidgetFormInputRead.class.php',
@@ -519,11 +520,11 @@ public static function make()
519520
if (false !== stripos($contents, 'class '.$class)
520521
|| false !== stripos($contents, 'interface '.$class)
521522
|| false !== stripos($contents, 'trait '.$class)) {
522-
$classes .= sprintf(" '%s' => '%s',\n", strtolower($class), substr(str_replace($libDir, '', $file), 1));
523+
$classes .= sprintf(" '%s' => '%s',\n", strtolower($class), substr(str_replace($libDir, '', $file), 1));
523524
}
524525
}
525526

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

528529
file_put_contents(__FILE__, $content);
529530
}

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
@@ -222,10 +222,7 @@ public function execute($configFiles)
222222

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

lib/mailer/sfMailer.class.php

100755100644
+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function __construct(sfEventDispatcher $dispatcher, $options)
5656
'logging' => false,
5757
'delivery_strategy' => self::REALTIME,
5858
'transport' => array(
59-
'class' => 'Swift_MailTransport',
59+
'class' => class_exists('Swift_MailTransport') ? 'Swift_MailTransport' : 'Swift_SmtpTransport',
6060
'param' => array(),
6161
),
6262
), $options);
@@ -260,7 +260,7 @@ public function sendNextImmediately()
260260
*
261261
* @return false|int The number of sent emails
262262
*/
263-
public function send($message, &$failedRecipients = null)
263+
public function send(sfMailerSwiftMessage $message, &$failedRecipients = null)
264264
{
265265
if ($this->force) {
266266
$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 <[email protected]>
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
@@ -67,9 +67,9 @@ public function stop()
6767
/**
6868
* Stores a message in the queue.
6969
*
70-
* @param Swift_Mime_Message $message The message to store
70+
* @param Swift_Mime_Message|Swift_Mime_SimpleMessage $message The message to store
7171
*/
72-
public function queueMessage(Swift_Mime_Message $message)
72+
public function queueMessage(sfMailerSwiftMessage $message)
7373
{
7474
$object = new $this->model();
7575

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
@@ -140,11 +140,7 @@ protected function getMailer()
140140
*/
141141
protected function initializeMailer()
142142
{
143-
if (!class_exists('Swift')) {
144-
$swift_dir = sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib';
145-
146-
require_once $swift_dir.'/swift_required.php';
147-
}
143+
require_once sfConfig::get('sf_symfony_lib_dir').'/config/autoload/swift.php';
148144

149145
$config = $this->getFactoryConfiguration();
150146

lib/validator/sfValidatorFile.class.php

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

101+
if (!isset($value['tmp_name'])) {
102+
throw new sfValidatorError($this, 'invalid', array('value' => 'Array'));
103+
}
104+
101105
if (!isset($value['name'])) {
102106
$value['name'] = '';
103107
}

lib/validator/sfValidatorSchema.class.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ public function clean($values)
8787
*/
8888
public function preClean($values)
8989
{
90-
if (null === $validator = $this->getPreValidator()) {
90+
$validator = $this->getPreValidator();
91+
92+
if (null === $validator) {
9193
return $values;
9294
}
9395

@@ -108,7 +110,9 @@ public function preClean($values)
108110
*/
109111
public function postClean($values)
110112
{
111-
if (null === $validator = $this->getPostValidator()) {
113+
$validator = $this->getPostValidator();
114+
115+
if (null === $validator) {
112116
return $values;
113117
}
114118

@@ -353,8 +357,14 @@ protected function doClean($values)
353357
protected function getBytes($value)
354358
{
355359
$value = trim($value);
360+
$length = strlen($value);
361+
362+
if (0 === $length) {
363+
return 0.0;
364+
}
365+
356366
$number = (float) $value;
357-
$modifier = strtolower($value[strlen($value) - 1]);
367+
$modifier = strtolower($value[$length - 1]);
358368

359369
$exp_by_modifier = array(
360370
'k' => 1,

lib/vendor/lime/lime.php

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

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

@@ -155,6 +156,10 @@ public function __destruct()
155156
{
156157
$this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed));
157158
}
159+
else if ($errors)
160+
{
161+
$this->output->red_bar(sprintf("# Looks like test pass but with %d errors.", $errors));
162+
}
158163
else if ($total == $plan)
159164
{
160165
$this->output->green_bar("# Looks like everything went fine.");
@@ -173,10 +178,11 @@ private function getExitCode()
173178
{
174179
$plan = $this->results['stats']['plan'];
175180
$failed = count($this->results['stats']['failed']);
181+
$errors = count($this->results['stats']['errors']);
176182
$total = $this->results['stats']['total'];
177183
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan));
178184

179-
if ($failed)
185+
if ($failed || $errors)
180186
{
181187
return 1;
182188
}
@@ -607,6 +613,12 @@ public function handle_error($code, $message, $file, $line, $context = null)
607613
case E_WARNING:
608614
$type = 'Warning';
609615
break;
616+
case E_STRICT:
617+
$type = 'Strict';
618+
break;
619+
case E_DEPRECATED:
620+
$type = 'Deprecated';
621+
break;
610622
default:
611623
$type = 'Notice';
612624
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)