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
|
|
|
use function trim; |
15
|
|
|
|
16
|
|
|
class FunctionalTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
public function testBuildWebsite() : void |
19
|
|
|
{ |
20
|
|
|
$input = new ArrayInput(['command' => 'doctrine:build-website']); |
21
|
|
|
|
22
|
|
|
$kernel = new AppKernel('test', true); |
23
|
|
|
$kernel->boot(); |
24
|
|
|
|
25
|
|
|
$container = $kernel->getContainer(); |
|
|
|
|
26
|
|
|
|
27
|
|
|
$application = new Application($kernel); |
28
|
|
|
$application->setAutoExit(false); |
29
|
|
|
$application->run($input); |
30
|
|
|
|
31
|
|
|
$buildDir = __DIR__ . '/App/build-test'; |
32
|
|
|
|
33
|
|
|
$indexContents = $this->getFileContents($buildDir, 'index.html'); |
34
|
|
|
|
35
|
|
|
self::assertContains( |
36
|
|
|
'<title>Doctrine Static Website</title>', |
37
|
|
|
$indexContents |
38
|
|
|
); |
39
|
|
|
|
40
|
|
|
self::assertContains( |
41
|
|
|
'<h1>DoctrineStaticWebsiteGeneratorBundle</h1>', |
42
|
|
|
$indexContents |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
self::assertContains( |
46
|
|
|
'<p>Testing that DoctrineStaticWebsiteGeneratorBundle works in a Symfony application.</p>', |
47
|
|
|
$indexContents |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
self::assertContains('Homepage: /index.html', $indexContents); |
51
|
|
|
|
52
|
|
|
self::assertContains('Homepage URL: http://localhost/index.html', $indexContents); |
53
|
|
|
|
54
|
|
|
self::assertContains('Controller Data: This data came from the controller', $indexContents); |
55
|
|
|
|
56
|
|
|
self::assertContains('Request Data: /index.html', $indexContents); |
57
|
|
|
|
58
|
|
|
$apiIndexContents = $this->getFileContents($buildDir, 'api/index.html'); |
59
|
|
|
|
60
|
|
|
self::assertSame('This file should not be rendered.', trim($apiIndexContents)); |
61
|
|
|
|
62
|
|
|
$jwageContents = $this->getFileContents($buildDir, 'user/jwage.html'); |
63
|
|
|
|
64
|
|
|
self::assertContains('jwage', $jwageContents); |
65
|
|
|
|
66
|
|
|
$ocramiusContents = $this->getFileContents($buildDir, 'user/ocramius.html'); |
67
|
|
|
|
68
|
|
|
self::assertContains('ocramius', $ocramiusContents); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function getFileContents(string $buildDir, string $file) : string |
72
|
|
|
{ |
73
|
|
|
$path = $buildDir . '/' . $file; |
74
|
|
|
|
75
|
|
|
self::assertTrue(file_exists($path)); |
76
|
|
|
|
77
|
|
|
$contents = file_get_contents($path); |
78
|
|
|
assert($contents !== false); |
79
|
|
|
|
80
|
|
|
return $contents; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|