Skip to content

Commit

Permalink
!fixup fix(test): fail on php errors
Browse files Browse the repository at this point in the history
  • Loading branch information
alquerci committed Jan 1, 2024
1 parent 82caad1 commit 24236cc
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
run: php data/bin/check_configuration.php

- name: Run Tests
run: php data/bin/symfony symfony:test --trace
run: php -derror_reporting=`php -r 'echo (E_ALL | E_STRICT) ^ E_USER_DEPRECATED ^ E_DEPRECATED ^ E_STRICT ^ E_USER_NOTICE ^ E_NOTICE;'` data/bin/symfony symfony:test --trace
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
7 changes: 4 additions & 3 deletions lib/autoload/sfCoreAutoload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,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 @@ -372,8 +373,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 @@ -520,11 +521,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
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
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
26 changes: 22 additions & 4 deletions test/bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# Example: "lowest highest"
#

__DIR__=`dirname "$0"`
ROOT_DIR="${__DIR__}/../.."

# Configuration
#
dependencyPreferences='highest'
Expand Down Expand Up @@ -41,10 +44,10 @@ scriptAll ()
{
for dependencyPreference in ${dependencyPreferences}
do
install_${dependencyPreference}

for phpVersion in ${phpVersions}
do
install_${dependencyPreference} ${phpVersion}

script ${phpVersion} ${dependencyPreference}
done
done
Expand All @@ -66,10 +69,25 @@ install_highest ()

install_lowest ()
{
reset_submodules
c_service=${1}
c_phpVersion=`echo "${c_service}" | sed 's/^php//'`

reset_submodules
${installSubmodule}
${dcexec} composer ${composerUpdate} --prefer-lowest

cp "${ROOT_DIR}/composer.json" "${ROOT_DIR}/composer.json~"

${dcexec} composer config platform.php `echo "${c_phpVersion}" | sed 's/.$/.\0/'`

if test 80 -le "${c_phpVersion}"; then
c_depFlags=`cat ${ROOT_DIR}/require_for_php8.txt`

${dcexec} composer ${COMPOSER_REQUIRE} ${c_depFlags} --prefer-lowest --update-with-all-dependencies
else
${dcexec} composer ${COMPOSER_UPDATE} --prefer-lowest
fi

mv "${ROOT_DIR}/composer.json~" "${ROOT_DIR}/composer.json"
}

reset_submodules ()
Expand Down
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
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
7 changes: 6 additions & 1 deletion test/unit/mailer/fixtures/TestMailerTransport.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ public function stop()
$this->started = false;
}

public function ping()
{
return false;
}

public function registerPlugin(Swift_Events_EventListener $plugin)
{
}
Expand All @@ -53,7 +58,7 @@ public function getSentCount()
return $this->count;
}

public function send(Swift_Mime_Message $message, &$failedRecipients = null)
public function send(sfMailerSwiftMessage $message, &$failedRecipients = null)
{
++$this->count;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/mailer/fixtures/TestSpool.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function stop()
{
}

public function queueMessage(Swift_Mime_Message $message)
public function queueMessage(sfMailerSwiftMessage $message)
{
$this->messages[] = $message;

Expand Down
2 changes: 1 addition & 1 deletion test/unit/mailer/sfMailerTest.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
require_once __DIR__.'/../../bootstrap/unit.php';

require_once sfConfig::get('sf_symfony_lib_dir').'/vendor/swiftmailer/lib/swift_required.php';
require_once sfConfig::get('sf_symfony_lib_dir').'/config/autoload/swift.php';

require_once __DIR__.'/fixtures/TestMailerTransport.class.php';

Expand Down
13 changes: 13 additions & 0 deletions test/unit/mailer/sfMailerWithoutComposerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?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.
*/

define('SF_TEST_WITHOUT_COMPOSER', 1);

require_once __DIR__.'/sfMailerTest.php';

0 comments on commit 24236cc

Please sign in to comment.