- How do I install omnipay/tests for Laravel projects?
- Run `composer require omnipay/tests --dev` in your Laravel project. Ensure you’re using Omnipay v4.x+ (e.g., `omnipay/omnipay:^4.0`) to match the test suite’s peer dependency. No additional Laravel-specific setup is needed beyond PHPUnit or Pest.
- Can I use these tests with Laravel’s Pest framework?
- Yes, but you’ll need a Pest plugin like `pest-plugin-phpunit` to bridge compatibility. The tests are PHPUnit-native, so adapt assertions (e.g., `assertTrue()` → `expect(true)->toBeTrue()`) or wrap them in Pest’s `test()` functions.
- What Laravel versions are supported by omnipay/tests?
- The package works with any Laravel version supporting PHP 8.1+. Test for Laravel 10+ explicitly, as older versions (e.g., 8.x) may need polyfills for PHPUnit 9+ features used in the test suite.
- How do I mock a specific payment gateway (e.g., Stripe) for testing?
- Extend `Omnipay\Tests\TestCase` and use `TestGateway` to simulate responses. For Stripe, override `purchase()` to return a mock response like `$this->getMockResponse('success')`. Example: `return $this->getMockResponse(['transactionReference' => 'mock_123']);`
- Are these tests suitable for production-like transaction validation?
- No. The tests use fake cards (e.g., `4242424242424242`) and mock responses—never use them in live environments. For production validation, test against sandbox APIs (e.g., Stripe’s test mode) or staging gateways with real credentials.
- How do I handle edge cases like failed transactions or 3D Secure flows?
- Use `TestGateway`’s built-in mocks for failures (e.g., `getMockResponse('failure')`) or customize responses with HTTP errors. For 3D Secure, simulate redirects by returning a `302` response with a test URL like `https://example.com/3ds-redirect`.
- Will these tests work with custom Omnipay gateways?
- Yes, but you’ll need to extend the test classes to match your gateway’s API. For example, if your `MyCustomGateway` has a `charge()` method, create `MyCustomGatewayTest` extending `TestCase` and override methods like `getGateway()` to return your gateway instance.
- Can I integrate these tests into Laravel’s CI/CD pipeline?
- Absolutely. The tests are lightweight and run in under 1 second. Use Docker for isolated environments to avoid conflicts with other services. For parallel CI jobs, ensure each worker uses unique mock instances to prevent gateway collisions.
- Are there alternatives to omnipay/tests for testing payment gateways?
- For Omnipay, alternatives are limited. VCR recordings (e.g., `vcr/vcr.php`) can capture real API interactions but lack Omnipay’s gateway-specific helpers. For non-Omnipay setups, use gateway-native tools (e.g., Stripe CLI) or factory patterns with Faker.
- How do I test refunds or subscription cancellations with these fixtures?
- Use `TestGateway`’s mock responses for refunds by overriding `refund()` to return a success/failure response. For subscriptions, simulate webhooks by extending `TestCase` and mocking `notify()` calls with test payloads (e.g., `invoice.payment_succeeded`).