mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-07-16 06:26:24 +02:00
Reformat codebase v4 (#2872)
Reformat code base to PSR12 Co-authored-by: rssbridge <noreply@github.com>
This commit is contained in:
@ -5,54 +5,60 @@ namespace RssBridge\Tests\Actions;
|
||||
use ActionInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ActionImplementationTest extends TestCase {
|
||||
private $class;
|
||||
private $obj;
|
||||
class ActionImplementationTest extends TestCase
|
||||
{
|
||||
private $class;
|
||||
private $obj;
|
||||
|
||||
/**
|
||||
* @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 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 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);
|
||||
/**
|
||||
* @dataProvider dataActionsProvider
|
||||
*/
|
||||
public function testVisibleMethods($path)
|
||||
{
|
||||
$allowedMethods = get_class_methods(ActionInterface::class);
|
||||
sort($allowedMethods);
|
||||
|
||||
$this->setAction($path);
|
||||
$this->setAction($path);
|
||||
|
||||
$methods = get_class_methods($this->obj);
|
||||
sort($methods);
|
||||
$methods = get_class_methods($this->obj);
|
||||
sort($methods);
|
||||
|
||||
$this->assertEquals($allowedMethods, $methods);
|
||||
}
|
||||
$this->assertEquals($allowedMethods, $methods);
|
||||
}
|
||||
|
||||
public function dataActionsProvider() {
|
||||
$actions = array();
|
||||
foreach (glob(PATH_LIB_ACTIONS . '*.php') as $path) {
|
||||
$actions[basename($path, '.php')] = array($path);
|
||||
}
|
||||
return $actions;
|
||||
}
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -6,85 +6,88 @@ use ActionFactory;
|
||||
use BridgeFactory;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ListActionTest extends TestCase {
|
||||
class ListActionTest extends TestCase
|
||||
{
|
||||
private $data;
|
||||
|
||||
private $data;
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @requires function xdebug_get_headers
|
||||
*/
|
||||
public function testHeaders()
|
||||
{
|
||||
$this->initAction();
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @requires function xdebug_get_headers
|
||||
*/
|
||||
public function testHeaders() {
|
||||
$this->initAction();
|
||||
$this->assertContains(
|
||||
'Content-Type: application/json',
|
||||
xdebug_get_headers()
|
||||
);
|
||||
}
|
||||
|
||||
$this->assertContains(
|
||||
'Content-Type: application/json',
|
||||
xdebug_get_headers()
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput()
|
||||
{
|
||||
$this->initAction();
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput() {
|
||||
$this->initAction();
|
||||
$items = json_decode($this->data, true);
|
||||
|
||||
$items = json_decode($this->data, true);
|
||||
$this->assertNotNull($items, 'invalid JSON output: ' . json_last_error_msg());
|
||||
|
||||
$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('total', $items, 'Missing "total" parameter');
|
||||
$this->assertIsInt($items['total'], 'Invalid type');
|
||||
$this->assertArrayHasKey('bridges', $items, 'Missing "bridges" array');
|
||||
|
||||
$this->assertArrayHasKey('bridges', $items, 'Missing "bridges" array');
|
||||
$this->assertEquals(
|
||||
$items['total'],
|
||||
count($items['bridges']),
|
||||
'Item count doesn\'t match'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
$items['total'],
|
||||
count($items['bridges']),
|
||||
'Item count doesn\'t match'
|
||||
);
|
||||
$bridgeFac = new BridgeFactory();
|
||||
|
||||
$bridgeFac = new BridgeFactory();
|
||||
$this->assertEquals(
|
||||
count($bridgeFac->getBridgeNames()),
|
||||
count($items['bridges']),
|
||||
'Number of bridges doesn\'t match'
|
||||
);
|
||||
|
||||
$this->assertEquals(
|
||||
count($bridgeFac->getBridgeNames()),
|
||||
count($items['bridges']),
|
||||
'Number of bridges doesn\'t match'
|
||||
);
|
||||
$expectedKeys = [
|
||||
'status',
|
||||
'uri',
|
||||
'name',
|
||||
'icon',
|
||||
'parameters',
|
||||
'maintainer',
|
||||
'description'
|
||||
];
|
||||
|
||||
$expectedKeys = array(
|
||||
'status',
|
||||
'uri',
|
||||
'name',
|
||||
'icon',
|
||||
'parameters',
|
||||
'maintainer',
|
||||
'description'
|
||||
);
|
||||
$allowedStatus = [
|
||||
'active',
|
||||
'inactive'
|
||||
];
|
||||
|
||||
$allowedStatus = array(
|
||||
'active',
|
||||
'inactive'
|
||||
);
|
||||
foreach ($items['bridges'] as $bridge) {
|
||||
foreach ($expectedKeys as $key) {
|
||||
$this->assertArrayHasKey($key, $bridge, 'Missing key "' . $key . '"');
|
||||
}
|
||||
|
||||
foreach($items['bridges'] as $bridge) {
|
||||
foreach($expectedKeys as $key) {
|
||||
$this->assertArrayHasKey($key, $bridge, 'Missing key "' . $key . '"');
|
||||
}
|
||||
$this->assertContains($bridge['status'], $allowedStatus, 'Invalid status value');
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertContains($bridge['status'], $allowedStatus, 'Invalid status value');
|
||||
}
|
||||
}
|
||||
private function initAction()
|
||||
{
|
||||
$actionFac = new ActionFactory();
|
||||
|
||||
private function initAction() {
|
||||
$actionFac = new ActionFactory();
|
||||
$action = $actionFac->create('list');
|
||||
|
||||
$action = $actionFac->create('list');
|
||||
|
||||
ob_start();
|
||||
$action->execute();
|
||||
$this->data = ob_get_contents();
|
||||
ob_clean();
|
||||
ob_end_flush();
|
||||
}
|
||||
ob_start();
|
||||
$action->execute();
|
||||
$this->data = ob_get_contents();
|
||||
ob_clean();
|
||||
ob_end_flush();
|
||||
}
|
||||
}
|
||||
|
@ -7,223 +7,236 @@ use BridgeInterface;
|
||||
use FeedExpander;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BridgeImplementationTest extends TestCase {
|
||||
private $class;
|
||||
private $obj;
|
||||
class BridgeImplementationTest extends TestCase
|
||||
{
|
||||
private $class;
|
||||
private $obj;
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testClassName($path) {
|
||||
$this->setBridge($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('Bridge', $this->class, 'class name must end with "Bridge"');
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testClassName($path)
|
||||
{
|
||||
$this->setBridge($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('Bridge', $this->class, 'class name must end with "Bridge"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testClassType($path) {
|
||||
$this->setBridge($path);
|
||||
$this->assertInstanceOf(BridgeInterface::class, $this->obj);
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testClassType($path)
|
||||
{
|
||||
$this->setBridge($path);
|
||||
$this->assertInstanceOf(BridgeInterface::class, $this->obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testConstants($path) {
|
||||
$this->setBridge($path);
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testConstants($path)
|
||||
{
|
||||
$this->setBridge($path);
|
||||
|
||||
$this->assertIsString($this->obj::NAME, 'class::NAME');
|
||||
$this->assertNotEmpty($this->obj::NAME, 'class::NAME');
|
||||
$this->assertIsString($this->obj::URI, 'class::URI');
|
||||
$this->assertNotEmpty($this->obj::URI, 'class::URI');
|
||||
$this->assertIsString($this->obj::DESCRIPTION, 'class::DESCRIPTION');
|
||||
$this->assertNotEmpty($this->obj::DESCRIPTION, 'class::DESCRIPTION');
|
||||
$this->assertIsString($this->obj::MAINTAINER, 'class::MAINTAINER');
|
||||
$this->assertNotEmpty($this->obj::MAINTAINER, 'class::MAINTAINER');
|
||||
$this->assertIsString($this->obj::NAME, 'class::NAME');
|
||||
$this->assertNotEmpty($this->obj::NAME, 'class::NAME');
|
||||
$this->assertIsString($this->obj::URI, 'class::URI');
|
||||
$this->assertNotEmpty($this->obj::URI, 'class::URI');
|
||||
$this->assertIsString($this->obj::DESCRIPTION, 'class::DESCRIPTION');
|
||||
$this->assertNotEmpty($this->obj::DESCRIPTION, 'class::DESCRIPTION');
|
||||
$this->assertIsString($this->obj::MAINTAINER, 'class::MAINTAINER');
|
||||
$this->assertNotEmpty($this->obj::MAINTAINER, 'class::MAINTAINER');
|
||||
|
||||
$this->assertIsArray($this->obj::PARAMETERS, 'class::PARAMETERS');
|
||||
$this->assertIsInt($this->obj::CACHE_TIMEOUT, 'class::CACHE_TIMEOUT');
|
||||
$this->assertGreaterThanOrEqual(0, $this->obj::CACHE_TIMEOUT, 'class::CACHE_TIMEOUT');
|
||||
}
|
||||
$this->assertIsArray($this->obj::PARAMETERS, 'class::PARAMETERS');
|
||||
$this->assertIsInt($this->obj::CACHE_TIMEOUT, 'class::CACHE_TIMEOUT');
|
||||
$this->assertGreaterThanOrEqual(0, $this->obj::CACHE_TIMEOUT, 'class::CACHE_TIMEOUT');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testParameters($path) {
|
||||
$this->setBridge($path);
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testParameters($path)
|
||||
{
|
||||
$this->setBridge($path);
|
||||
|
||||
$multiMinimum = 2;
|
||||
if (isset($this->obj::PARAMETERS['global'])) {
|
||||
++$multiMinimum;
|
||||
}
|
||||
$multiContexts = (count($this->obj::PARAMETERS) >= $multiMinimum);
|
||||
$paramsSeen = array();
|
||||
$multiMinimum = 2;
|
||||
if (isset($this->obj::PARAMETERS['global'])) {
|
||||
++$multiMinimum;
|
||||
}
|
||||
$multiContexts = (count($this->obj::PARAMETERS) >= $multiMinimum);
|
||||
$paramsSeen = [];
|
||||
|
||||
$allowedTypes = array(
|
||||
'text',
|
||||
'number',
|
||||
'list',
|
||||
'checkbox'
|
||||
);
|
||||
$allowedTypes = [
|
||||
'text',
|
||||
'number',
|
||||
'list',
|
||||
'checkbox'
|
||||
];
|
||||
|
||||
foreach($this->obj::PARAMETERS as $context => $params) {
|
||||
if ($multiContexts) {
|
||||
$this->assertIsString($context, 'invalid context name');
|
||||
foreach ($this->obj::PARAMETERS as $context => $params) {
|
||||
if ($multiContexts) {
|
||||
$this->assertIsString($context, 'invalid context name');
|
||||
|
||||
$this->assertNotEmpty($context, 'The context name cannot be empty');
|
||||
}
|
||||
$this->assertNotEmpty($context, 'The context name cannot be empty');
|
||||
}
|
||||
|
||||
if (empty($params)) {
|
||||
continue;
|
||||
}
|
||||
if (empty($params)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($paramsSeen as $seen) {
|
||||
$this->assertNotEquals($seen, $params, 'same set of parameters not allowed');
|
||||
}
|
||||
$paramsSeen[] = $params;
|
||||
foreach ($paramsSeen as $seen) {
|
||||
$this->assertNotEquals($seen, $params, 'same set of parameters not allowed');
|
||||
}
|
||||
$paramsSeen[] = $params;
|
||||
|
||||
foreach ($params as $field => $options) {
|
||||
$this->assertIsString($field, $field . ': invalid id');
|
||||
$this->assertNotEmpty($field, $field . ':empty id');
|
||||
foreach ($params as $field => $options) {
|
||||
$this->assertIsString($field, $field . ': invalid id');
|
||||
$this->assertNotEmpty($field, $field . ':empty id');
|
||||
|
||||
$this->assertIsString($options['name'], $field . ': invalid name');
|
||||
$this->assertNotEmpty($options['name'], $field . ': empty name');
|
||||
$this->assertIsString($options['name'], $field . ': invalid name');
|
||||
$this->assertNotEmpty($options['name'], $field . ': empty name');
|
||||
|
||||
if (isset($options['type'])) {
|
||||
$this->assertIsString($options['type'], $field . ': invalid type');
|
||||
$this->assertContains($options['type'], $allowedTypes, $field . ': unknown type');
|
||||
if (isset($options['type'])) {
|
||||
$this->assertIsString($options['type'], $field . ': invalid type');
|
||||
$this->assertContains($options['type'], $allowedTypes, $field . ': unknown type');
|
||||
|
||||
if ($options['type'] == 'list') {
|
||||
$this->assertArrayHasKey('values', $options, $field . ': missing list values');
|
||||
$this->assertIsArray($options['values'], $field . ': invalid list values');
|
||||
$this->assertNotEmpty($options['values'], $field . ': empty list values');
|
||||
if ($options['type'] == 'list') {
|
||||
$this->assertArrayHasKey('values', $options, $field . ': missing list values');
|
||||
$this->assertIsArray($options['values'], $field . ': invalid list values');
|
||||
$this->assertNotEmpty($options['values'], $field . ': empty list values');
|
||||
|
||||
foreach ($options['values'] as $valueName => $value) {
|
||||
$this->assertIsString($valueName, $field . ': invalid value name');
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($options['values'] as $valueName => $value) {
|
||||
$this->assertIsString($valueName, $field . ': invalid value name');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['required'])) {
|
||||
$this->assertIsBool($options['required'], $field . ': invalid required');
|
||||
if (isset($options['required'])) {
|
||||
$this->assertIsBool($options['required'], $field . ': invalid required');
|
||||
|
||||
if($options['required'] === true && isset($options['type'])) {
|
||||
switch($options['type']) {
|
||||
case 'list':
|
||||
case 'checkbox':
|
||||
$this->assertArrayNotHasKey(
|
||||
'required',
|
||||
$options,
|
||||
$field . ': "required" attribute not supported for ' . $options['type']
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($options['required'] === true && isset($options['type'])) {
|
||||
switch ($options['type']) {
|
||||
case 'list':
|
||||
case 'checkbox':
|
||||
$this->assertArrayNotHasKey(
|
||||
'required',
|
||||
$options,
|
||||
$field . ': "required" attribute not supported for ' . $options['type']
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['title'])) {
|
||||
$this->assertIsString($options['title'], $field . ': invalid title');
|
||||
$this->assertNotEmpty($options['title'], $field . ': empty title');
|
||||
}
|
||||
if (isset($options['title'])) {
|
||||
$this->assertIsString($options['title'], $field . ': invalid title');
|
||||
$this->assertNotEmpty($options['title'], $field . ': empty title');
|
||||
}
|
||||
|
||||
if (isset($options['pattern'])) {
|
||||
$this->assertIsString($options['pattern'], $field . ': invalid pattern');
|
||||
$this->assertNotEquals('', $options['pattern'], $field . ': empty pattern');
|
||||
}
|
||||
if (isset($options['pattern'])) {
|
||||
$this->assertIsString($options['pattern'], $field . ': invalid pattern');
|
||||
$this->assertNotEquals('', $options['pattern'], $field . ': empty pattern');
|
||||
}
|
||||
|
||||
if (isset($options['exampleValue'])) {
|
||||
if (is_string($options['exampleValue']))
|
||||
$this->assertNotEquals('', $options['exampleValue'], $field . ': empty exampleValue');
|
||||
}
|
||||
if (isset($options['exampleValue'])) {
|
||||
if (is_string($options['exampleValue'])) {
|
||||
$this->assertNotEquals('', $options['exampleValue'], $field . ': empty exampleValue');
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($options['defaultValue'])) {
|
||||
if (is_string($options['defaultValue']))
|
||||
$this->assertNotEquals('', $options['defaultValue'], $field . ': empty defaultValue');
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isset($options['defaultValue'])) {
|
||||
if (is_string($options['defaultValue'])) {
|
||||
$this->assertNotEquals('', $options['defaultValue'], $field . ': empty defaultValue');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->obj::TEST_DETECT_PARAMETERS as $url => $params) {
|
||||
$this->assertEquals($this->obj->detectParameters($url), $params);
|
||||
}
|
||||
foreach ($this->obj::TEST_DETECT_PARAMETERS as $url => $params) {
|
||||
$this->assertEquals($this->obj->detectParameters($url), $params);
|
||||
}
|
||||
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testVisibleMethods($path) {
|
||||
$allowedBridgeAbstract = get_class_methods(BridgeAbstract::class);
|
||||
sort($allowedBridgeAbstract);
|
||||
$allowedFeedExpander = get_class_methods(FeedExpander::class);
|
||||
sort($allowedFeedExpander);
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testVisibleMethods($path)
|
||||
{
|
||||
$allowedBridgeAbstract = get_class_methods(BridgeAbstract::class);
|
||||
sort($allowedBridgeAbstract);
|
||||
$allowedFeedExpander = get_class_methods(FeedExpander::class);
|
||||
sort($allowedFeedExpander);
|
||||
|
||||
$this->setBridge($path);
|
||||
$this->setBridge($path);
|
||||
|
||||
$methods = get_class_methods($this->obj);
|
||||
sort($methods);
|
||||
if ($this->obj instanceof FeedExpander) {
|
||||
$this->assertEquals($allowedFeedExpander, $methods);
|
||||
} else {
|
||||
$this->assertEquals($allowedBridgeAbstract, $methods);
|
||||
}
|
||||
}
|
||||
$methods = get_class_methods($this->obj);
|
||||
sort($methods);
|
||||
if ($this->obj instanceof FeedExpander) {
|
||||
$this->assertEquals($allowedFeedExpander, $methods);
|
||||
} else {
|
||||
$this->assertEquals($allowedBridgeAbstract, $methods);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testMethodValues($path) {
|
||||
$this->setBridge($path);
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testMethodValues($path)
|
||||
{
|
||||
$this->setBridge($path);
|
||||
|
||||
$value = $this->obj->getDescription();
|
||||
$this->assertIsString($value, '$class->getDescription()');
|
||||
$this->assertNotEmpty($value, '$class->getDescription()');
|
||||
$value = $this->obj->getDescription();
|
||||
$this->assertIsString($value, '$class->getDescription()');
|
||||
$this->assertNotEmpty($value, '$class->getDescription()');
|
||||
|
||||
$value = $this->obj->getMaintainer();
|
||||
$this->assertIsString($value, '$class->getMaintainer()');
|
||||
$this->assertNotEmpty($value, '$class->getMaintainer()');
|
||||
$value = $this->obj->getMaintainer();
|
||||
$this->assertIsString($value, '$class->getMaintainer()');
|
||||
$this->assertNotEmpty($value, '$class->getMaintainer()');
|
||||
|
||||
$value = $this->obj->getName();
|
||||
$this->assertIsString($value, '$class->getName()');
|
||||
$this->assertNotEmpty($value, '$class->getName()');
|
||||
$value = $this->obj->getName();
|
||||
$this->assertIsString($value, '$class->getName()');
|
||||
$this->assertNotEmpty($value, '$class->getName()');
|
||||
|
||||
$value = $this->obj->getURI();
|
||||
$this->assertIsString($value, '$class->getURI()');
|
||||
$this->assertNotEmpty($value, '$class->getURI()');
|
||||
$value = $this->obj->getURI();
|
||||
$this->assertIsString($value, '$class->getURI()');
|
||||
$this->assertNotEmpty($value, '$class->getURI()');
|
||||
|
||||
$value = $this->obj->getIcon();
|
||||
$this->assertIsString($value, '$class->getIcon()');
|
||||
}
|
||||
$value = $this->obj->getIcon();
|
||||
$this->assertIsString($value, '$class->getIcon()');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testUri($path) {
|
||||
$this->setBridge($path);
|
||||
/**
|
||||
* @dataProvider dataBridgesProvider
|
||||
*/
|
||||
public function testUri($path)
|
||||
{
|
||||
$this->setBridge($path);
|
||||
|
||||
$this->checkUrl($this->obj::URI);
|
||||
$this->checkUrl($this->obj->getURI());
|
||||
}
|
||||
$this->checkUrl($this->obj::URI);
|
||||
$this->checkUrl($this->obj->getURI());
|
||||
}
|
||||
|
||||
public function dataBridgesProvider() {
|
||||
$bridges = array();
|
||||
foreach (glob(PATH_LIB_BRIDGES . '*Bridge.php') as $path) {
|
||||
$bridges[basename($path, '.php')] = array($path);
|
||||
}
|
||||
return $bridges;
|
||||
}
|
||||
public function dataBridgesProvider()
|
||||
{
|
||||
$bridges = [];
|
||||
foreach (glob(PATH_LIB_BRIDGES . '*Bridge.php') as $path) {
|
||||
$bridges[basename($path, '.php')] = [$path];
|
||||
}
|
||||
return $bridges;
|
||||
}
|
||||
|
||||
private function setBridge($path) {
|
||||
$this->class = '\\' . basename($path, '.php');
|
||||
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
|
||||
$this->obj = new $this->class();
|
||||
}
|
||||
private function setBridge($path)
|
||||
{
|
||||
$this->class = '\\' . basename($path, '.php');
|
||||
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
|
||||
$this->obj = new $this->class();
|
||||
}
|
||||
|
||||
private function checkUrl($url) {
|
||||
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL), 'no valid URL: ' . $url);
|
||||
}
|
||||
private function checkUrl($url)
|
||||
{
|
||||
$this->assertNotFalse(filter_var($url, FILTER_VALIDATE_URL), 'no valid URL: ' . $url);
|
||||
}
|
||||
}
|
||||
|
@ -5,39 +5,44 @@ namespace RssBridge\Tests\Caches;
|
||||
use CacheInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CacheImplementationTest extends TestCase {
|
||||
private $class;
|
||||
class CacheImplementationTest extends TestCase
|
||||
{
|
||||
private $class;
|
||||
|
||||
/**
|
||||
* @dataProvider dataCachesProvider
|
||||
*/
|
||||
public function testClassName($path) {
|
||||
$this->setCache($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('Cache', $this->class, 'class name must end with "Cache"');
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataCachesProvider
|
||||
*/
|
||||
public function testClassName($path)
|
||||
{
|
||||
$this->setCache($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('Cache', $this->class, 'class name must end with "Cache"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataCachesProvider
|
||||
*/
|
||||
public function testClassType($path) {
|
||||
$this->setCache($path);
|
||||
$this->assertTrue(is_subclass_of($this->class, CacheInterface::class), 'class must be subclass of CacheInterface');
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataCachesProvider
|
||||
*/
|
||||
public function testClassType($path)
|
||||
{
|
||||
$this->setCache($path);
|
||||
$this->assertTrue(is_subclass_of($this->class, CacheInterface::class), 'class must be subclass of CacheInterface');
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public function dataCachesProvider() {
|
||||
$caches = array();
|
||||
foreach (glob(PATH_LIB_CACHES . '*.php') as $path) {
|
||||
$caches[basename($path, '.php')] = array($path);
|
||||
}
|
||||
return $caches;
|
||||
}
|
||||
public function dataCachesProvider()
|
||||
{
|
||||
$caches = [];
|
||||
foreach (glob(PATH_LIB_CACHES . '*.php') as $path) {
|
||||
$caches[basename($path, '.php')] = [$path];
|
||||
}
|
||||
return $caches;
|
||||
}
|
||||
|
||||
private function setCache($path) {
|
||||
$this->class = '\\' . basename($path, '.php');
|
||||
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
|
||||
}
|
||||
private function setCache($path)
|
||||
{
|
||||
$this->class = '\\' . basename($path, '.php');
|
||||
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* AtomFormat - RFC 4287: The Atom Syndication Format
|
||||
* https://tools.ietf.org/html/rfc4287
|
||||
@ -10,18 +11,20 @@ require_once __DIR__ . '/BaseFormatTest.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AtomFormatTest extends BaseFormatTest {
|
||||
private const PATH_EXPECTED = self::PATH_SAMPLES . 'expectedAtomFormat/';
|
||||
class AtomFormatTest extends BaseFormatTest
|
||||
{
|
||||
private const PATH_EXPECTED = self::PATH_SAMPLES . 'expectedAtomFormat/';
|
||||
|
||||
/**
|
||||
* @dataProvider sampleProvider
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput(string $name, string $path) {
|
||||
$data = $this->formatData('Atom', $this->loadSample($path));
|
||||
$this->assertNotFalse(simplexml_load_string($data));
|
||||
/**
|
||||
* @dataProvider sampleProvider
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput(string $name, string $path)
|
||||
{
|
||||
$data = $this->formatData('Atom', $this->loadSample($path));
|
||||
$this->assertNotFalse(simplexml_load_string($data));
|
||||
|
||||
$expected = self::PATH_EXPECTED . $name . '.xml';
|
||||
$this->assertXmlStringEqualsXmlFile($expected, $data);
|
||||
}
|
||||
$expected = self::PATH_EXPECTED . $name . '.xml';
|
||||
$this->assertXmlStringEqualsXmlFile($expected, $data);
|
||||
}
|
||||
}
|
||||
|
@ -5,59 +5,65 @@ namespace RssBridge\Tests\Formats;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use FormatFactory;
|
||||
|
||||
abstract class BaseFormatTest extends TestCase {
|
||||
protected const PATH_SAMPLES = __DIR__ . '/samples/';
|
||||
abstract class BaseFormatTest extends TestCase
|
||||
{
|
||||
protected const PATH_SAMPLES = __DIR__ . '/samples/';
|
||||
|
||||
/**
|
||||
* @return array<string, array{string, string}>
|
||||
*/
|
||||
public function sampleProvider() {
|
||||
$samples = [];
|
||||
foreach (glob(self::PATH_SAMPLES . '*.json') as $path) {
|
||||
$name = basename($path, '.json');
|
||||
$samples[$name] = [
|
||||
$name,
|
||||
$path,
|
||||
];
|
||||
}
|
||||
return $samples;
|
||||
}
|
||||
/**
|
||||
* @return array<string, array{string, string}>
|
||||
*/
|
||||
public function sampleProvider()
|
||||
{
|
||||
$samples = [];
|
||||
foreach (glob(self::PATH_SAMPLES . '*.json') as $path) {
|
||||
$name = basename($path, '.json');
|
||||
$samples[$name] = [
|
||||
$name,
|
||||
$path,
|
||||
];
|
||||
}
|
||||
return $samples;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cannot be part of the sample returned by sampleProvider since this modifies $_SERVER
|
||||
* and thus needs to be run in a separate process to avoid side effects.
|
||||
*/
|
||||
protected function loadSample(string $path): \stdClass {
|
||||
$data = json_decode(file_get_contents($path), true);
|
||||
if (isset($data['meta']) && isset($data['items'])) {
|
||||
if (!empty($data['server']))
|
||||
$this->setServerVars($data['server']);
|
||||
/**
|
||||
* Cannot be part of the sample returned by sampleProvider since this modifies $_SERVER
|
||||
* and thus needs to be run in a separate process to avoid side effects.
|
||||
*/
|
||||
protected function loadSample(string $path): \stdClass
|
||||
{
|
||||
$data = json_decode(file_get_contents($path), true);
|
||||
if (isset($data['meta']) && isset($data['items'])) {
|
||||
if (!empty($data['server'])) {
|
||||
$this->setServerVars($data['server']);
|
||||
}
|
||||
|
||||
$items = array();
|
||||
foreach($data['items'] as $item) {
|
||||
$items[] = new \FeedItem($item);
|
||||
}
|
||||
$items = [];
|
||||
foreach ($data['items'] as $item) {
|
||||
$items[] = new \FeedItem($item);
|
||||
}
|
||||
|
||||
return (object)array(
|
||||
'meta' => $data['meta'],
|
||||
'items' => $items,
|
||||
);
|
||||
} else {
|
||||
$this->fail('invalid test sample: ' . basename($path, '.json'));
|
||||
}
|
||||
}
|
||||
return (object)[
|
||||
'meta' => $data['meta'],
|
||||
'items' => $items,
|
||||
];
|
||||
} else {
|
||||
$this->fail('invalid test sample: ' . basename($path, '.json'));
|
||||
}
|
||||
}
|
||||
|
||||
private function setServerVars(array $list): void {
|
||||
$_SERVER = array_merge($_SERVER, $list);
|
||||
}
|
||||
private function setServerVars(array $list): void
|
||||
{
|
||||
$_SERVER = array_merge($_SERVER, $list);
|
||||
}
|
||||
|
||||
protected function formatData(string $formatName, \stdClass $sample): string {
|
||||
$formatFac = new FormatFactory();
|
||||
$format = $formatFac->create($formatName);
|
||||
$format->setItems($sample->items);
|
||||
$format->setExtraInfos($sample->meta);
|
||||
$format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));
|
||||
protected function formatData(string $formatName, \stdClass $sample): string
|
||||
{
|
||||
$formatFac = new FormatFactory();
|
||||
$format = $formatFac->create($formatName);
|
||||
$format->setItems($sample->items);
|
||||
$format->setExtraInfos($sample->meta);
|
||||
$format->setLastModified(strtotime('2000-01-01 12:00:00 UTC'));
|
||||
|
||||
return $format->stringify();
|
||||
}
|
||||
return $format->stringify();
|
||||
}
|
||||
}
|
||||
|
@ -2,39 +2,44 @@
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class FormatImplementationTest extends TestCase {
|
||||
private $class;
|
||||
private $obj;
|
||||
class FormatImplementationTest extends TestCase
|
||||
{
|
||||
private $class;
|
||||
private $obj;
|
||||
|
||||
/**
|
||||
* @dataProvider dataFormatsProvider
|
||||
*/
|
||||
public function testClassName($path) {
|
||||
$this->setFormat($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('Format', $this->class, 'class name must end with "Format"');
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataFormatsProvider
|
||||
*/
|
||||
public function testClassName($path)
|
||||
{
|
||||
$this->setFormat($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('Format', $this->class, 'class name must end with "Format"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataFormatsProvider
|
||||
*/
|
||||
public function testClassType($path) {
|
||||
$this->setFormat($path);
|
||||
$this->assertInstanceOf(FormatInterface::class, $this->obj);
|
||||
}
|
||||
/**
|
||||
* @dataProvider dataFormatsProvider
|
||||
*/
|
||||
public function testClassType($path)
|
||||
{
|
||||
$this->setFormat($path);
|
||||
$this->assertInstanceOf(FormatInterface::class, $this->obj);
|
||||
}
|
||||
|
||||
public function dataFormatsProvider() {
|
||||
$formats = array();
|
||||
foreach (glob(PATH_LIB_FORMATS . '*.php') as $path) {
|
||||
$formats[basename($path, '.php')] = array($path);
|
||||
}
|
||||
return $formats;
|
||||
}
|
||||
public function dataFormatsProvider()
|
||||
{
|
||||
$formats = [];
|
||||
foreach (glob(PATH_LIB_FORMATS . '*.php') as $path) {
|
||||
$formats[basename($path, '.php')] = [$path];
|
||||
}
|
||||
return $formats;
|
||||
}
|
||||
|
||||
private function setFormat($path) {
|
||||
$this->class = basename($path, '.php');
|
||||
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
|
||||
$this->obj = new $this->class();
|
||||
}
|
||||
private function setFormat($path)
|
||||
{
|
||||
$this->class = basename($path, '.php');
|
||||
$this->assertTrue(class_exists($this->class), 'class ' . $this->class . ' doesn\'t exist');
|
||||
$this->obj = new $this->class();
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* JsonFormat - JSON Feed Version 1
|
||||
* https://jsonfeed.org/version/1
|
||||
@ -10,18 +11,20 @@ require_once __DIR__ . '/BaseFormatTest.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class JsonFormatTest extends BaseFormatTest {
|
||||
private const PATH_EXPECTED = self::PATH_SAMPLES . 'expectedJsonFormat/';
|
||||
class JsonFormatTest extends BaseFormatTest
|
||||
{
|
||||
private const PATH_EXPECTED = self::PATH_SAMPLES . 'expectedJsonFormat/';
|
||||
|
||||
/**
|
||||
* @dataProvider sampleProvider
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput(string $name, string $path) {
|
||||
$data = $this->formatData('Json', $this->loadSample($path));
|
||||
$this->assertNotNull(json_decode($data), 'invalid JSON output: ' . json_last_error_msg());
|
||||
/**
|
||||
* @dataProvider sampleProvider
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput(string $name, string $path)
|
||||
{
|
||||
$data = $this->formatData('Json', $this->loadSample($path));
|
||||
$this->assertNotNull(json_decode($data), 'invalid JSON output: ' . json_last_error_msg());
|
||||
|
||||
$expected = self::PATH_EXPECTED . $name . '.json';
|
||||
$this->assertJsonStringEqualsJsonFile($expected, $data);
|
||||
}
|
||||
$expected = self::PATH_EXPECTED . $name . '.json';
|
||||
$this->assertJsonStringEqualsJsonFile($expected, $data);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* MrssFormat - RSS 2.0 + Media RSS
|
||||
* http://www.rssboard.org/rss-specification
|
||||
@ -11,18 +12,20 @@ require_once __DIR__ . '/BaseFormatTest.php';
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class MrssFormatTest extends BaseFormatTest {
|
||||
private const PATH_EXPECTED = self::PATH_SAMPLES . 'expectedMrssFormat/';
|
||||
class MrssFormatTest extends BaseFormatTest
|
||||
{
|
||||
private const PATH_EXPECTED = self::PATH_SAMPLES . 'expectedMrssFormat/';
|
||||
|
||||
/**
|
||||
* @dataProvider sampleProvider
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput(string $name, string $path) {
|
||||
$data = $this->formatData('Mrss', $this->loadSample($path));
|
||||
$this->assertNotFalse(simplexml_load_string($data));
|
||||
/**
|
||||
* @dataProvider sampleProvider
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOutput(string $name, string $path)
|
||||
{
|
||||
$data = $this->formatData('Mrss', $this->loadSample($path));
|
||||
$this->assertNotFalse(simplexml_load_string($data));
|
||||
|
||||
$expected = self::PATH_EXPECTED . $name . '.xml';
|
||||
$this->assertXmlStringEqualsXmlFile($expected, $data);
|
||||
}
|
||||
$expected = self::PATH_EXPECTED . $name . '.xml';
|
||||
$this->assertXmlStringEqualsXmlFile($expected, $data);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user