Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: PHP warnings triggered by the test suite #302

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
services:
memcached:
image: "memcached:${{ matrix.memcached-version }}"
ports:
- 11211:11211

steps:
- name: Checkout
Expand All @@ -39,7 +41,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 @@ -192,6 +192,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 @@ -371,8 +372,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 @@ -519,11 +520,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 @@ -222,10 +222,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 @@ -56,7 +56,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 @@ -260,7 +260,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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach is a bit like https://github.com/FriendsOfSymfony1/symfony1/pull/237/files but way more elegant.

Question is, if we are able to support swiftmailer 6 including the doctrine spools, do we really need to support swiftmailer 5?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I guess not.

But it depends, on the ability of applications using swiftmailer 5 to migrate to swiftmailer 6.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This opens a path to add support for symfony/mailer.

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 @@ -67,9 +67,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 @@ -140,11 +140,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 @@ -94,10 +94,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 @@ -87,7 +87,9 @@ public function clean($values)
*/
public function preClean($values)
{
if (null === $validator = $this->getPreValidator()) {
$validator = $this->getPreValidator();

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

Expand All @@ -108,7 +110,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 @@ -353,8 +357,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
45 changes: 44 additions & 1 deletion lib/vendor/lime/lime.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@ class lime_test
protected $options = array();

static protected $all_results = array();
static private $instanceCount = 0;
static private $allExitCode = 0;

public function __construct($plan = null, $options = array())
{
++self::$instanceCount;

// for BC
if (!is_array($options))
{
Expand All @@ -37,7 +41,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 @@ -130,9 +134,12 @@ static public function to_xml($results = null)

public function __destruct()
{
--self::$instanceCount;

$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 @@ -149,12 +156,42 @@ 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.");
}

flush();

self::$allExitCode |= $this->getExitCode();

if (0 === self::$instanceCount) {
exit(self::$allExitCode);
}
}

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 || $errors)
{
return 1;
}
else if ($total == $plan)
{
return 0;
}

return 1;
}

/**
Expand Down Expand Up @@ -576,6 +613,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')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thePanz and @connorhu this will bring support for composer autoloading in the tests and a way towards getting rid of the submodules.

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
Loading