Fix a lot of notices/warnings/deprecation notes in the test directory

This commit is contained in:
Philipp 2020-10-18 20:31:57 +02:00
parent efaec26b1d
commit d55ecb9288
No known key found for this signature in database
GPG key ID: 9A28B7D4FF5667BD
77 changed files with 428 additions and 558 deletions

View file

@ -21,7 +21,6 @@
namespace Friendica\Test\src\Util;
use Error;
use Friendica\Model\Group;
use Friendica\Util\ACLFormatter;
use PHPUnit\Framework\TestCase;

View file

@ -64,11 +64,12 @@ class BasePathTest extends MockedTest
/**
* Test the basepath determination with a complete wrong path
* @expectedException \Exception
* @expectedExceptionMessageRegExp /(.*) is not a valid basepath/
*/
public function testFailedBasePath()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp("/(.*) is not a valid basepath/");
$basepath = new BasePath('/now23452sgfgas', []);
$basepath->getPath();
}

View file

@ -534,9 +534,9 @@ class BaseURLTest extends MockedTest
self::assertFalse($baseUrl->save('test', 10, 'nope'));
// nothing should have changed because we never successfully saved anything
self::assertEquals($baseUrl->getHostname(), 'friendica.local');
self::assertEquals($baseUrl->getUrlPath(), 'new/test');
self::assertEquals($baseUrl->getSSLPolicy(), BaseURL::DEFAULT_SSL_SCHEME);
self::assertEquals($baseUrl->get(), 'http://friendica.local/new/test');
self::assertEquals('friendica.local', $baseUrl->getHostname());
self::assertEquals('new/test', $baseUrl->getUrlPath());
self::assertEquals(BaseURL::DEFAULT_SSL_SCHEME, $baseUrl->getSSLPolicy());
self::assertEquals('http://friendica.local/new/test', $baseUrl->get());
}
}

View file

