aboutsummaryrefslogtreecommitdiff
path: root/tests/Formats
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2022-07-01 15:10:30 +0200
committerGravatar GitHub <noreply@github.com> 2022-07-01 15:10:30 +0200
commit4f75591060d95208a301bc6bf460d875631b29cc (patch)
tree4e37d86840e8d990a563ba75d3de6f84a53cc2de /tests/Formats
parent66568e3a39c61546c09a47a5688914a0bdf3c60c (diff)
downloadrss-bridge-4f75591060d95208a301bc6bf460d875631b29cc.tar.gz
rss-bridge-4f75591060d95208a301bc6bf460d875631b29cc.tar.zst
rss-bridge-4f75591060d95208a301bc6bf460d875631b29cc.zip
Reformat codebase v4 (#2872)
Reformat code base to PSR12 Co-authored-by: rssbridge <noreply@github.com>
Diffstat (limited to 'tests/Formats')
-rw-r--r--tests/Formats/AtomFormatTest.php27
-rw-r--r--tests/Formats/BaseFormatTest.php116
-rw-r--r--tests/Formats/FormatImplementationTest.php67
-rw-r--r--tests/Formats/JsonFormatTest.php27
-rw-r--r--tests/Formats/MrssFormatTest.php27
5 files changed, 142 insertions, 122 deletions
diff --git a/tests/Formats/AtomFormatTest.php b/tests/Formats/AtomFormatTest.php
index a871ea86..77bb9cbc 100644
--- a/tests/Formats/AtomFormatTest.php
+++ b/tests/Formats/AtomFormatTest.php
@@ -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);
+ }
}
diff --git a/tests/Formats/BaseFormatTest.php b/tests/Formats/BaseFormatTest.php
index 94da7b04..ace4d3ea 100644
--- a/tests/Formats/BaseFormatTest.php
+++ b/tests/Formats/BaseFormatTest.php
@@ -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/';
-
- /**
- * @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']);
-
- $items = array();
- 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'));
- }
- }
-
- 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'));
-
- return $format->stringify();
- }
+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;
+ }
+
+ /**
+ * 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 = [];
+ foreach ($data['items'] as $item) {
+ $items[] = new \FeedItem($item);
+ }
+
+ 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);
+ }
+
+ 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();
+ }
}
diff --git a/tests/Formats/FormatImplementationTest.php b/tests/Formats/FormatImplementationTest.php
index e4501d68..55c6335f 100644
--- a/tests/Formats/FormatImplementationTest.php
+++ b/tests/Formats/FormatImplementationTest.php
@@ -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();
+ }
}
diff --git a/tests/Formats/JsonFormatTest.php b/tests/Formats/JsonFormatTest.php
index 3b9f8d47..c21d3f34 100644
--- a/tests/Formats/JsonFormatTest.php
+++ b/tests/Formats/JsonFormatTest.php
@@ -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);
+ }
}
diff --git a/tests/Formats/MrssFormatTest.php b/tests/Formats/MrssFormatTest.php
index 6def6afb..af74923e 100644
--- a/tests/Formats/MrssFormatTest.php
+++ b/tests/Formats/MrssFormatTest.php
@@ -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);
+ }
}