1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-09 18:16:36 +02:00

refactor: logger (#3678)

This commit is contained in:
Dag
2023-09-21 22:05:55 +02:00
committed by GitHub
parent 360f953be8
commit 7329b83cc0
30 changed files with 297 additions and 338 deletions

View File

@@ -1,69 +0,0 @@
<?php
namespace RssBridge\Tests\Actions;
use ActionInterface;
use PHPUnit\Framework\TestCase;
class ActionImplementationTest extends TestCase
{
private $class;
private $obj;
public function setUp(): void
{
\Configuration::loadConfiguration();
}
/**
* @dataProvider dataActionsProvider
*/
public function testClassName($path)
{
$this->setAction($path);
$this->assertTrue($this->class === ucfirst($this->class), 'class name must start with uppercase character');
$this->assertEquals(0, substr_count($this->class, ' '), 'class name must not contain spaces');
$this->assertStringEndsWith('Action', $this->class, 'class name must end with "Action"');
}
/**
* @dataProvider dataActionsProvider
*/
public function testClassType($path)
{
$this->setAction($path);
$this->assertInstanceOf(ActionInterface::class, $this->obj);
}
/**
* @dataProvider dataActionsProvider
*/
public function testVisibleMethods($path)
{
$allowedMethods = get_class_methods(ActionInterface::class);
sort($allowedMethods);
$this->setAction($path);
$methods = array_diff(get_class_methods($this->obj), ['__construct']);
sort($methods);
$this->assertEquals($allowedMethods, $methods);
}
public function dataActionsProvider()
{
$actions = [];
foreach (glob(PATH_LIB_ACTIONS . '*.php') as $path) {
$actions[basename($path, '.php')] = [$path];
}
return $actions;
}
private function setAction($path)
{
$this->class = '\\' . basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class();
}
}

View File

@@ -1,76 +0,0 @@
<?php
namespace RssBridge\Tests\Actions;
use BridgeFactory;
use PHPUnit\Framework\TestCase;
class ListActionTest extends TestCase
{
public function setUp(): void
{
\Configuration::loadConfiguration();
}
public function testHeaders()
{
$action = new \ListAction();
$response = $action->execute([]);
$headers = $response->getHeaders();
$contentType = $response->getHeader('content-type');
$this->assertSame($contentType, 'application/json');
}
public function testOutput()
{
$action = new \ListAction();
$response = $action->execute([]);
$data = $response->getBody();
$items = json_decode($data, true);
$this->assertNotNull($items, 'invalid JSON output: ' . json_last_error_msg());
$this->assertArrayHasKey('total', $items, 'Missing "total" parameter');
$this->assertIsInt($items['total'], 'Invalid type');
$this->assertArrayHasKey('bridges', $items, 'Missing "bridges" array');
$this->assertEquals(
$items['total'],
count($items['bridges']),
'Item count doesn\'t match'
);
$bridgeFactory = new BridgeFactory();
$this->assertEquals(
count($bridgeFactory->getBridgeClassNames()),
count($items['bridges']),
'Number of bridges doesn\'t match'
);
$expectedKeys = [
'status',
'uri',
'name',
'icon',
'parameters',
'maintainer',
'description'
];
$allowedStatus = [
'active',
'inactive'
];
foreach ($items['bridges'] as $bridge) {
foreach ($expectedKeys as $key) {
$this->assertArrayHasKey($key, $bridge, 'Missing key "' . $key . '"');
}
$this->assertContains($bridge['status'], $allowedStatus, 'Invalid status value');
}
}
}

View File

@@ -6,25 +6,14 @@ use PHPUnit\Framework\TestCase;
class BridgeFactoryTest extends TestCase
{
public function setUp(): void
{
\Configuration::loadConfiguration();
}
public function testNormalizeBridgeName()
{
$this->assertSame('TwitterBridge', \BridgeFactory::normalizeBridgeName('TwitterBridge'));
$this->assertSame('TwitterBridge', \BridgeFactory::normalizeBridgeName('TwitterBridge.php'));
$this->assertSame('TwitterBridge', \BridgeFactory::normalizeBridgeName('Twitter'));
}
public function testSanitizeBridgeName()
{
$sut = new \BridgeFactory();
$this->assertSame('TwitterBridge', $sut->createBridgeClassName('twitterbridge'));
$this->assertSame('TwitterBridge', $sut->createBridgeClassName('twitter'));
$this->assertSame('TwitterBridge', $sut->createBridgeClassName('tWitTer'));
$this->assertSame('TwitterBridge', $sut->createBridgeClassName('TWITTERBRIDGE'));
// $this->assertSame('TwitterBridge', $sut->createBridgeClassName('twitterbridge'));
// $this->assertSame('TwitterBridge', $sut->createBridgeClassName('twitter'));
// $this->assertSame('TwitterBridge', $sut->createBridgeClassName('tWitTer'));
// $this->assertSame('TwitterBridge', $sut->createBridgeClassName('TWITTERBRIDGE'));
}
}

View File

@@ -231,7 +231,10 @@ class BridgeImplementationTest extends TestCase
{
$this->class = '\\' . basename($path, '.php');
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
$this->obj = new $this->class();
$this->obj = new $this->class(
new \NullCache(),
new \NullLogger()
);
}
private function checkUrl($url)

View File

@@ -8,13 +8,13 @@ class CacheTest extends TestCase
{
public function testConfig()
{
$sut = new \FileCache(['path' => '/tmp/']);
$sut = new \FileCache(new \NullLogger(), ['path' => '/tmp/']);
$this->assertSame(['path' => '/tmp/', 'enable_purge' => true], $sut->getConfig());
$sut = new \FileCache(['path' => '/', 'enable_purge' => false]);
$sut = new \FileCache(new \NullLogger(), ['path' => '/', 'enable_purge' => false]);
$this->assertSame(['path' => '/', 'enable_purge' => false], $sut->getConfig());
$sut = new \FileCache(['path' => '/tmp', 'enable_purge' => true]);
$sut = new \FileCache(new \NullLogger(), ['path' => '/tmp', 'enable_purge' => true]);
$this->assertSame(['path' => '/tmp/', 'enable_purge' => true], $sut->getConfig());
}
@@ -23,7 +23,7 @@ class CacheTest extends TestCase
$temporaryFolder = sprintf('%s/rss_bridge_%s/', sys_get_temp_dir(), create_random_string());
mkdir($temporaryFolder);
$sut = new \FileCache([
$sut = new \FileCache(new \NullLogger(), [
'path' => $temporaryFolder,
'enable_purge' => true,
]);