@ -55,11 +55,12 @@ class ConfigFileLoaderTest extends MockedTest
/**
* Test the loadConfigFiles() method with a wrong local.config.php
* @expectedException \Exception
* @expectedExceptionMessageRegExp /Error loading config file \w+/
*
*/
public function testLoadConfigWrong()
{
$this->expectExceptionMessageRegExp("/Error loading config file \w+/");
$this->expectException(\Exception::class);
$this->delConfigFile('local.config.php');
vfsStream::newFile('local.config.php')

View file

@ -19,6 +19,8 @@
*
* This is in the same namespace as Crypto for mocking 'rand' and 'random_init'
*/
/// @todo Use right namespace - needs alternative way of mocking random_int()
namespace Friendica\Util;
use phpseclib\Crypt\RSA;
@ -120,7 +122,6 @@ function random_int($min, $max)
{
global $phpMock;
if (isset($phpMock['random_int'])) {
$result = call_user_func_array($phpMock['random_int'], func_get_args());
return $result;
return call_user_func_array($phpMock['random_int'], func_get_args());
}
}

View file

@ -35,9 +35,6 @@ class EMailerTest extends MockedTest
/** @var BaseURL|MockInterface */
private $baseUrl;
/** @var string */
private $defaultHeaders;
protected function setUp()
{
parent::setUp();
@ -54,8 +51,6 @@ class EMailerTest extends MockedTest
$this->baseUrl = \Mockery::mock(BaseURL::class);
$this->baseUrl->shouldReceive('getHostname')->andReturn('friendica.local');
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
$this->defaultHeaders = [];
}
protected function tearDown()

View file

@ -24,6 +24,7 @@ namespace Friendica\Test\src\Util\Emailer;
use Friendica\App\BaseURL;
use Friendica\Core\Config\IConfig;
use Friendica\Core\L10n;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Object\EMail\IEmail;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\SampleMailBuilder;
@ -50,7 +51,7 @@ class MailBuilderTest extends MockedTest
/** @var string */
private $defaultHeaders;
public function setUp()
protected function setUp()
{
parent::setUp();
@ -95,7 +96,7 @@ class MailBuilderTest extends MockedTest
*/
public function testBuilderWithNonRawEmail()
{
$this->markTestIncomplete('Cannot easily mock Renderer and BBCode, so skipping tests wit them');
static::markTestIncomplete('Cannot easily mock Renderer and BBCode, so skipping tests wit them');
}
/**
@ -128,11 +129,12 @@ class MailBuilderTest extends MockedTest
/**
* Test if the builder throws an exception in case no recipient
*
* @expectedException \Friendica\Network\HTTPException\InternalServerErrorException
* @expectedExceptionMessage Recipient address is missing.
*/
public function testBuilderWithEmptyMail()
{
$this->expectException(InternalServerErrorException::class);
$this->expectExceptionMessage("Recipient address is missing.");
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
$builder->build(true);
@ -140,12 +142,12 @@ class MailBuilderTest extends MockedTest
/**
* Test if the builder throws an exception in case no sender
*
* @expectedException \Friendica\Network\HTTPException\InternalServerErrorException
* @expectedExceptionMessage Sender address or name is missing.
*/
public function testBuilderWithEmptySender()
{
$this->expectException(InternalServerErrorException::class);
$this->expectExceptionMessage("Sender address or name is missing.");
$builder = new SampleMailBuilder($this->l10n, $this->baseUrl, $this->config, new NullLogger());
$builder

View file

@ -41,10 +41,7 @@ class SystemMailBuilderTest extends MockedTest
/** @var BaseURL */
private $baseUrl;
/** @var string[] */
private $defaultHeaders;
public function setUp()
protected function setUp()
{
parent::setUp();
@ -59,8 +56,6 @@ class SystemMailBuilderTest extends MockedTest
$this->baseUrl = \Mockery::mock(BaseURL::class);
$this->baseUrl->shouldReceive('getHostname')->andReturn('friendica.local');
$this->baseUrl->shouldReceive('get')->andReturn('http://friendica.local');
$this->defaultHeaders = [];
}
/**

View file

@ -32,11 +32,6 @@ class StreamLoggerTest extends AbstractLoggerTest
{
use VFSTrait;
/**
* @var StreamLogger
*/
private $logger;
/**
* @var vfsStreamFile
*/
@ -53,7 +48,7 @@ class StreamLoggerTest extends AbstractLoggerTest
$this->setUpVfsDir();
$this->fileSystem = new Filesystem();
$this->fileSystem = new FileSystem();
}
/**
@ -64,9 +59,9 @@ class StreamLoggerTest extends AbstractLoggerTest
$this->logfile = vfsStream::newFile('friendica.log')
->at($this->root);
$this->logger = new StreamLogger('test', $this->logfile->url(), $this->introspection, $this->fileSystem, $level);
$logger = new StreamLogger('test', $this->logfile->url(), $this->introspection, $this->fileSystem, $level);
return $this->logger;
return $logger;
}
/**
@ -116,11 +111,12 @@ class StreamLoggerTest extends AbstractLoggerTest
/**
* Test when a file isn't set
* @expectedException \LogicException
* @expectedExceptionMessage Missing stream URL.
*/
public function testNoUrl()
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage("Missing stream URL.");
$logger = new StreamLogger('test', '', $this->introspection, $this->fileSystem);
$logger->emergency('not working');
@ -128,11 +124,12 @@ class StreamLoggerTest extends AbstractLoggerTest
/**
* Test when a file cannot be opened
* @expectedException \UnexpectedValueException
* @expectedExceptionMessageRegExp /The stream or file .* could not be opened: .* /
*/
public function testWrongUrl()
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessageRegExp("/The stream or file .* could not be opened: .* /");
$logfile = vfsStream::newFile('friendica.log')
->at($this->root)->chmod(0);
@ -143,12 +140,13 @@ class StreamLoggerTest extends AbstractLoggerTest
/**
* Test when the directory cannot get created
* @expectedException \UnexpectedValueException
* @expectedExceptionMessageRegExp /Directory .* cannot get created: .* /
*/
public function testWrongDir()
{
$this->markTestIncomplete('We need a platform independent way to set directory to readonly');
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessageRegExp("/Directory .* cannot get created: .* /");
static::markTestIncomplete('We need a platform independent way to set directory to readonly');
$logger = new StreamLogger('test', '/$%/wrong/directory/file.txt', $this->introspection, $this->fileSystem);
@ -157,21 +155,23 @@ class StreamLoggerTest extends AbstractLoggerTest
/**
* Test when the minimum level is not valid
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
*/
public function testWrongMinimumLevel()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
$logger = new StreamLogger('test', 'file.text', $this->introspection, $this->fileSystem, 'NOPE');
}
/**
* Test when the minimum level is not valid
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
*/
public function testWrongLogLevel()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
$logfile = vfsStream::newFile('friendica.log')
->at($this->root);
@ -182,11 +182,12 @@ class StreamLoggerTest extends AbstractLoggerTest
/**
* Test when the file is null
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage A stream must either be a resource or a string.
*/
public function testWrongFile()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("A stream must either be a resource or a string.");
$logger = new StreamLogger('test', null, $this->introspection, $this->fileSystem);
}
@ -195,7 +196,7 @@ class StreamLoggerTest extends AbstractLoggerTest
*/
public function testRealPath()
{
$this->markTestSkipped('vfsStream isn\'t compatible with chdir, so not testable.');
static::markTestSkipped('vfsStream isn\'t compatible with chdir, so not testable.');
$logfile = vfsStream::newFile('friendica.log')
->at($this->root);

View file

@ -59,21 +59,23 @@ class SyslogLoggerTest extends AbstractLoggerTest
/**
* Test when the minimum level is not valid
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
*/
public function testWrongMinimumLevel()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
$logger = new SyslogLoggerWrapper('test', $this->introspection, 'NOPE');
}
/**
* Test when the minimum level is not valid
* @expectedException \InvalidArgumentException
* @expectedExceptionMessageRegExp /The level ".*" is not valid./
*/
public function testWrongLogLevel()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessageRegExp("/The level \".*\" is not valid./");
$logger = new SyslogLoggerWrapper('test', $this->introspection);
$logger->log('NOPE', 'a test');
@ -81,11 +83,12 @@ class SyslogLoggerTest extends AbstractLoggerTest
/**
* Test when the logfacility is wrong (string)
* @expectedException \UnexpectedValueException
* @expectedExceptionMessageRegExp /Can\'t open syslog for ident ".*" and facility ".*": .* /
*/
public function testServerException()
{
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessageRegExp("/Can\'t open syslog for ident \".*\" and facility \".*\": .* /");
$logger = new SyslogLoggerWrapper('test', $this->introspection, LogLevel::DEBUG, null, 'a string');
$logger->emergency('not working');
}

View file

@ -51,6 +51,7 @@ class SyslogLoggerWrapper extends SyslogLogger
/**
* {@inheritdoc}
* @noinspection PhpMissingParentCallCommonInspection
*/
protected function syslogWrapper($level, $entry)
{

View file

@ -34,10 +34,12 @@ class WorkerLoggerTest extends MockedTest
/**
* Test the a id with length zero
* @expectedException \Error
*
*/
public function testGetWorkerIdZero()
{
$this->expectException(\Error::class);
$logger = \Mockery::mock(LoggerInterface::class);
new WorkerLogger($logger, 'test', 0);
}

View file

@ -53,6 +53,8 @@ class ProfilerTest extends MockedTest
->andReturn(true)
->twice();
$profiler = new Profiler($configCache);
self::assertInstanceOf(Profiler::class, $profiler);
}
/**
@ -141,7 +143,7 @@ class ProfilerTest extends MockedTest
* Test the Profiler reset
* @dataProvider dataPerformance
*/
public function testReset($timestamp, $name, array $functions)
public function testReset($timestamp, $name)
{
$configCache = \Mockery::mock(Cache::class);
$configCache->shouldReceive('get')

View file

@ -126,11 +126,11 @@ class StringsTest extends TestCase
* Tests if the string is a valid hexadecimal value
*
* @param string $input
* @param bool $valid
* @param bool $valid
*
* @dataProvider dataIsHex
*/
public function testIsHex($input, $valid)
public function testIsHex(string $input, bool $valid)
{
self::assertEquals($valid, Strings::isHex($input));
}

View file

@ -29,36 +29,36 @@ use PHPUnit\Framework\TestCase;
*/
class XmlTest extends TestCase
{
/**
* escape and unescape
*/
/**
* escape and unescape
*/
public function testEscapeUnescape()
{
$text="<tag>I want to break\n this!11!<?hard?></tag>";
$xml=XML::escape($text);
$retext=XML::unescape($text);
$text = "<tag>I want to break\n this!11!<?hard?></tag>";
$xml = XML::escape($text);
$retext = XML::unescape($text);
self::assertEquals($text, $retext);
}
}
/**
* escape and put in a document
*/
public function testEscapeDocument()
{
$tag="<tag>I want to break</tag>";
$xml=XML::escape($tag);
$text='<text>'.$xml.'</text>';
$xml_parser=xml_parser_create();
$tag = "<tag>I want to break</tag>";
$xml = XML::escape($tag);
$text = '<text>' . $xml . '</text>';
$xml_parser = xml_parser_create();
//should be possible to parse it
$values=array();
$index=array();
$values = [];
$index = [];
self::assertEquals(1, xml_parse_into_struct($xml_parser, $text, $values, $index));
self::assertEquals(
array('TEXT'=>array(0)),
['TEXT' => [0]],
$index
);
self::assertEquals(
array(array('tag'=>'TEXT', 'type'=>'complete', 'level'=>1, 'value'=>$tag)),
[['tag' => 'TEXT', 'type' => 'complete', 'level' => 1, 'value' => $tag]],
$values
);
xml_parser_free($xml_parser);