Download the PHP package viewtrender/php-youtube-testkit-core without Composer
On this page you can find all versions of the php package viewtrender/php-youtube-testkit-core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download viewtrender/php-youtube-testkit-core
More information about viewtrender/php-youtube-testkit-core
Files in viewtrender/php-youtube-testkit-core
Package php-youtube-testkit-core
Short Description Core mock layer for Google YouTube APIs
License MIT
Informations about the package php-youtube-testkit-core
php-youtube-testkit-core
Fake responses for YouTube Data API, Analytics API, and Reporting API in PHP tests.
Overview
php-youtube-testkit-core lets you test code that uses google/apiclient without hitting real YouTube APIs. Queue fake responses, call Google services as normal, then assert which requests were made.
Supports three YouTube APIs:
- YouTube Data API — videos, channels, playlists, search, comments
- YouTube Analytics API — on-demand metrics queries
- YouTube Reporting API — bulk data exports and scheduled jobs
Framework-agnostic — works with any PHP project and any test runner.
Installation
Requirements
- PHP 8.3+
google/apiclient^2.15
Quick Start
YouTube Data API
YouTube Analytics API
YouTube Reporting API
YouTube Data API
Setting up fakes
Data API Factories
| Factory | Methods |
|---|---|
YoutubeVideo |
list(), listWithVideos(), video(), empty(), notFound() |
YoutubeChannel |
list(), listWithChannels(), channel(), empty(), notFound() |
YoutubePlaylist |
list(), listWithPlaylists(), playlist(), empty() |
YoutubePlaylistItems |
list(), listWithItems(), empty() |
YoutubeSearchResult |
list(), listWithResults(), searchResult(), empty() |
YoutubeCommentThreads |
list(), listWithThreads(), empty() |
YoutubeComments |
list(), listWithComments(), empty() |
YoutubeSubscriptions |
list(), listWithSubscriptions(), empty() |
YoutubeActivities |
list(), listWithActivities(), empty() |
YoutubeCaptions |
list(), listWithCaptions(), empty() |
Custom items
Data API Assertions
Pagination
Test code that paginates through multi-page API responses. Pagination is provided by the HasPagination trait on YoutubePlaylistItems and YoutubeActivities — the Data API endpoints that return nextPageToken.
Both methods return array<FakeResponse> — spread them into fake([]):
| Method | Purpose |
|---|---|
paginated(pages, perPage) |
Auto-generate items with fixture defaults |
pages(array) |
Full control over each page's items |
Each factory also provides a named item constructor:
YoutubePlaylistItems::playlistItem(array $overrides = [])YoutubeActivities::activity(array $overrides = [])
Auto-Generated Pages
Use paginated() to generate multiple pages of fake items:
Explicit Page Contents
Use pages() for full control over each page's items. You can pass raw override arrays or use the named constructors:
See docs/DATA_API.md for complete reference.
YouTube Analytics API
For on-demand metrics queries — dashboards, real-time stats, custom date ranges.
Setting up fakes
Analytics Factory Methods
| Method | Description |
|---|---|
channelOverview() |
Channel-level aggregated metrics |
dailyMetrics() |
Day-by-day breakdown |
topVideos() |
Top performing videos |
trafficSources() |
Traffic source breakdown |
demographics() |
Age/gender viewer percentages |
geography() |
Country-level metrics |
deviceTypes() |
Device type breakdown |
videoAnalytics() |
Per-video metrics |
videoTypes() |
Metrics by content type |
Channel Overview
Traffic Sources
Demographics
Content Types
See docs/ANALYTICS_API.md for complete metrics and dimensions reference.
YouTube Reporting API
For bulk data exports — background jobs, historical data pipelines, scheduled reports.
Workflow: Create job → Poll for reports → Download CSV → Parse & upsert
Setting up fakes
Reporting Factories
| Factory | Methods |
|---|---|
ReportingJob |
create(), list(), delete() |
ReportingReport |
list(), get() |
ReportingReportType |
list() |
ReportingMedia |
download() |
Creating a Job
Listing Jobs
Listing Reports
Downloading CSV Data
Common Report Types
| Report Type ID | Description |
|---|---|
channel_basic_a2 |
Core channel metrics |
channel_demographics_a1 |
Viewer age/gender |
channel_device_os_a2 |
Device and OS distribution |
channel_traffic_source_a2 |
Traffic source breakdown |
See docs/REPORTING_API.md for complete reference.
Error Responses
Simulate API errors for any service:
Custom Responses
Build arbitrary responses with FakeResponse:
Preventing Stray Requests
Throw an exception when no fake response is queued:
Framework Integration
Register a callback that runs whenever fake() is called:
License
MIT
All versions of php-youtube-testkit-core with dependencies
google/apiclient Version ^2.15
google/apiclient-services Version *
guzzlehttp/guzzle Version ^7.4
guzzlehttp/psr7 Version ^2.0