Passed
Pull Request — master (#1)
by Jonathan
02:28
created

FunctionalTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 31
dl 0
loc 61
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileContents() 0 10 1
A testBuildWebsite() 0 47 1
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();
0 ignored issues
show
Unused Code introduced by
The assignment to $container is dead and can be removed.
Loading history...
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