mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-27 21:58:52 +00:00
[ticket/13358] Fix tests and use exceptions instead of user object
PHPBB3-13358
This commit is contained in:
parent
f6e7a94bd5
commit
352648f173
5 changed files with 17 additions and 22 deletions
|
@ -111,8 +111,6 @@ services:
|
||||||
|
|
||||||
file_downloader:
|
file_downloader:
|
||||||
class: phpbb\file_downloader
|
class: phpbb\file_downloader
|
||||||
arguments:
|
|
||||||
- @user
|
|
||||||
|
|
||||||
http_kernel:
|
http_kernel:
|
||||||
class: Symfony\Component\HttpKernel\HttpKernel
|
class: Symfony\Component\HttpKernel\HttpKernel
|
||||||
|
|
|
@ -15,25 +15,12 @@ namespace phpbb;
|
||||||
|
|
||||||
class file_downloader
|
class file_downloader
|
||||||
{
|
{
|
||||||
/** @var \phpbb\user */
|
|
||||||
protected $user;
|
|
||||||
|
|
||||||
/** @var string Error string */
|
/** @var string Error string */
|
||||||
public $error_string = '';
|
public $error_string = '';
|
||||||
|
|
||||||
/** @var int Error number */
|
/** @var int Error number */
|
||||||
public $error_number = 0;
|
public $error_number = 0;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param \phpbb\user $user phpBB user object
|
|
||||||
*/
|
|
||||||
public function __construct(user $user)
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve contents from remotely stored file
|
* Retrieve contents from remotely stored file
|
||||||
*
|
*
|
||||||
|
@ -45,6 +32,9 @@ class file_downloader
|
||||||
*
|
*
|
||||||
* @return mixed File data as string if file can be read and there is no
|
* @return mixed File data as string if file can be read and there is no
|
||||||
* timeout, false if there were errors or the connection timed out
|
* timeout, false if there were errors or the connection timed out
|
||||||
|
*
|
||||||
|
* @throws \RuntimeException If data can't be retrieved and no error
|
||||||
|
* message is returned
|
||||||
*/
|
*/
|
||||||
function get($host, $directory, $filename, $port = 80, $timeout = 6)
|
function get($host, $directory, $filename, $port = 80, $timeout = 6)
|
||||||
{
|
{
|
||||||
|
@ -75,8 +65,7 @@ class file_downloader
|
||||||
}
|
}
|
||||||
else if (stripos($line, '404 not found') !== false)
|
else if (stripos($line, '404 not found') !== false)
|
||||||
{
|
{
|
||||||
$this->error_string = $this->user->lang('FILE_NOT_FOUND', $filename);
|
throw new \RuntimeException(array('FILE_NOT_FOUND', $filename));
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,8 +73,7 @@ class file_downloader
|
||||||
|
|
||||||
if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
|
if (!empty($stream_meta_data['timed_out']) || time() >= $timer_stop)
|
||||||
{
|
{
|
||||||
$this->error_string = $this->user->lang['FSOCK_TIMEOUT'];
|
throw new \RuntimeException('FSOCK_TIMEOUT');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@fclose($socket);
|
@fclose($socket);
|
||||||
|
@ -99,8 +87,7 @@ class file_downloader
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$this->error_string = $this->user->lang['FSOCK_DISABLED'];
|
throw new \RuntimeException('FSOCK_DISABLED');
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -257,7 +257,13 @@ class version_helper
|
||||||
$errstr = $errno = '';
|
$errstr = $errno = '';
|
||||||
$this->file_downloader->set_error_number($errno)
|
$this->file_downloader->set_error_number($errno)
|
||||||
->set_error_string($errstr);
|
->set_error_string($errstr);
|
||||||
$info = $this->file_downloader->get($this->host, $this->path, $this->file);
|
try {
|
||||||
|
$info = $this->file_downloader->get($this->host, $this->path, $this->file);
|
||||||
|
}
|
||||||
|
catch (\RuntimeException $exception)
|
||||||
|
{
|
||||||
|
throw new \RuntimeException(call_user_func_array(array($this->user, 'lang'), $exception->getMessage()));
|
||||||
|
}
|
||||||
|
|
||||||
if (!empty($errstr))
|
if (!empty($errstr))
|
||||||
{
|
{
|
||||||
|
|
|
@ -33,6 +33,7 @@ class phpbb_version_helper_fetch_test extends phpbb_test_case
|
||||||
new \phpbb\config\config(array(
|
new \phpbb\config\config(array(
|
||||||
'version' => '3.1.0',
|
'version' => '3.1.0',
|
||||||
)),
|
)),
|
||||||
|
new \phpbb\file_downloader(),
|
||||||
new \phpbb\user('\phpbb\datetime')
|
new \phpbb\user('\phpbb\datetime')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ class phpbb_version_helper_test extends phpbb_test_case
|
||||||
new \phpbb\config\config(array(
|
new \phpbb\config\config(array(
|
||||||
'version' => '3.1.0',
|
'version' => '3.1.0',
|
||||||
)),
|
)),
|
||||||
|
new \phpbb\file_downloader(),
|
||||||
new \phpbb\user('\phpbb\datetime')
|
new \phpbb\user('\phpbb\datetime')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -208,6 +209,7 @@ class phpbb_version_helper_test extends phpbb_test_case
|
||||||
new \phpbb\config\config(array(
|
new \phpbb\config\config(array(
|
||||||
'version' => $current_version,
|
'version' => $current_version,
|
||||||
)),
|
)),
|
||||||
|
new \phpbb\file_downloader(),
|
||||||
new \phpbb\user('\phpbb\datetime'),
|
new \phpbb\user('\phpbb\datetime'),
|
||||||
))
|
))
|
||||||
->getMock()
|
->getMock()
|
||||||
|
@ -318,6 +320,7 @@ class phpbb_version_helper_test extends phpbb_test_case
|
||||||
new \phpbb\config\config(array(
|
new \phpbb\config\config(array(
|
||||||
'version' => $current_version,
|
'version' => $current_version,
|
||||||
)),
|
)),
|
||||||
|
new \phpbb\file_downloader(),
|
||||||
new \phpbb\user('\phpbb\datetime'),
|
new \phpbb\user('\phpbb\datetime'),
|
||||||
))
|
))
|
||||||
->getMock()
|
->getMock()
|
||||||
|
|
Loading…
Add table
Reference in a new issue