}
foreach ($rows as $row) {
- $dba->insert($tableName, $row, true);
+ if (is_array($row)) {
+ $dba->insert($tableName, $row, true);
+ } else {
+ throw new \Exception('row isn\'t an array');
+ }
}
}
}
*/
trait DiceHttpMockHandlerTrait
{
+ use FixtureTestTrait;
+
/**
* Handler for mocking requests anywhere for testing purpose
*
protected function setupHttpMockHandler(): void
{
- if (!empty($this->httpRequestHandler) && $this->httpRequestHandler instanceof HandlerStack) {
- return;
- }
+ $this->setUpFixtures();
$this->httpRequestHandler = HandlerStack::create();
DI::init($newDice);
}
- protected function tearDown(): void
+ protected function tearDownHandler(): void
{
- \Mockery::close();
-
- parent::tearDown();
+ $this->tearDownFixtures();
}
}
/**
* Parent class for test cases requiring fixtures
*/
-abstract class FixtureTest extends DatabaseTest
+abstract class FixtureTest extends MockedTest
{
- use VFSTrait;
+ use FixtureTestTrait;
- /** @var Dice */
- protected $dice;
-
- /**
- * Create variables used by tests.
- */
protected function setUp(): void
{
- $this->setUpVfsDir();
-
parent::setUp();
- $server = $_SERVER;
- $server['REQUEST_METHOD'] = Router::GET;
-
- $this->dice = (new Dice())
- ->addRules(include __DIR__ . '/../static/dependencies.config.php')
- ->addRule(ConfigFileManager::class, [
- 'instanceOf' => Config::class,
- 'call' => [['createConfigFileManager', [$this->root->url(), $server,],
- Dice::CHAIN_CALL]]])
- ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
- ->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null])
- ->addRule(Arguments::class, [
- 'instanceOf' => Arguments::class,
- 'call' => [
- ['determine', [$server, $_GET], Dice::CHAIN_CALL],
- ],
- ]);
- DI::init($this->dice);
-
- $config = $this->dice->create(IManageConfigValues::class);
- $config->set('database', 'disable_pdo', true);
-
- /** @var Database $dba */
- $dba = $this->dice->create(Database::class);
-
- $dba->setTestmode(true);
-
- // Load the API dataset for the whole API
- $this->loadFixture(__DIR__ . '/datasets/api.fixture.php', $dba);
+ $this->setUpFixtures();
}
- protected function useHttpMethod(string $method = Router::GET)
+ protected function tearDown(): void
{
- $server = $_SERVER;
- $server['REQUEST_METHOD'] = $method;
-
- $this->dice = $this->dice
- ->addRule(Arguments::class, [
- 'instanceOf' => Arguments::class,
- 'call' => [
- ['determine', [$server, $_GET], Dice::CHAIN_CALL],
- ],
- ]);
+ $this->tearDownFixtures();
- DI::init($this->dice);
+ parent::tearDown();
}
}
--- /dev/null
+<?php
+
+namespace Friendica\Test;
+
+use Dice\Dice;
+use Friendica\App\Arguments;
+use Friendica\App\Router;
+use Friendica\Core\Config\Capability\IManageConfigValues;
+use Friendica\Core\Config\Factory\Config;
+use Friendica\Core\Config\Util\ConfigFileManager;
+use Friendica\Core\Session\Capability\IHandleSessions;
+use Friendica\Core\Session\Type\Memory;
+use Friendica\Database\Database;
+use Friendica\Database\DBStructure;
+use Friendica\DI;
+use Friendica\Test\Util\Database\StaticDatabase;
+use Friendica\Test\Util\VFSTrait;
+
+trait FixtureTestTrait
+{
+ use VFSTrait;
+ use DatabaseTestTrait;
+
+ /** @var Dice */
+ protected $dice;
+
+ /**
+ * Create variables used by tests.
+ */
+ protected function setUpFixtures(): void
+ {
+ $this->setUpVfsDir();
+ $this->setUpDb();
+
+ $server = $_SERVER;
+ $server['REQUEST_METHOD'] = Router::GET;
+
+ $this->dice = (new Dice())
+ ->addRules(include __DIR__ . '/../static/dependencies.config.php')
+ ->addRule(ConfigFileManager::class, [
+ 'instanceOf' => Config::class,
+ 'call' => [['createConfigFileManager', [$this->root->url(), $server,],
+ Dice::CHAIN_CALL]]])
+ ->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
+ ->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null])
+ ->addRule(Arguments::class, [
+ 'instanceOf' => Arguments::class,
+ 'call' => [
+ ['determine', [$server, $_GET], Dice::CHAIN_CALL],
+ ],
+ ]);
+ DI::init($this->dice, true);
+
+ $config = $this->dice->create(IManageConfigValues::class);
+ $config->set('database', 'disable_pdo', true);
+
+ /** @var Database $dba */
+ $dba = $this->dice->create(Database::class);
+ $dba->setTestmode(true);
+
+ DBStructure::checkInitialValues();
+
+ // Load the API dataset for the whole API
+ $this->loadFixture(__DIR__ . '/datasets/api.fixture.php', $dba);
+ }
+
+ protected function tearDownFixtures(): void
+ {
+ $this->tearDownDb();
+ }
+
+ protected function useHttpMethod(string $method = Router::GET)
+ {
+ $server = $_SERVER;
+ $server['REQUEST_METHOD'] = $method;
+
+ $this->dice = $this->dice
+ ->addRule(Arguments::class, [
+ 'instanceOf' => Arguments::class,
+ 'call' => [
+ ['determine', [$server, $_GET], Dice::CHAIN_CALL],
+ ],
+ ]);
+
+ DI::init($this->dice);
+ }
+}
'workerqueue',
'mail',
'post-delivery-data',
+ 'gserver' => [
+ [
+ 'id' => 42,
+ 'url' => 'https://friendica.test',
+ 'info' => 'test_node',
+ 'active-week-users' => 1,
+ 'active-month-users' => 1,
+ 'active-halfyear-users' => 1,
+ 'local-posts' => 42,
+ 'local-comments' => 42,
+ 'protocol' => 'apub',
+ 'detection-method' => 'none',
+ 'blocked' => 0,
+ 'failed' => 0,
+ ],
+ ],
// Base test config to avoid notice messages
'user' => [
[
namespace Friendica\Test\functional;
-use Dice\Dice;
use Friendica\App;
use Friendica\Core\Cache\Capability\ICanCache;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Database\Database;
-use Friendica\Test\Util\VFSTrait;
+use Friendica\Test\FixtureTest;
use Friendica\Util\BasePath;
use Friendica\Core\Config\Util\ConfigFileManager;
-use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
-class DependencyCheckTest extends TestCase
+class DependencyCheckTest extends FixtureTest
{
- use VFSTrait;
-
- /**
- * @var Dice
- */
- private $dice;
-
protected function setUp() : void
{
parent::setUp();
- $this->setUpVfsDir();
-
- $this->dice = (new Dice())
- ->addRules(include __DIR__ . '/../../static/dependencies.config.php')
- ->addRule(BasePath::class, [
- 'constructParams' => [
- $this->root->url(),
- [],
- ],
- ])
- ->addRule(LoggerInterface::class, ['constructParams' => ['test']]);
-
/** @var IManageConfigValues $config */
$config = $this->dice->create(IManageConfigValues::class);
$config->set('system', 'logfile', $this->root->url() . '/logs/friendica.log');
self::assertInstanceOf(BasePath::class, $basePath);
self::assertEquals($this->root->url(), $basePath->getPath());
+
+ /** @var Database $dba */
+ $dba = $this->dice->create(Database::class);
}
/**
namespace Friendica\Test\src\Console;
-use Dice\Dice;
use Friendica\Console\ServerBlock;
-use Friendica\Core\Config\Capability\IManageConfigValues;
-use Friendica\DI;
use Friendica\Moderation\DomainPatternBlocklist;
+use Friendica\Test\FixtureTestTrait;
use Mockery;
class ServerBlockConsoleTest extends ConsoleTest
{
+ use FixtureTestTrait;
+
protected $defaultBlockList = [
[
'domain' => 'social.nobodyhasthe.biz',
{
parent::setUp();
+ $this->setUpFixtures();
+
$this->blocklistMock = Mockery::mock(DomainPatternBlocklist::class);
}
+ protected function tearDown(): void
+ {
+ $this->tearDownFixtures();
+
+ parent::tearDown();
+ }
+
/**
* Test to list the default blocked servers
*/
*/
public function testAddBlockedServer()
{
- $dice = new Dice();
- $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
-
- DI::init($dice, true);
-
$this->blocklistMock
->shouldReceive('addPattern')
->with('testme.now', 'I like it!')
*/
public function testUpdateBlockedServer()
{
- $dice = new Dice();
- $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
-
- DI::init($dice, true);
-
$this->blocklistMock
->shouldReceive('addPattern')
->with('pod.ordoevangelistarum.com', 'Other reason')
*/
public function testRemoveBlockedServer()
{
- $dice = new Dice();
- $dice = $dice->addRules(include __DIR__ . '/../../../static/dependencies.config.php');
-
- DI::init($dice, true);
-
$this->blocklistMock
->shouldReceive('removePattern')
->with('pod.ordoevangelistarum.com')
namespace Friendica\Test\src\Content;
-use Friendica\Test\MockedTest;
+use Friendica\Test\DatabaseTest;
-class PageInfoTest extends MockedTest
+class PageInfoTest extends DatabaseTest
{
public function dataGetRelevantUrlFromBody()
{
$this->setupHttpMockHandler();
}
+ protected function tearDown(): void
+ {
+ $this->tearDownHandler();
+
+ parent::tearDown();
+ }
+
/**
* Test for issue https://github.com/friendica/friendica/issues/10473#issuecomment-907749093
*/
use Friendica\Network\Probe;
use Friendica\Test\DiceHttpMockHandlerTrait;
-use Friendica\Test\FixtureTest;
+use Friendica\Test\MockedTest;
use GuzzleHttp\Middleware;
-class ProbeTest extends FixtureTest
+class ProbeTest extends MockedTest
{
use DiceHttpMockHandlerTrait;
$this->setupHttpMockHandler();
}
+ protected function tearDown(): void
+ {
+ $this->tearDownHandler();
+
+ parent::tearDown();
+ }
+
const TEMPLATENOBASE = '
<!DOCTYPE html>
<html lang="en-us">
$this->setupHttpMockHandler();
}
+ protected function tearDown(): void
+ {
+ $this->tearDownFixtures();
+
+ parent::tearDown();
+ }
+
public function dataImages()
{
return [