tipoff/test-support
Deprecated/archived package providing shared unit/feature testing support for Tipoff Laravel packages. Previously included common test utilities and configuration; being removed as a dependency so packages can update independently and adopt newer Laravel versions faster.
Installation Add the package via Composer:
composer require tipoff/test-support --dev
Register the service provider in config/app.php under providers (if not auto-discovered):
Tipoff\TestSupport\TestSupportServiceProvider::class,
First Use Case: Mocking External Services
Use the MockExternalService trait in your test class to simulate API calls or third-party services:
use Tipoff\TestSupport\Traits\MockExternalService;
class MyTest extends TestCase
{
use MockExternalService;
public function test_something()
{
$this->mockExternalService('http://api.example.com', [
'response' => 'mocked_data'
]);
// Assertions...
}
}
Windows Blade Testing Fix The package now includes a Laravel fix for Blade testing on Windows environments. Ensure your test environment is properly configured to leverage this improvement.
Key Files to Explore
src/Traits/MockExternalService.php – Core trait for mocking HTTP requests.src/Traits/Assertions.php – Custom assertions for testing package behavior.src/Helpers/TestHelper.php – Utility functions for common test scenarios.src/WindowsBladeFix/BladeWindowsFix.php – New helper for Blade testing on Windows.Mocking HTTP Requests Replace real HTTP calls with predefined responses:
$this->mockExternalService('https://api.example.com/users', [
'status' => 200,
'body' => json_encode(['id' => 1, 'name' => 'Test User']),
]);
Testing Package Dependencies
Use the TestPackageDependency trait to isolate package tests:
use Tipoff\TestSupport\Traits\TestPackageDependency;
class MyPackageTest extends TestCase
{
use TestPackageDependency;
protected function setUp(): void
{
$this->mockDependency('vendor/package', [
'method' => 'someMethod',
'return' => 'mocked_value',
]);
}
}
Custom Assertions Extend built-in assertions for package-specific logic:
$this->assertPackageExceptionThrown(
fn() => MyPackage::doSomething(),
MyPackageException::class,
'Expected error message'
);
Blade Testing on Windows Use the new Blade fix for Windows environments to avoid common path resolution issues:
use Tipoff\TestSupport\WindowsBladeFix\BladeWindowsFix;
class BladeTest extends TestCase
{
use BladeWindowsFix;
public function test_blade_rendering_on_windows()
{
$this->setWindowsBladePaths();
// Test Blade rendering logic...
}
}
Http::fake() can be combined with mockExternalService).TestHelper::refreshDatabase() for clean state between tests.TestHelper::overrideConfig():
TestHelper::overrideConfig('package.key', 'test_value');
setWindowsBladePaths() method when testing Blade templates on Windows.Mock Scope Leakage
Mocks defined in setUp() persist across tests unless cleared. Use:
$this->clearMocks();
after each test to avoid unintended side effects.
HTTP Mock Matching
Mocks are matched by exact URL. Use wildcards sparingly (e.g., 'https://api.example.com/*' may not work as expected).
Static Method Mocking
The package does not natively mock static methods. Use PHPUnit’s getMockBuilder() as a fallback:
$mock = $this->getMockBuilder(StaticClass::class)
->onlyMethods(['staticMethod'])
->getMock();
Blade Path Resolution on Windows
If you encounter Blade path resolution issues on Windows, ensure you call setWindowsBladePaths() in your test setup. Failure to do so may result in incorrect path handling.
TestHelper::dumpMocks() to inspect active mocks:
$this->dumpMocks(); // Outputs all registered mocks to console.
config/test-support.php:
'debug' => env('TEST_SUPPORT_DEBUG', false),
BladeWindowsFix::logBladePaths() to debug path resolution issues:
BladeWindowsFix::logBladePaths();
Custom Mock Providers
Extend Tipoff\TestSupport\Contracts\MockProvider to support new services:
class CustomMockProvider implements MockProvider
{
public function mock($service, $response)
{
// Custom logic...
}
}
Register via the service provider.
Assertion Extensions Add custom assertions by publishing the package’s config:
php artisan vendor:publish --provider="Tipoff\TestSupport\TestSupportServiceProvider"
Then extend config/test-support.php under assertions.
Database Seed Overrides Override seeds for specific tests:
TestHelper::seedDatabase(['CustomSeeder']);
Windows-Specific Blade Extensions
Extend the BladeWindowsFix trait to add custom path resolution logic for your project:
class CustomBladeWindowsFix extends BladeWindowsFix
{
protected function getCustomWindowsPaths()
{
return [
'custom/path' => 'C:\custom\path',
];
}
}
Use this custom trait in your test classes.
How can I help you explore Laravel packages today?