Skip to content

Commit 8450b13

Browse files
TybazethePanz
authored andcommitted
PHP 8.1 > Unit Test
sfException> fileExcerpt file can be null, and PHP 8.1 do not allow null on is_readable() sfBrowser> Move sf_test conf before getContext, because getContext can throw some sfException, which will raise some printStackTrace, hidden by another Exception "header already sent ..." lime.php> some trace can have no "file" (internal methods call) lime.php> handle_exception can handle Error/Throwable, not avaialble under php7.2: remove typing sfTestFunctionalBase> can throw exception Fix Select Unit test NewActivePendingExpired. DomDocument on recent php return a list of values, not concatened ones. Fix SessionStorage UnitTest. sfSessionStorage could not be restarted. Flag $sessionStarted as false when shutdown to avoid error during unit test which can start several sfSessionStorage Storage need to be shutdown to avoid: PHP Warning: session_name(): Session name cannot be changed when a session is active
1 parent dcb1ce3 commit 8450b13

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

lib/exception/sfException.class.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,10 @@ static protected function formatArrayAsHtml($values)
366366
*/
367367
static protected function fileExcerpt($file, $line)
368368
{
369+
// $file can be null for RuntimeException
370+
if($file === null) {
371+
return '';
372+
}
369373
if (is_readable($file))
370374
{
371375
$content = preg_split('#<br />#', preg_replace('/^<code>(.*)<\/code>$/s', '$1', highlight_file($file, true)));

lib/plugins/sfDoctrinePlugin/test/functional/AdminGenBrowser.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ protected function _testEnumDropdown()
152152
$this->
153153
get('/subscriptions/new')->
154154
with('response')->begin()->
155-
checkElement('select', 'NewActivePendingExpired')->
155+
checkElement('select', '/^New\R?Active\R?Pending\R?Expired\R?$/m')->
156156
end()
157157
;
158158
}
@@ -237,7 +237,7 @@ protected function _runAdminGenModuleSanityCheck($model, $module)
237237
}
238238

239239
protected function _generateAdminGenModule($model, $module)
240-
{
240+
{
241241
$this->info('Generating admin gen module "' . $module . '"');
242242
$task = new sfDoctrineGenerateAdminTask($this->getContext()->getEventDispatcher(), new sfFormatter());
243243
$task->run(array('application' => 'backend', 'route_or_model' => $model));

lib/storage/sfSessionStorage.class.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,5 +190,6 @@ public function shutdown()
190190
{
191191
// don't need a shutdown procedure because read/write do it in real-time
192192
session_write_close();
193+
self::$sessionStarted = false;
193194
}
194195
}

lib/test/sfTestFunctionalBase.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static public function handlePhpError($errno, $errstr, $errfile, $errline)
478478
/**
479479
* Exception handler for the current test browser instance.
480480
*
481-
* @param Exception $exception The exception
481+
* @param Throwable $exception The exception
482482
*/
483483
function handleException($exception)
484484
{

lib/util/sfBrowser.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,12 @@ class sfBrowser extends sfBrowserBase
2828
*/
2929
protected function doCall()
3030
{
31+
// Before getContext, it can trigger some
32+
sfConfig::set('sf_test', true);
33+
3134
// recycle our context object
3235
$this->context = $this->getContext(true);
3336

34-
sfConfig::set('sf_test', true);
35-
3637
// we register a fake rendering filter
3738
sfConfig::set('sf_rendering_filter', array('sfFakeRenderingFilter', null));
3839

lib/vendor/lime/lime.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,11 @@ public function error($message, $file = null, $line = null, array $traces = arra
520520
{
521521
$this->output->error($message, $file, $line, $traces);
522522

523-
$this->results['stats']['errors'][] = array(
524-
'message' => $message,
525-
'file' => $file,
526-
'line' => $line,
527-
);
523+
$this->results['stats']['errors'][] = array(
524+
'message' => $message,
525+
'file' => $file,
526+
'line' => $line,
527+
);
528528
}
529529

530530
protected function update_stats()
@@ -553,7 +553,8 @@ protected function find_caller($traces)
553553
$t = array_reverse($traces);
554554
foreach ($t as $trace)
555555
{
556-
if (isset($trace['object']) && $this->is_test_object($trace['object']))
556+
// In internal calls, like error_handle, 'file' will be missing
557+
if (isset($trace['object']) && $this->is_test_object($trace['object']) && isset($trace['file']))
557558
{
558559
return array($trace['file'], $trace['line']);
559560
}
@@ -587,7 +588,11 @@ public function handle_error($code, $message, $file, $line, $context = null)
587588
$this->error($type.': '.$message, $file, $line, $trace);
588589
}
589590

590-
public function handle_exception(Throwable $exception)
591+
/**
592+
* @param Throwable $exception only available on php7
593+
* @return bool
594+
*/
595+
public function handle_exception($exception)
591596
{
592597
$this->error(get_class($exception).': '.$exception->getMessage(), $exception->getFile(), $exception->getLine(), $exception->getTrace());
593598

test/unit/storage/sfSessionStorageTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{
2727
$storage = new sfSessionStorage();
2828
$t->pass('->__construct() does not throw an exception when not provided with options');
29+
$storage->shutdown();
2930
}
3031
catch (InvalidArgumentException $e)
3132
{

0 commit comments

Comments
 (0)