Completed
Push — master ( e93157...8451c3 )
by Sergi Tur
09:10
created

InstallCommandTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 66
Code Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 66
rs 9.3191
cc 1
eloc 50
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
namespace Acacha\AdminLTETemplateLaravel;
4
5
use Acacha\AdminLTETemplateLaravel\Console\InstallCommand;
6
use Symfony\Component\Console\Application;
7
use Symfony\Component\Console\Tester\CommandTester;
8
9
/**
10
 * Class InstallCommandTest.
11
 */
12
class InstallCommandTest extends \PHPUnit_Framework_TestCase
13
{
14
15
    /**
16
     * Test execution.
17
     */
18
    public function testExecute()
19
    {
20
        $application = new Application();
21
        $application->add(new InstallCommand());
22
23
        $command = $application->find('install');
24
        $commandTester = new CommandTester($command);
25
        $commandTester->execute([
26
            'command' => $command->getName().
27
            '--force'
28
        ]);
29
30
        $this->assertTrue(
31
            $this->fileHasContent('/composer.json','acacha/admin-lte-template-laravel'));
32
33
        $this->assertTrue(
34
            $this->fileHasContent(
35
                '/config/app.php',
36
                'Acacha\AdminLTETemplateLaravel\Providers\AdminLTETemplateServiceProvider::class'
37
            ));
38
39
        $this->assertTrue(
40
            $this->fileHasContent(
41
                '/config/app.php',
42
                'Acacha\AdminLTETemplateLaravel\Facades\AdminLTE::class'
43
            ));
44
45
        $this->assertFileExists('app/Http/Controllers/HomeController.php');
46
47
        $this->assertTrue(
48
            $this->fileHasContent(
49
                '/app/Http/Controllers/Auth/RegisterController.php',
50
                "'terms' => 'required',"
51
            ));
52
53
        $this->assertFileExists('public/img');
54
        $this->assertFileExists('public/img/AcachaAdminLTE.png');
55
        $this->assertFileExists('public/css/AdminLTE.css');
56
        $this->assertFileExists('public/js/adminlte-app.js');
57
        $this->assertFileExists('public/plugins');
58
        $this->assertFileExists('public/fonts');
59
        $this->assertFileExists('resources/views/auth');
60
        $this->assertFileExists('resources/views/auth/emails');
61
        $this->assertFileExists('resources/views/errors/404.blade.php');
62
        $this->assertFileExists('resources/views/layouts');
63
        $this->assertFileExists('resources/views/home.blade.php');
64
        $this->assertTrue(
65
            $this->fileHasContent(
66
                '/resources/views/welcome.blade.php',
67
                "extends('layouts.landing')"
68
            ));
69
        $this->assertFileExists('resources/assets/less');
70
        $this->assertTrue(
71
            $this->fileHasContent(
72
                '/gulpfile.js',
73
                "mix.less('admin-lte/AdminLTE.less');"
74
            ));
75
        $this->assertFileExists('tests/AcachaAdminLTELaravelTest.php');
76
        $this->assertTrue(
77
            $this->fileHasContent(
78
                '/phpunit.xml',
79
                "sqlite"
80
            ));
81
        $this->assertFileExists('resources/lang/vendor/adminlte_lang');
82
        $this->assertFileExists('config/gravatar.php');
83
    }
84
85
    /**
86
     * Test if file has content.
87
     *
88
     * @param $file
89
     * @param $content
90
     * @return bool
91
     */
92
    private function fileHasContent($file, $content)
93
    {
94
        return strpos(file_get_contents(getcwd().$file), $content) != false;
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing strpos(file_get_contents...d() . $file), $content) of type integer to the boolean false. If you are specifically checking for non-zero, consider using something more explicit like > 0 or !== 0 instead.
Loading history...
95
    }
96
}