|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Doctrine\Bundle\DoctrineStaticWebsiteGeneratorBundle\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use App\AppKernel; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
10
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
11
|
|
|
use function assert; |
|
12
|
|
|
use function file_exists; |
|
13
|
|
|
use function file_get_contents; |
|
14
|
|
|
|
|
15
|
|
|
class FunctionalTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
public function testBuildWebsite() : void |
|
18
|
|
|
{ |
|
19
|
|
|
$input = new ArrayInput(['command' => 'doctrine:build-website']); |
|
20
|
|
|
|
|
21
|
|
|
$kernel = new AppKernel('test', true); |
|
22
|
|
|
$kernel->boot(); |
|
23
|
|
|
|
|
24
|
|
|
$container = $kernel->getContainer(); |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
$application = new Application($kernel); |
|
27
|
|
|
$application->setAutoExit(false); |
|
28
|
|
|
$application->run($input); |
|
29
|
|
|
|
|
30
|
|
|
$buildDir = __DIR__ . '/App/build-test'; |
|
31
|
|
|
|
|
32
|
|
|
$indexContents = $this->getFileContents($buildDir, 'index.html'); |
|
33
|
|
|
|
|
34
|
|
|
self::assertContains( |
|
35
|
|
|
'<title>Doctrine Static Website</title>', |
|
36
|
|
|
$indexContents |
|
37
|
|
|
); |
|
38
|
|
|
|
|
39
|
|
|
self::assertContains( |
|
40
|
|
|
'<h1>DoctrineStaticWebsiteGeneratorBundle</h1>', |
|
41
|
|
|
$indexContents |
|
42
|
|
|
); |
|
43
|
|
|
|
|
44
|
|
|
self::assertContains( |
|
45
|
|
|
'<p>Testing that DoctrineStaticWebsiteGeneratorBundle works in a Symfony application.</p>', |
|
46
|
|
|
$indexContents |
|
47
|
|
|
); |
|
48
|
|
|
|
|
49
|
|
|
self::assertContains('Homepage: /index.html', $indexContents); |
|
50
|
|
|
|
|
51
|
|
|
self::assertContains('Homepage URL: http://localhost/index.html', $indexContents); |
|
52
|
|
|
|
|
53
|
|
|
self::assertContains('Controller Data: This data came from the controller', $indexContents); |
|
54
|
|
|
|
|
55
|
|
|
self::assertContains('Request Data: /index.html', $indexContents); |
|
56
|
|
|
|
|
57
|
|
|
$jwageContents = $this->getFileContents($buildDir, 'user/jwage.html'); |
|
58
|
|
|
|
|
59
|
|
|
self::assertContains('jwage', $jwageContents); |
|
60
|
|
|
|
|
61
|
|
|
$ocramiusContents = $this->getFileContents($buildDir, 'user/ocramius.html'); |
|
62
|
|
|
|
|
63
|
|
|
self::assertContains('ocramius', $ocramiusContents); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
private function getFileContents(string $buildDir, string $file) : string |
|
67
|
|
|
{ |
|
68
|
|
|
$path = $buildDir . '/' . $file; |
|
69
|
|
|
|
|
70
|
|
|
self::assertTrue(file_exists($path)); |
|
71
|
|
|
|
|
72
|
|
|
$contents = file_get_contents($path); |
|
73
|
|
|
assert($contents !== false); |
|
74
|
|
|
|
|
75
|
|
|
return $contents; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|