Skip to content

Commit

Permalink
fix(test): fail on php errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Jan 19, 2024
1 parent 154bc18 commit e1e02b2
Show file tree
Hide file tree
Showing 27 changed files with 127 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
services:
memcached:
image: "memcached:${{ matrix.memcached-version }}"
ports:
- 11211:11211

steps:
- name: Checkout
Expand All @@ -40,7 +42,7 @@ jobs:
with:
php-version: "${{ matrix.php-version }}"
extensions: apcu
ini-values: apc.enable_cli=1
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"

- name: Get composer cache directory
id: composer-cache
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/lib/*/doctrine/*/base/
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/cache/
lib/plugins/sfDoctrinePlugin/test/functional/fixtures/log/
/lib/plugins/sfDoctrinePlugin/test/functional/fixtures/data/*.sqlite*
/vendor
/composer.lock
.php-cs-fixer.cache
6 changes: 6 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ services:
{
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
echo 'memory_limit = -1'
echo 'error_reporting = '`
php -r 'echo (E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE;'
`
echo 'short_open_tag = off'
echo 'magic_quotes_gpc = off'
echo 'date.timezone = "UTC"'
Expand Down Expand Up @@ -57,6 +60,9 @@ services:
{
echo 'pdo_mysql.default_socket = /var/run/mysqld/mysql.sock'
echo 'memory_limit = -1'
echo 'error_reporting = '`
php -r 'echo (E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE;'
`
echo 'short_open_tag = off'
echo 'magic_quotes_gpc = off'
echo 'date.timezone = "UTC"'
Expand Down
7 changes: 4 additions & 3 deletions lib/autoload/sfCoreAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ class sfCoreAutoload
'sfwebdebuglogger' => 'log/sfWebDebugLogger.class.php',
'sfmailer' => 'mailer/sfMailer.class.php',
'sfmailermessageloggerplugin' => 'mailer/sfMailerMessageLoggerPlugin.class.php',
'sfmailerswiftmessage' => 'mailer/sfMailerSwiftMessage.php',
'sfnomailer' => 'mailer/sfNoMailer.class.php',
'sfpearconfig' => 'plugin/sfPearConfig.class.php',
'sfpeardownloader' => 'plugin/sfPearDownloader.class.php',
Expand Down Expand Up @@ -373,8 +374,8 @@ class sfCoreAutoload
'sfwidgetforminput' => 'widget/sfWidgetFormInput.class.php',
'sfwidgetforminputcheckbox' => 'widget/sfWidgetFormInputCheckbox.class.php',
'sfwidgetforminputfile' => 'widget/sfWidgetFormInputFile.class.php',
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
'sfwidgetforminputfileeditable' => 'widget/sfWidgetFormInputFileEditable.class.php',
'sfwidgetforminputfilemulti' => 'widget/sfWidgetFormInputFileMulti.class.php',
'sfwidgetforminputhidden' => 'widget/sfWidgetFormInputHidden.class.php',
'sfwidgetforminputpassword' => 'widget/sfWidgetFormInputPassword.class.php',
'sfwidgetforminputread' => 'widget/sfWidgetFormInputRead.class.php',
Expand Down Expand Up @@ -521,11 +522,11 @@ public static function make()
if (false !== stripos($contents, 'class '.$class)
|| false !== stripos($contents, 'interface '.$class)
|| false !== stripos($contents, 'trait '.$class)) {
$classes .= sprintf(" '%s' => '%s',\n", strtolower($class), substr(str_replace($libDir, '', $file), 1));
$classes .= sprintf(" '%s' => '%s',\n", strtolower($class), substr(str_replace($libDir, '', $file), 1));
}
}

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

file_put_contents(__FILE__, $content);
}
Expand Down
6 changes: 6 additions & 0 deletions lib/config/autoload/swift.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

if (!class_exists('Swift')) {
$swift_dir = sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib';
require_once $swift_dir.'/swift_required.php';
}
5 changes: 1 addition & 4 deletions lib/config/sfFactoryConfigHandler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ public function execute($configFiles)

case 'mailer':
$instances[] = sprintf(
"if (!class_exists('Swift')) {\n".
" \$swift_dir = sfConfig::get('sf_swiftmailer_dir', sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib');\n".
" require_once \$swift_dir.'/swift_required.php';\n".
"}\n".
preg_replace('/<\?php\s*/', '', file_get_contents(__DIR__.'/autoload/swift.php')).
"\$this->setMailerConfiguration(array_merge(array('class' => sfConfig::get('sf_factory_mailer', '%s')), sfConfig::get('sf_factory_mailer_parameters', %s)));\n",
$class,
var_export($parameters, true)
Expand Down
4 changes: 2 additions & 2 deletions lib/mailer/sfMailer.class.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(sfEventDispatcher $dispatcher, $options)
'logging' => false,
'delivery_strategy' => self::REALTIME,
'transport' => array(
'class' => 'Swift_MailTransport',
'class' => class_exists('Swift_MailTransport') ? 'Swift_MailTransport' : 'Swift_SmtpTransport',
'param' => array(),
),
), $options);
Expand Down Expand Up @@ -262,7 +262,7 @@ public function sendNextImmediately()
*
* @return false|int The number of sent emails
*/
public function send($message, &$failedRecipients = null)
public function send(sfMailerSwiftMessage $message, &$failedRecipients = null)
{
if ($this->force) {
$this->force = false;
Expand Down
17 changes: 17 additions & 0 deletions lib/mailer/sfMailerSwiftMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
* This file is part of the symfony package.
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

class_exists('Swift');

if (version_compare(Swift::VERSION, '6.0.0') >= 0) {
class_alias('Swift_Mime_SimpleMessage', 'sfMailerSwiftMessage');
} else {
class_alias('Swift_Mime_Message', 'sfMailerSwiftMessage');
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public function stop()
/**
* Stores a message in the queue.
*
* @param Swift_Mime_Message $message The message to store
* @param Swift_Mime_Message|Swift_Mime_SimpleMessage $message The message to store
*/
public function queueMessage(Swift_Mime_Message $message)
public function queueMessage(sfMailerSwiftMessage $message)
{
$object = new $this->model();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev:

test:
.settings:
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
cache: false
web_debug: false
no_script_name: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev:

test:
.settings:
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
cache: false
web_debug: false
no_script_name: false
Expand Down
23 changes: 14 additions & 9 deletions lib/storage/sfCacheSessionStorage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ public function initialize($options = array())
}

if (empty($this->id)) {
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'localhost';
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';

// generate new id based on random # / ip / user agent / secret
$this->id = md5(mt_rand(0, 999999).$ip.$ua.$this->options['session_cookie_secret']);
$this->id = $this->generateId();

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

// generate session id
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';

$this->id = md5(mt_rand(0, 999999).$_SERVER['REMOTE_ADDR'].$ua.$this->options['session_cookie_secret']);
$this->id = $this->generateId();

// save data to cache
$this->cache->set($this->id, serialize($this->data));
Expand Down Expand Up @@ -275,4 +268,16 @@ public function shutdown()
}
}
}

/**
* @return string
*/
private function generateId()
{
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'localhost';
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';

// generate new id based on random # / ip / user agent / secret
return md5(mt_rand(0, 999999).$ip.$ua.$this->options['session_cookie_secret']);
}
}
6 changes: 1 addition & 5 deletions lib/task/sfCommandApplicationTask.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,7 @@ protected function getMailer()
*/
protected function initializeMailer()
{
if (!class_exists('Swift')) {
$swift_dir = sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib';

require_once $swift_dir.'/swift_required.php';
}
require_once sfConfig::get('sf_symfony_lib_dir').'/config/autoload/swift.php';

$config = $this->getFactoryConfiguration();

Expand Down
6 changes: 5 additions & 1 deletion lib/validator/sfValidatorFile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ protected function configure($options = array(), $messages = array())
*/
protected function doClean($value)
{
if (!is_array($value) || !isset($value['tmp_name'])) {
if (!is_array($value)) {
throw new sfValidatorError($this, 'invalid', array('value' => (string) $value));
}

if (!isset($value['tmp_name'])) {
throw new sfValidatorError($this, 'invalid', array('value' => 'Array'));
}

if (!isset($value['name'])) {
$value['name'] = '';
}
Expand Down
16 changes: 13 additions & 3 deletions lib/validator/sfValidatorSchema.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ public function clean($values)
*/
public function preClean($values)
{
if (null === $validator = $this->getPreValidator()) {
$validator = $this->getPreValidator();

if (null === $validator) {
return $values;
}

Expand All @@ -110,7 +112,9 @@ public function preClean($values)
*/
public function postClean($values)
{
if (null === $validator = $this->getPostValidator()) {
$validator = $this->getPostValidator();

if (null === $validator) {
return $values;
}

Expand Down Expand Up @@ -355,8 +359,14 @@ protected function doClean($values)
protected function getBytes($value)
{
$value = trim($value);
$length = strlen($value);

if (0 === $length) {
return 0.0;
}

$number = (float) $value;
$modifier = strtolower($value[strlen($value) - 1]);
$modifier = strtolower($value[$length - 1]);

$exp_by_modifier = array(
'k' => 1,
Expand Down
16 changes: 14 additions & 2 deletions lib/vendor/lime/lime.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct($plan = null, $options = array())
'force_colors' => false,
'output' => null,
'verbose' => false,
'error_reporting' => false,
'error_reporting' => true,
), $options);

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

Expand All @@ -156,6 +157,10 @@ public function __destruct()
{
$this->output->red_bar(sprintf("# Looks like you failed %d tests of %d.", $failed, $passed + $failed));
}
else if ($errors)
{
$this->output->red_bar(sprintf("# Looks like test pass but with %d errors.", $errors));
}
else if ($total == $plan)
{
$this->output->green_bar("# Looks like everything went fine.");
Expand All @@ -174,10 +179,11 @@ private function getExitCode()
{
$plan = $this->results['stats']['plan'];
$failed = count($this->results['stats']['failed']);
$errors = count($this->results['stats']['errors']);
$total = $this->results['stats']['total'];
is_null($plan) and $plan = $total and $this->output->echoln(sprintf("1..%d", $plan));

if ($failed)
if ($failed || $errors)
{
return 1;
}
Expand Down Expand Up @@ -608,6 +614,12 @@ public function handle_error($code, $message, $file, $line, $context = null)
case E_WARNING:
$type = 'Warning';
break;
case E_STRICT:
$type = 'Strict';
break;
case E_DEPRECATED:
$type = 'Deprecated';
break;
default:
$type = 'Notice';
break;
Expand Down
2 changes: 2 additions & 0 deletions require_for_php8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
swiftmailer/swiftmailer:^5.4.6
egulias/email-validator:^2.1.10
4 changes: 4 additions & 0 deletions test/bootstrap/functional.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* file that was distributed with this source code.
*/

if (!defined('SF_TEST_WITHOUT_COMPOSER')) {
require_once __DIR__.'/../../vendor/autoload.php';
}

// setup expected test environment (per check_configuration.php)
ini_set('magic_quotes_runtime', 'off');
ini_set('session.auto_start', 'off');
Expand Down
4 changes: 4 additions & 0 deletions test/bootstrap/unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
* file that was distributed with this source code.
*/

if (!defined('SF_TEST_WITHOUT_COMPOSER')) {
require_once __DIR__.'/../../vendor/autoload.php';
}

// setup expected test environment (per check_configuration.php)
ini_set('magic_quotes_runtime', 'off');
ini_set('session.auto_start', 'off');
Expand Down
6 changes: 2 additions & 4 deletions test/functional/fixtures/apps/cache/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ prod:

dev:
.settings:
# E_ALL | E_STRICT = 4095
error_reporting: 4095
error_reporting: <?php echo (E_ALL | E_STRICT)."\n" ?>
web_debug: true
cache: true
no_script_name: false
etag: true

test:
.settings:
# E_ALL | E_STRICT = 4095
error_reporting: 4095
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
web_debug: false
cache: true
no_script_name: false
Expand Down
2 changes: 1 addition & 1 deletion test/functional/fixtures/apps/frontend/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev:

test:
.settings:
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
cache: false
web_debug: false
no_script_name: false
Expand Down
2 changes: 1 addition & 1 deletion test/functional/fixtures/apps/i18n/config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dev:

test:
.settings:
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_NOTICE)."\n" ?>
error_reporting: <?php echo ((E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE)."\n" ?>
cache: false
web_debug: false
no_script_name: false
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mailer/fixtures/TestMailMessage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
class TestMailMessage
{
public function setMessage(Swift_Mime_Message $message)
public function setMessage(sfMailerSwiftMessage $message)
{
}

Expand Down
Loading

0 comments on commit e1e02b2

Please sign in to comment.