Download the PHP package viewtrender/php-youtube-testkit-laravel without Composer
On this page you can find all versions of the php package viewtrender/php-youtube-testkit-laravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download viewtrender/php-youtube-testkit-laravel
More information about viewtrender/php-youtube-testkit-laravel
Files in viewtrender/php-youtube-testkit-laravel
Package php-youtube-testkit-laravel
Short Description Laravel integration for php-youtube-testkit
License MIT
Informations about the package php-youtube-testkit-laravel
php-youtube-testkit-laravel
Laravel integration for mocking YouTube Data, Analytics, and Reporting APIs in tests.
Overview
Laravel service provider, facades, and automatic container swaps for viewtrender/php-youtube-testkit-core. 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
When you call fake() on any API facade, the service provider replaces the Google Service container binding with a fake instance — controllers that type-hint the service receive the fake automatically.
Installation
The service provider is auto-discovered. To publish the config file:
Requirements
- PHP 8.3+
- Laravel 10, 11, or 12
google/apiclient^2.15
Setup
Register the real Google services in your AppServiceProvider:
Controllers can then type-hint any service:
Testing with Pest
Base Setup
Create a base test file or add to tests/Pest.php:
Import Factories
Factory Examples — Pest
Videos
Channels
Playlists
Playlist Items
Search Results
Subscriptions
Comments
Comment Threads
Activities
Captions
Channel Sections
Members (OAuth Required)
Membership Levels (OAuth Required)
I18n Languages
I18n Regions
Video Categories
Video Abuse Report Reasons
Thumbnails (Write-Only)
Watermarks (Write-Only)
Pagination
Two factories support multi-page responses via the HasPagination trait: YoutubePlaylistItems and YoutubeActivities. These are the Data API endpoints that return nextPageToken for iterating through large result sets.
Both expose two static methods that return array<FakeResponse> — spread them into fake([]) to queue all pages at once:
| Method | Purpose |
|---|---|
paginated(pages, perPage) |
Auto-generate items with sensible defaults |
pages(array) |
Explicit control over each page's items |
Each factory also provides a named constructor for building individual items:
YoutubePlaylistItems::playlistItem(array $overrides = [])YoutubeActivities::activity(array $overrides = [])
paginated() — auto-generated items
Generate multiple pages of fake items with a single call. Each page includes a nextPageToken except the last, and pageInfo reflects the total count.
Manual pagination loop
If your code paginates through results directly (e.g., in a job or service class), you can test the full loop:
pages() — explicit items per page
For full control over each page's contents, pass an array of pages, where each page is an array of item overrides. Use the named constructors (::playlistItem(), ::activity()) or pass raw override arrays.
You can also pass raw arrays to pages() — they'll be merged with fixture defaults:
Single page (no nextPageToken)
Passing one sub-array to pages() produces a single response with no nextPageToken — useful when you want explicit item control without multi-page behavior:
Testing pagination in Laravel jobs
A common pattern is testing a Laravel job that syncs all items from a paginated endpoint:
Testing with PHPUnit
Base Test Case
Video Tests
Channel Tests
Search Tests
Subscription Tests
Complete Feature Test Example
YouTube Analytics API
For on-demand metrics queries — dashboards, real-time stats, custom date ranges.
Base Test Case (Analytics)
Channel Analytics Tests
YouTube Reporting API
For bulk data exports — background jobs, historical data pipelines, scheduled reports.
Workflow: Create job → Poll for reports → Download CSV → Parse & upsert
Base Test Case (Reporting)
Reporting Job Tests
Complete Pipeline Test
Error Responses
Simulate API errors in your tests:
Assertions
Configuration
License
MIT
All versions of php-youtube-testkit-laravel with dependencies
viewtrender/php-youtube-testkit-core Version ^0.6
illuminate/support Version ^10.0|^11.0|^12.0|^13.0