From 37038cc608bdf99310650d46fbd9e39b184d33a7 Mon Sep 17 00:00:00 2001 From: Claude Code Date: Wed, 30 Jul 2025 10:02:16 +0000 Subject: [PATCH 1/2] feat: add unit tests for RssParser parse function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add comprehensive unit tests for RssParser::parse() method - Test valid XML parsing with different XML formats (RSS, simple XML, namespaced XML) - Test empty response exception handling - Test invalid XML handling - Follow existing test patterns and PHPUnit conventions 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- tests/Parser/RssParserTest.php | 83 ++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 tests/Parser/RssParserTest.php diff --git a/tests/Parser/RssParserTest.php b/tests/Parser/RssParserTest.php new file mode 100644 index 0000000..0925c84 --- /dev/null +++ b/tests/Parser/RssParserTest.php @@ -0,0 +1,83 @@ +rssParser = new RssParser(); + } + + /** + * @dataProvider validXmlDataProvider + */ + public function testParseWithValidXml(string $xmlContent, string $expectedRootElement): void + { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn($xmlContent); + + $response = $this->createMock(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); + + $result = $this->rssParser->parse($response); + + $this->assertInstanceOf(\SimpleXMLElement::class, $result); + $this->assertEquals($expectedRootElement, $result->getName()); + } + + public function testParseWithEmptyResponse(): void + { + $this->expectException(EmptyResponseException::class); + $this->expectExceptionMessage('Empty response received'); + + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn(''); + + $response = $this->createMock(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); + + $this->rssParser->parse($response); + } + + public function testParseWithInvalidXml(): void + { + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn('invalid xml content'); + + $response = $this->createMock(ResponseInterface::class); + $response->method('getBody')->willReturn($stream); + + $result = $this->rssParser->parse($response); + + $this->assertFalse($result); + } + + public static function validXmlDataProvider(): array + { + return [ + 'basic RSS feed' => [ + 'xmlContent' => 'Test RSS', + 'expectedRootElement' => 'rss' + ], + 'simple XML' => [ + 'xmlContent' => 'test', + 'expectedRootElement' => 'root' + ], + 'XML with namespaces' => [ + 'xmlContent' => 'Test Feed', + 'expectedRootElement' => 'feed' + ] + ]; + } +} \ No newline at end of file From 6abb57972accb8f2f29b7faa1bec4dd7ec263d39 Mon Sep 17 00:00:00 2001 From: Billy AI Dev Date: Wed, 30 Jul 2025 10:02:34 +0000 Subject: [PATCH 2/2] test: add unit tests for RssParser (AB-1111)