FunctionalTest::testBuildWebsite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 51
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 51
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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();
0 ignored issues
show
Unused Code introduced by
The assignment to $container is dead and can be removed.
Loading history...
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