16
16
use PHPUnit \Framework \Attributes \CoversClass ;
17
17
use PHPUnit \Framework \Attributes \UsesClass ;
18
18
use PHPUnit \Framework \TestCase ;
19
+ use Symfony \AI \Store \Document \Metadata ;
19
20
use Symfony \AI \Store \Document \TextDocument ;
20
21
use Symfony \AI \Store \Exception \InvalidArgumentException ;
22
+ use Symfony \Component \HttpClient \Exception \ClientException ;
21
23
use Symfony \Component \HttpClient \MockHttpClient ;
22
24
use Symfony \Component \HttpClient \Response \MockResponse ;
23
25
use Symfony \Component \Uid \Uuid ;
@@ -28,7 +30,7 @@ final class FeedLoaderTest extends TestCase
28
30
{
29
31
public function testLoadWithValidFeedUrl ()
30
32
{
31
- $ loader = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/fixtures/symfony-feed.xml ' )));
33
+ $ loader = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/../ fixtures/symfony-blog.rss ' )));
32
34
$ documents = iterator_to_array ($ loader ->load ('https://feeds.feedburner.com/symfony/blog ' ));
33
35
34
36
$ this ->assertCount (2 , $ documents );
@@ -40,12 +42,12 @@ public function testLoadWithValidFeedUrl()
40
42
$ expectedFirstUuid = Uuid::v5 (Uuid::fromString ('6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' ), 'Save the date, SymfonyDay Montreal 2026! ' );
41
43
$ this ->assertEquals ($ expectedFirstUuid , $ firstDocument ->id );
42
44
43
- $ this ->assertStringContainsString ('Title: Save the date, SymfonyDay Montreal 2026! ' , $ firstDocument ->text );
44
- $ this ->assertStringContainsString ('From: Paola Suárez on 2025-09-11 ' , $ firstDocument ->text );
45
- $ this ->assertStringContainsString ("We're thrilled to announce that SymfonyDay Montreal is happening on June 4, 2026! " , $ firstDocument ->text );
46
- $ this ->assertStringContainsString ('Mark your calendars, tell your friends ' , $ firstDocument ->text );
45
+ $ this ->assertStringContainsString ('Title: Save the date, SymfonyDay Montreal 2026! ' , $ firstDocument ->content );
46
+ $ this ->assertStringContainsString ('From: Paola Suárez on 2025-09-11 ' , $ firstDocument ->content );
47
+ $ this ->assertStringContainsString ("We're thrilled to announce that SymfonyDay Montreal is happening on June 4, 2026! " , $ firstDocument ->content );
48
+ $ this ->assertStringContainsString ('Mark your calendars, tell your friends ' , $ firstDocument ->content );
47
49
48
- $ firstMetadata = $ firstDocument ->metadata -> toArray () ;
50
+ $ firstMetadata = $ firstDocument ->metadata ;
49
51
$ this ->assertSame ($ expectedFirstUuid ->toRfc4122 (), $ firstMetadata ['id ' ]);
50
52
$ this ->assertSame ('Save the date, SymfonyDay Montreal 2026! ' , $ firstMetadata ['title ' ]);
51
53
$ this ->assertSame ('https://symfony.com/blog/save-the-date-symfonyday-montreal-2026?utm_source=Symfony%20Blog%20Feed&utm_medium=feed ' , $ firstMetadata ['link ' ]);
@@ -61,11 +63,11 @@ public function testLoadWithValidFeedUrl()
61
63
$ expectedSecondUuid = Uuid::v5 (Uuid::fromString ('6ba7b810-9dad-11d1-80b4-00c04fd430c8 ' ), 'SymfonyCon Amsterdam 2025: Call for IT student volunteers: Volunteer, Learn & Connect! ' );
62
64
$ this ->assertEquals ($ expectedSecondUuid , $ secondDocument ->id );
63
65
64
- $ this ->assertStringContainsString ('Title: SymfonyCon Amsterdam 2025: Call for IT student volunteers: Volunteer, Learn & Connect! ' , $ secondDocument ->text );
65
- $ this ->assertStringContainsString ('From: Paola Suárez on 2025-09-10 ' , $ secondDocument ->text );
66
- $ this ->assertStringContainsString ('🎓SymfonyCon Amsterdam 2025: Call for IT Student Volunteers! ' , $ secondDocument ->text );
66
+ $ this ->assertStringContainsString ('Title: SymfonyCon Amsterdam 2025: Call for IT student volunteers: Volunteer, Learn & Connect! ' , $ secondDocument ->content );
67
+ $ this ->assertStringContainsString ('From: Paola Suárez on 2025-09-10 ' , $ secondDocument ->content );
68
+ $ this ->assertStringContainsString ('🎓SymfonyCon Amsterdam 2025: Call for IT Student Volunteers! ' , $ secondDocument ->content );
67
69
68
- $ secondMetadata = $ secondDocument ->metadata -> toArray () ;
70
+ $ secondMetadata = $ secondDocument ->metadata ;
69
71
$ this ->assertSame ($ expectedSecondUuid ->toRfc4122 (), $ secondMetadata ['id ' ]);
70
72
$ this ->assertSame ('SymfonyCon Amsterdam 2025: Call for IT student volunteers: Volunteer, Learn & Connect! ' , $ secondMetadata ['title ' ]);
71
73
$ this ->assertSame ('https://symfony.com/blog/symfonycon-amsterdam-2025-call-for-it-student-volunteers-volunteer-learn-and-connect?utm_source=Symfony%20Blog%20Feed&utm_medium=feed ' , $ secondMetadata ['link ' ]);
@@ -108,45 +110,44 @@ public function testLoadWithHttpError()
108
110
{
109
111
$ loader = new FeedLoader (new MockHttpClient (new MockResponse ('' , ['http_code ' => 404 ])));
110
112
111
- $ this ->expectException (\ Symfony \ Contracts \ HttpClient \ Exception \ ClientException::class);
113
+ $ this ->expectException (ClientException::class);
112
114
113
115
iterator_to_array ($ loader ->load ('https://example.com/non-existent-feed.xml ' ));
114
116
}
115
117
116
118
public function testLoadWithMalformedXml ()
117
119
{
118
- $ malformedXml = '<?xml version="1.0" encoding="UTF-8" ?><rss><channel><title>Test</title> ' ;
120
+ $ malformedXml = 'Not XML at all ' ;
119
121
120
122
$ loader = new FeedLoader (new MockHttpClient (new MockResponse ($ malformedXml )));
123
+ $ documents = iterator_to_array ($ loader ->load ('https://example.com/malformed-feed.xml ' ));
121
124
122
- $ this ->expectException (\Exception::class);
123
-
124
- iterator_to_array ($ loader ->load ('https://example.com/malformed-feed.xml ' ));
125
+ $ this ->assertCount (0 , $ documents );
125
126
}
126
127
127
128
public function testLoadReturnsIterableOfTextDocuments ()
128
129
{
129
- $ loader = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/fixtures/symfony-feed.xml ' )));
130
+ $ loader = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/../ fixtures/symfony-blog.rss ' )));
130
131
$ result = $ loader ->load ('https://feeds.feedburner.com/symfony/blog ' );
131
132
132
133
$ this ->assertIsIterable ($ result );
133
134
134
135
foreach ($ result as $ document ) {
135
136
$ this ->assertInstanceOf (TextDocument::class, $ document );
136
137
$ this ->assertInstanceOf (Uuid::class, $ document ->id );
137
- $ this ->assertIsString ($ document ->text );
138
- $ this ->assertNotEmpty ($ document ->text );
139
- $ this ->assertIsArray ( $ document ->metadata -> toArray () );
138
+ $ this ->assertIsString ($ document ->content );
139
+ $ this ->assertNotEmpty ($ document ->content );
140
+ $ this ->assertInstanceOf (Metadata::class, $ document ->metadata );
140
141
}
141
142
}
142
143
143
144
public function testLoadGeneratesConsistentUuids ()
144
145
{
145
- $ loader = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/fixtures/symfony-feed.xml ' )));
146
+ $ loader = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/../ fixtures/symfony-blog.rss ' )));
146
147
$ documents1 = iterator_to_array ($ loader ->load ('https://feeds.feedburner.com/symfony/blog ' ));
147
148
148
149
// Load same feed again
149
- $ loader2 = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/fixtures/symfony-feed.xml ' )));
150
+ $ loader2 = new FeedLoader (new MockHttpClient (MockResponse::fromFile (__DIR__ .'/../ fixtures/symfony-blog.rss ' )));
150
151
$ documents2 = iterator_to_array ($ loader2 ->load ('https://feeds.feedburner.com/symfony/blog ' ));
151
152
152
153
$ this ->assertCount (2 , $ documents1 );
0 commit comments