|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Micilini\PhpSockets\Tests\Unit\Examples; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | + |
| 9 | +final class ExampleServerAutoloadTest extends TestCase |
| 10 | +{ |
| 11 | + public function testExamplesHaveSharedBootstrapFile(): void |
| 12 | + { |
| 13 | + self::assertFileExists(__DIR__ . '/../../../examples/bootstrap.php'); |
| 14 | + } |
| 15 | + |
| 16 | + public function testExampleServersUseSharedBootstrapInsteadOfLocalVendorAutoload(): void |
| 17 | + { |
| 18 | + $serverFiles = [ |
| 19 | + __DIR__ . '/../../../examples/easy-chat/server.php', |
| 20 | + __DIR__ . '/../../../examples/medium-chat/server.php', |
| 21 | + __DIR__ . '/../../../examples/private-chat/server.php', |
| 22 | + ]; |
| 23 | + |
| 24 | + foreach ($serverFiles as $serverFile) { |
| 25 | + self::assertFileExists($serverFile); |
| 26 | + |
| 27 | + $contents = (string) file_get_contents($serverFile); |
| 28 | + |
| 29 | + self::assertStringContainsString( |
| 30 | + "require __DIR__ . '/../bootstrap.php';", |
| 31 | + $contents, |
| 32 | + "{$serverFile} should use the shared examples bootstrap.", |
| 33 | + ); |
| 34 | + |
| 35 | + self::assertStringNotContainsString( |
| 36 | + '/../../vendor/autoload.php', |
| 37 | + $contents, |
| 38 | + "{$serverFile} should not assume a local package vendor directory.", |
| 39 | + ); |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + public function testSharedBootstrapSupportsRepositoryAndComposerInstallPaths(): void |
| 44 | + { |
| 45 | + $bootstrap = (string) file_get_contents(__DIR__ . '/../../../examples/bootstrap.php'); |
| 46 | + |
| 47 | + self::assertStringContainsString("__DIR__ . '/../vendor/autoload.php'", $bootstrap); |
| 48 | + self::assertStringContainsString("__DIR__ . '/../../../autoload.php'", $bootstrap); |
| 49 | + self::assertStringContainsString("getcwd() . '/vendor/autoload.php'", $bootstrap); |
| 50 | + } |
| 51 | +} |
0 commit comments