Skip to content

Commit f694137

Browse files
committed
minor #971 [Agent][YouTubeTranscriber] Add test case (OskarStark)
This PR was squashed before being merged into the main branch. Discussion ---------- [Agent][YouTubeTranscriber] Add test case | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Docs? | no | Issues | -- | License | MIT Commits ------- 2ff0f13 [Agent][YouTubeTranscriber] Add test case
2 parents a122dcb + 2ff0f13 commit f694137

File tree

5 files changed

+90
-0
lines changed

5 files changed

+90
-0
lines changed

src/agent/composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
},
3535
"require-dev": {
3636
"mrmysql/youtube-transcript": "^0.0.5",
37+
"nyholm/psr7": "^1.8",
38+
"php-http/discovery": "^1.19",
3739
"phpstan/phpstan": "^2.0",
3840
"phpstan/phpstan-strict-rules": "^2.0",
3941
"phpunit/phpunit": "^11.5.13",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"playabilityStatus": {
3+
"status": "OK"
4+
},
5+
"captions": {
6+
"playerCaptionsTracklistRenderer": {
7+
"captionTracks": [
8+
{
9+
"baseUrl": "https://www.youtube.com/api/timedtext?v=dQw4w9WgXcQ",
10+
"name": {
11+
"runs": [
12+
{
13+
"text": "English"
14+
}
15+
]
16+
},
17+
"languageCode": "en",
18+
"isTranslatable": true
19+
}
20+
],
21+
"translationLanguages": [
22+
{
23+
"languageName": {
24+
"runs": [
25+
{
26+
"text": "Spanish"
27+
}
28+
]
29+
},
30+
"languageCode": "es"
31+
}
32+
]
33+
}
34+
}
35+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<transcript>
3+
<text start="0.0" dur="2.5">Hello and welcome to this video</text>
4+
<text start="2.5" dur="3.0">Today we will learn about PHP</text>
5+
<text start="5.5" dur="2.0">Thank you for watching</text>
6+
</transcript>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<script>
5+
var ytcfg = {"INNERTUBE_API_KEY": "AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8"};
6+
</script>
7+
</head>
8+
<body>
9+
</body>
10+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Agent\Tests\Toolbox\Tool;
13+
14+
use PHPUnit\Framework\TestCase;
15+
use Symfony\AI\Agent\Toolbox\Tool\YouTubeTranscriber;
16+
use Symfony\Component\HttpClient\MockHttpClient;
17+
use Symfony\Component\HttpClient\Response\MockResponse;
18+
19+
final class YouTubeTranscriberTest extends TestCase
20+
{
21+
public function testInvoke()
22+
{
23+
$httpClient = new MockHttpClient([
24+
MockResponse::fromFile(__DIR__.'/../../Fixtures/Tool/youtube-video-page.html'),
25+
MockResponse::fromFile(__DIR__.'/../../Fixtures/Tool/youtube-captions.json'),
26+
MockResponse::fromFile(__DIR__.'/../../Fixtures/Tool/youtube-transcript.xml'),
27+
]);
28+
29+
$transcriber = new YouTubeTranscriber($httpClient);
30+
31+
$result = $transcriber('dQw4w9WgXcQ');
32+
33+
$this->assertStringContainsString('Hello and welcome to this video', $result);
34+
$this->assertStringContainsString('Today we will learn about PHP', $result);
35+
$this->assertStringContainsString('Thank you for watching', $result);
36+
}
37+
}

0 commit comments

Comments
 (0)