GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

testIsUnlockedExitsWithZeroWhenDeployIsNotLocked()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
nc 1
nop 0
dl 0
loc 8
c 0
b 0
f 0
cc 1
rs 10
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer;
9
10
use Symfony\Component\Console\Output\Output;
11
12
class DeployTest extends AbstractTest
0 ignored issues
show
Deprecated Code introduced by
The class Deployer\AbstractTest has been deprecated: Use JoyTest instead. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

12
class DeployTest extends /** @scrutinizer ignore-deprecated */ AbstractTest
Loading history...
13
{
14
    public const RECIPE = __DIR__ . '/recipe/deploy.php';
15
16
    public function testDeploy()
17
    {
18
        $display = $this->dep(self::RECIPE, 'deploy');
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $display is correct as $this->dep(self::RECIPE, 'deploy') targeting Deployer\AbstractTest::dep() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Unused Code introduced by
The assignment to $display is dead and can be removed.
Loading history...
19
20
        $display = $this->tester->getDisplay();
21
        self::assertEquals(0, $this->tester->getStatusCode(), $display);
22
23
        foreach ($this->deployer->hosts as $host) {
24
            $deployPath = $host->get('deploy_path');
25
26
            self::assertDirectoryExists($deployPath . '/.dep');
27
            self::assertDirectoryExists($deployPath . '/releases');
28
            self::assertDirectoryExists($deployPath . '/shared');
29
            self::assertDirectoryExists($deployPath . '/current');
30
            self::assertDirectoryExists($deployPath . '/current/');
31
            self::assertFileExists($deployPath . '/current/README.md');
32
            self::assertDirectoryExists($deployPath . '/current/storage/logs');
33
            self::assertDirectoryExists($deployPath . '/current/storage/db');
34
            self::assertDirectoryExists($deployPath . '/shared/storage/logs');
35
            self::assertDirectoryExists($deployPath . '/shared/storage/db');
36
            self::assertFileExists($deployPath . '/shared/uploads/poem.txt');
37
            self::assertFileExists($deployPath . '/shared/.env');
38
            self::assertFileExists($deployPath . '/current/config/test.yaml');
39
            self::assertFileExists($deployPath . '/shared/config/test.yaml');
40
            self::assertEquals(1, intval(exec("cd $deployPath && ls -1 releases | wc -l")));
41
        }
42
    }
43
44
    public function testDeploySelectHosts()
45
    {
46
        $this->init(self::RECIPE);
47
        $this->tester->setInputs(['0,1']);
48
        $this->tester->run(['deploy', '-f' => self::RECIPE, '-l' => 1], [
49
            'verbosity' => Output::VERBOSITY_NORMAL,
50
            'interactive' => true,
51
        ]);
52
        self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay());
53
    }
54
55
    public function testKeepReleases()
56
    {
57
        for ($i = 0; $i < 3; $i++) {
58
            $this->dep(self::RECIPE, 'deploy');
59
            self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay());
60
        }
61
62
        for ($i = 0; $i < 6; $i++) {
63
            $this->dep(self::RECIPE, 'deploy:fail');
64
            self::assertEquals(1, $this->tester->getStatusCode(), $this->tester->getDisplay());
65
        }
66
67
        for ($i = 0; $i < 3; $i++) {
68
            $this->dep(self::RECIPE, 'deploy');
69
            self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay());
70
        }
71
72
        foreach ($this->deployer->hosts as $host) {
73
            $deployPath = $host->get('deploy_path');
74
75
            self::assertEquals(3, intval(exec("cd $deployPath && ls -1 releases | wc -l")));
76
        }
77
    }
78
79
    /**
80
     * @depends testKeepReleases
81
     */
82
    public function testRollback()
83
    {
84
        $this->dep(self::RECIPE, 'rollback');
85
86
        self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay());
87
88
        foreach ($this->deployer->hosts as $host) {
89
            $deployPath = $host->get('deploy_path');
90
91
            self::assertEquals(3, intval(exec("cd $deployPath && ls -1 releases | wc -l")));
92
        }
93
    }
94
95
    public function testFail()
96
    {
97
        $this->dep(self::RECIPE, 'deploy:fail');
98
99
        $display = $this->tester->getDisplay();
100
        self::assertEquals(1, $this->tester->getStatusCode(), $display);
101
102
        foreach ($this->deployer->hosts as $host) {
103
            $deployPath = $host->get('deploy_path');
104
105
            self::assertEquals('ok', exec("cd $deployPath && [ -f .dep/deploy.lock ] || echo ok"), 'fail hooks deploy:unlock did not run');
106
        }
107
    }
108
109
    /**
110
     * @depends testFail
111
     */
112
    public function testCleanup()
113
    {
114
        $this->dep(self::RECIPE, 'deploy:cleanup');
115
116
        self::assertEquals(0, $this->tester->getStatusCode(), $this->tester->getDisplay());
117
118
        foreach ($this->deployer->hosts as $host) {
119
            $deployPath = $host->get('deploy_path');
120
121
            self::assertFileDoesNotExist($deployPath . '/release');
122
        }
123
    }
124
125
    public function testIsUnlockedExitsWithOneWhenDeployIsLocked()
126
    {
127
        $this->dep(self::RECIPE, 'deploy:lock');
128
        $this->dep(self::RECIPE, 'deploy:is_locked');
129
        $display = $this->tester->getDisplay();
130
131
        self::assertStringContainsString('Deploy is locked by ', $display);
132
        self::assertSame(1, $this->tester->getStatusCode());
133
    }
134
135
    public function testIsUnlockedExitsWithZeroWhenDeployIsNotLocked()
136
    {
137
        $this->dep(self::RECIPE, 'deploy:unlock');
138
        $this->dep(self::RECIPE, 'deploy:is_locked');
139
        $display = $this->tester->getDisplay();
140
141
        self::assertStringContainsString('Deploy is unlocked.', $display);
142
        self::assertSame(0, $this->tester->getStatusCode());
143
    }
144
}
145