|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Pest\Browser\Configuration; |
| 6 | +use Pest\Browser\Playwright\Playwright; |
| 7 | + |
| 8 | +beforeEach(function (): void { |
| 9 | + // Reset Playwright state before each test |
| 10 | + Playwright::setHost(null); |
| 11 | +}); |
| 12 | + |
| 13 | +it('can set host via configuration', function (): void { |
| 14 | + $config = new Configuration(); |
| 15 | + |
| 16 | + $result = $config->withHost('tenant.localhost'); |
| 17 | + |
| 18 | + expect($result)->toBeInstanceOf(Configuration::class); |
| 19 | + expect(Playwright::host())->toBe('tenant.localhost'); |
| 20 | +}); |
| 21 | + |
| 22 | +it('follows fluent interface pattern', function (): void { |
| 23 | + $config = new Configuration(); |
| 24 | + |
| 25 | + $result = $config |
| 26 | + ->withHost('app.localhost') |
| 27 | + ->userAgent('Test Agent') |
| 28 | + ->timeout(10000); |
| 29 | + |
| 30 | + expect($result)->toBeInstanceOf(Configuration::class); |
| 31 | + expect(Playwright::host())->toBe('app.localhost'); |
| 32 | +}); |
| 33 | + |
| 34 | +it('stores host in Playwright global state', function (): void { |
| 35 | + expect(Playwright::host())->toBeNull(); |
| 36 | + |
| 37 | + Playwright::setHost('custom.localhost'); |
| 38 | + |
| 39 | + expect(Playwright::host())->toBe('custom.localhost'); |
| 40 | +}); |
| 41 | + |
| 42 | +it('can override host multiple times', function (): void { |
| 43 | + Playwright::setHost('first.localhost'); |
| 44 | + expect(Playwright::host())->toBe('first.localhost'); |
| 45 | + |
| 46 | + Playwright::setHost('second.localhost'); |
| 47 | + expect(Playwright::host())->toBe('second.localhost'); |
| 48 | + |
| 49 | + Playwright::setHost('final.localhost'); |
| 50 | + expect(Playwright::host())->toBe('final.localhost'); |
| 51 | +}); |
| 52 | + |
| 53 | +it('handles various host formats', function (): void { |
| 54 | + $hosts = [ |
| 55 | + 'localhost', |
| 56 | + 'app.localhost', |
| 57 | + 'subdomain.domain.tld', |
| 58 | + '192.168.1.100', |
| 59 | + 'custom-host.test', |
| 60 | + ]; |
| 61 | + |
| 62 | + foreach ($hosts as $host) { |
| 63 | + Playwright::setHost($host); |
| 64 | + expect(Playwright::host())->toBe($host); |
| 65 | + } |
| 66 | +}); |
0 commit comments