|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Panther project. |
| 5 | + * |
| 6 | + * (c) Kévin Dunglas <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace Symfony\Component\Panther\Tests\ProcessManager; |
| 15 | + |
| 16 | +use PHPUnit\Framework\TestCase; |
| 17 | +use Symfony\Component\Panther\Exception\RuntimeException; |
| 18 | +use Symfony\Component\Panther\ProcessManager\FirefoxManager; |
| 19 | + |
| 20 | +/** |
| 21 | + * @author Tugdual Saunier <[email protected]> |
| 22 | + */ |
| 23 | +class FirefoxManagerTest extends TestCase |
| 24 | +{ |
| 25 | + public function testRun(): void |
| 26 | + { |
| 27 | + $manager = new FirefoxManager(); |
| 28 | + $client = $manager->start(); |
| 29 | + $this->assertNotEmpty($client->getCurrentURL()); |
| 30 | + $manager->quit(); |
| 31 | + } |
| 32 | + |
| 33 | + public function testAlreadyRunning(): void |
| 34 | + { |
| 35 | + $this->expectException(RuntimeException::class); |
| 36 | + $this->expectExceptionMessage('The port 4444 is already in use.'); |
| 37 | + |
| 38 | + $driver1 = new FirefoxManager(); |
| 39 | + $driver1->start(); |
| 40 | + |
| 41 | + $driver2 = new FirefoxManager(); |
| 42 | + try { |
| 43 | + $driver2->start(); |
| 44 | + } finally { |
| 45 | + $driver1->quit(); |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + public function testNonDefaultPort(): void |
| 50 | + { |
| 51 | + $manager = new FirefoxManager(null, null, ['port' => 4445]); |
| 52 | + $client = $manager->start(); |
| 53 | + $this->assertNotEmpty($client->getCurrentURL()); |
| 54 | + $manager->quit(); |
| 55 | + } |
| 56 | + |
| 57 | + public function testMultipleInstances(): void |
| 58 | + { |
| 59 | + $driver1 = new FirefoxManager(); |
| 60 | + $client1 = $driver1->start(); |
| 61 | + |
| 62 | + $driver2 = new FirefoxManager(null, null, ['port' => 4445]); |
| 63 | + $client2 = $driver2->start(); |
| 64 | + |
| 65 | + $this->assertNotEmpty($client1->getCurrentURL()); |
| 66 | + $this->assertNotEmpty($client2->getCurrentURL()); |
| 67 | + |
| 68 | + $driver1->quit(); |
| 69 | + $driver2->quit(); |
| 70 | + } |
| 71 | +} |
0 commit comments