Skip to content

Commit 8ad2eac

Browse files
committed
wip
1 parent e0eb130 commit 8ad2eac

File tree

3 files changed

+24
-35
lines changed

3 files changed

+24
-35
lines changed

src/Support/TransformationRegistration.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ public function getUrls(): Generator
2828
foreach ($this->urls as $url) {
2929
$url = $url instanceof Closure ? ($url)() : $url;
3030

31-
yield $url;
31+
if (! is_array($url)) {
32+
$url = [$url];
33+
}
34+
35+
foreach ($url as $singleUrl) {
36+
yield $singleUrl;
37+
}
3238
}
3339
}
3440

tests/Actions/FetchUrlContentActionTest.php

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
});
2727

2828
it('can be overridden with custom implementation', function () {
29-
// Create a custom implementation
3029
$customAction = new class extends FetchUrlContentAction
3130
{
3231
public function execute(string $url): string
@@ -39,35 +38,3 @@ public function execute(string $url): string
3938

4039
expect($content)->toBe('custom content for https://example.com');
4140
});
42-
43-
it('is used by ProcessRegistrationAction via config', function () {
44-
Http::fake([
45-
'https://example.com' => Http::response('<html><body>Config test</body></html>', 200),
46-
]);
47-
48-
// The ProcessRegistrationAction should use the configured action
49-
$processAction = new \Spatie\LaravelUrlAiTransformer\Actions\ProcessRegistrationAction;
50-
51-
// Use reflection to test the protected method
52-
$reflection = new ReflectionClass($processAction);
53-
$method = $reflection->getMethod('fetchUrlContent');
54-
$method->setAccessible(true);
55-
56-
$content = $method->invoke($processAction, 'https://example.com');
57-
58-
expect($content)->toBe('<html><body>Config test</body></html>');
59-
});
60-
61-
it('can handle large content', function () {
62-
$largeContent = str_repeat('Lorem ipsum dolor sit amet. ', 10000);
63-
64-
Http::fake([
65-
'https://example.com' => Http::response($largeContent, 200),
66-
]);
67-
68-
$action = new FetchUrlContentAction;
69-
$content = $action->execute('https://example.com');
70-
71-
expect($content)->toBe($largeContent);
72-
expect(strlen($content))->toBeGreaterThan(100000);
73-
});

tests/Support/TransformTest.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
expect($urls)->toBe(['https://example.com/', 'https://another.com/']);
4949
});
5050

51-
it('can register urls using closures', function () {
51+
it('can register urls using closures that return a single url', function () {
5252
Transform::urls(
5353
fn () => 'https://example.com/',
5454
'https://another.com/',
@@ -66,6 +66,22 @@
6666
expect($urls)->toBe(['https://example.com/', 'https://another.com/', 'https://third.com/']);
6767
});
6868

69+
it('can register urls using closures that return an array of urls', function () {
70+
Transform::urls(
71+
fn() => ['https://example.com/', 'https://another.com/']
72+
)->usingTransformers(new TestTransformer);
73+
74+
$registrations = app(RegisteredTransformations::class)->all();
75+
76+
expect($registrations)->toHaveCount(1);
77+
78+
/** @var \Spatie\LaravelUrlAiTransformer\Support\TransformationRegistration $registration */
79+
$registration = $registrations[0];
80+
$urls = iterator_to_array($registration->getUrls());
81+
82+
expect($urls)->toBe(['https://example.com/', 'https://another.com/']);
83+
});
84+
6985
it('can register multiple transformations separately', function () {
7086
Transform::urls('https://example.com/')
7187
->usingTransformers(new TestTransformer);

0 commit comments

Comments
 (0)