Completed
Pull Request — master (#513)
by Helpful
04:05
created

RollbackStepTest::testSnapshotFailure()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 32
rs 8.8571
cc 1
eloc 17
nc 1
nop 0
1
<?php
2
3
/**
4
 * Test rollback of deployments
5
 */
6
class RollbackStepTest extends PipelineTest {
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
7
8
	protected static $fixture_file = 'PipelineTest.yml';
9
10
	/**
11
	 * Makes the dummy deployment step
12
	 *
13
	 * @return Pipeline
14
	 */
15
	public function getDummyPipeline($restoreDB = true) {
16
		// Get default backups
17
		$previous = DNDeployment::create();
18
		$previous->write();
19
		$current = DNDeployment::create();
20
		$current->write();
21
		$snapshot = DNDataTransfer::create();
22
		$snapshot->write();
23
24
		// Setup default pipeline
25
		$pipeline = $this->objFromFixture('Pipeline', 'testpipesmoketest');
26
		$pipeline->Config = serialize(array(
27
			'RollbackStep1' => array(
28
				'Class' => 'RollbackStep',
29
				'RestoreDB' => $restoreDB,
30
				'MaxDuration' => '3600'
31
			)
32
		));
33
		$pipeline->PreviousDeploymentID = $previous->ID;
34
		$pipeline->CurrentDeploymentID = $current->ID;
35
		$pipeline->PreviousSnapshotID = $snapshot->ID;
36
		$pipeline->write();
37
		return $pipeline;
38
	}
39
40
	public function testSuccessful() {
41
		$pipeline = $this->getDummyPipeline();
42
43
		// Start failure
44
		$pipeline->markFailed();
45
		$step = $pipeline->RollbackStep1();
46
47
		// Assert not error at startup
48
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
49
		$this->assertEquals('Deployment', $step->Doing);
1 ignored issue
show
Documentation introduced by
The property Doing does not exist on object<PipelineStep>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
		$this->assertNotLogged('Maintenance page disabled'); // Shouldn't be disabled yet
51
52
		// Mark the service as completed and check result
53
		$deployment = $step->RollbackDeployment();
0 ignored issues
show
Documentation Bug introduced by
The method RollbackDeployment does not exist on object<PipelineStep>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
54
		$deployment->markFinished();
55
56
		// Re-enter step as if called from checkPipelineStatus
57
		PipelineTest_MockLog::clear();
58
		$step->start();
59
60
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
61
		$this->assertEquals('Snapshot', $step->Doing);
1 ignored issue
show
Documentation introduced by
The property Doing does not exist on object<PipelineStep>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
		$this->assertNotLogged('Maintenance page disabled'); // Shouldn't be disabled yet
63
64
		// Mark the snapshot as completed and check result
65
		$snapshot = $step->RollbackDatabase();
0 ignored issues
show
Documentation Bug introduced by
The method RollbackDatabase does not exist on object<PipelineStep>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
66
		$snapshot->markFinished();
67
68
		// Re-enter step as if called from checkPipelineStatus
69
		PipelineTest_MockLog::clear();
70
		$step->start();
71
72
		$this->assertEquals('Finished', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
		// confirm the maintenace page has been left up for a failed rollback
74
		$this->assertFalse(PipelineTest_MockLog::has_message('Enabling maintenance page for failed rollback'));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
75
	}
76
77
	/**
78
	 * Test rollback without DB restoration
79
	 */
80
	public function testNoDB() {
81
		$pipeline = $this->getDummyPipeline(false);
82
83
		// Start failure
84
		$pipeline->markFailed();
85
		$step = $pipeline->RollbackStep1();
86
87
		// Assert not error at startup
88
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
		$this->assertEquals('Deployment', $step->Doing);
1 ignored issue
show
Documentation introduced by
The property Doing does not exist on object<PipelineStep>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
91
		// Mark the service as completed and check result
92
		$deployment = $step->RollbackDeployment();
0 ignored issues
show
Documentation Bug introduced by
The method RollbackDeployment does not exist on object<PipelineStep>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
93
		$deployment->markFinished();
94
95
		// Re-enter step as if called from checkPipelineStatus
96
		PipelineTest_MockLog::clear();
97
		$step->start();
98
99
		$this->assertEquals('Finished', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
100
	}
101
102
	/**
103
	 * Test failure at the snapshot step
104
	 */
105
	public function testSnapshotFailure() {
106
		$pipeline = $this->getDummyPipeline();
107
108
		// Start failure
109
		$pipeline->markFailed();
110
		$step = $pipeline->RollbackStep1();
111
112
		// Assert not error at startup
113
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
114
		$this->assertEquals('Deployment', $step->Doing);
1 ignored issue
show
Documentation introduced by
The property Doing does not exist on object<PipelineStep>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
115
116
		// Mark the service as completed and check result
117
		$deployment = $step->RollbackDeployment();
0 ignored issues
show
Documentation Bug introduced by
The method RollbackDeployment does not exist on object<PipelineStep>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
118
		$deployment->markFinished();
119
120
		// Re-enter step as if called from checkPipelineStatus
121
		PipelineTest_MockLog::clear();
122
		$step->start();
123
124
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
125
		$this->assertEquals('Snapshot', $step->Doing);
1 ignored issue
show
Documentation introduced by
The property Doing does not exist on object<PipelineStep>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
126
127
		// Mark the snapshot as completed and check result
128
		$snapshot = $step->RollbackDatabase();
0 ignored issues
show
Documentation Bug introduced by
The method RollbackDatabase does not exist on object<PipelineStep>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
129
		$snapshot->markFailed();
130
131
		// Re-enter step as if called from checkPipelineStatus
132
		PipelineTest_MockLog::clear();
133
		$step->start();
134
135
		$this->assertEquals('Failed', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
136
	}
137
138
	/**
139
	 * Test failure at the deployment step
140
	 */
141
	public function testDeploymentFailure() {
142
		$pipeline = $this->getDummyPipeline();
143
144
		// Start failure
145
		$pipeline->markFailed();
146
		$step = $pipeline->RollbackStep1();
147
148
		// Assert not error at startup
149
		$this->assertEquals('Started', $step->Status);
1 ignored issue
show
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
150
		$this->assertEquals('Deployment', $step->Doing);
1 ignored issue
show
Documentation introduced by
The property Doing does not exist on object<PipelineStep>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
The method assertEquals() does not seem to exist on object<RollbackStepTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
151
152
		// Mark the service as completed and check result
153
		$deployment = $step->RollbackDeployment();
0 ignored issues
show
Documentation Bug introduced by
The method RollbackDeployment does not exist on object<PipelineStep>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
154
		$deployment->markFailed();
155
156
		// Confirm that the maintenance page is not disabled
157
		$this->assertNotLogged('Maintenance page disabled');
158
	}
159
}
160