-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExampleServerAutoloadTest.php
More file actions
76 lines (61 loc) · 2.55 KB
/
Copy pathExampleServerAutoloadTest.php
File metadata and controls
76 lines (61 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
declare(strict_types=1);
namespace Micilini\PhpSockets\Tests\Unit\Examples;
use PHPUnit\Framework\TestCase;
final class ExampleServerAutoloadTest extends TestCase
{
public function testExamplesHaveSharedBootstrapFile(): void
{
self::assertFileExists(__DIR__ . '/../../../examples/bootstrap.php');
}
public function testExampleServersUseSharedBootstrapInsteadOfLocalVendorAutoload(): void
{
$serverFiles = [
__DIR__ . '/../../../examples/easy-chat/server.php',
__DIR__ . '/../../../examples/medium-chat/server.php',
__DIR__ . '/../../../examples/private-chat/server.php',
];
foreach ($serverFiles as $serverFile) {
self::assertFileExists($serverFile);
$contents = (string) file_get_contents($serverFile);
self::assertStringContainsString(
"require __DIR__ . '/../bootstrap.php';",
$contents,
"{$serverFile} should use the shared examples bootstrap.",
);
self::assertStringNotContainsString(
'/../../vendor/autoload.php',
$contents,
"{$serverFile} should not assume a local package vendor directory.",
);
}
}
public function testSharedBootstrapSupportsRepositoryAndComposerInstallPaths(): void
{
$bootstrap = (string) file_get_contents(__DIR__ . '/../../../examples/bootstrap.php');
self::assertStringContainsString("__DIR__ . '/../vendor/autoload.php'", $bootstrap);
self::assertStringContainsString("__DIR__ . '/../../../autoload.php'", $bootstrap);
self::assertStringContainsString("getcwd() . '/vendor/autoload.php'", $bootstrap);
}
public function testExampleServersPrintDynamicPublicPaths(): void
{
$serverFiles = [
__DIR__ . '/../../../examples/easy-chat/server.php',
__DIR__ . '/../../../examples/medium-chat/server.php',
__DIR__ . '/../../../examples/private-chat/server.php',
];
foreach ($serverFiles as $serverFile) {
$contents = (string) file_get_contents($serverFile);
self::assertStringContainsString(
'$publicPath = str_replace',
$contents,
"{$serverFile} should compute its public path dynamically.",
);
self::assertStringContainsString(
'{$publicPath}',
$contents,
"{$serverFile} should print the dynamic public path.",
);
}
}
}