Completed
Push — 2.9 ( 407240...f17a1b )
by Marcus
02:08
created

TestExceptingJob::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
/**
4
 *
5
 *
6
 * @author Marcus Nyeholt <[email protected]>
7
 */
8
class QueuedJobsTest extends SapphireTest {
0 ignored issues
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...
9
10
    /**
11
     * We need the DB for this test
12
     *
13
     * @var bool
14
     */
15
    protected $usesDatabase = true;
16
17
	public function setUp() {
18
		parent::setUp();
19
20
		Config::nest();
21
		// Two restarts are allowed per job
22
		Config::inst()->update('QueuedJobService', 'stall_threshold', 2);
23
	}
24
25
	public function tearDown() {
26
		Config::unnest();
27
		parent::tearDown();
28
	}
29
30
31
	/**
32
	 * @return QueuedJobService
33
	 */
34
	protected function getService() {
35
		return singleton("TestQJService");
36
	}
37
38
	public function testQueueJob() {
39
		$svc = $this->getService();
40
41
		// lets create a new job and add it tio the queue
42
		$job = new TestQueuedJob();
43
		$jobId = $svc->queueJob($job);
44
		$list = $svc->getJobList();
45
46
		$this->assertEquals(1, $list->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
47
48
		$myJob = null;
49
		foreach ($list as $job) {
50
			if ($job->Implementation == 'TestQueuedJob') {
51
				$myJob = $job;
52
				break;
53
			}
54
		}
55
56
		$this->assertNotNull($myJob);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<QueuedJobsTest>.

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...
57
		$this->assertTrue($jobId > 0);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<QueuedJobsTest>.

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...
58
		$this->assertEquals('TestQueuedJob', $myJob->Implementation);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
59
		$this->assertNotNull($myJob->SavedJobData);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<QueuedJobsTest>.

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...
60
	}
61
62
	public function testJobRunAs() {
63
		$svc = $this->getService();
64
		$list = $svc->getJobList();
65
		foreach ($list as $job) {
66
			$job->delete();
67
		}
68
69
		$this->logInWithPermission('DUMMY');
70
71
		// lets create a new job and add it tio the queue
72
		$job = new TestQueuedJob();
73
		$job->runningAs = "DUMMY";
0 ignored issues
show
Documentation introduced by
The property runningAs does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
74
		$jobId = $svc->queueJob($job);
0 ignored issues
show
Unused Code introduced by
$jobId is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
75
		$list = $svc->getJobList();
76
77
		$myJob = $list->First();
78
79
		$this->assertEquals("[email protected]", $myJob->RunAs()->Email);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
80
	}
81
82
	public function testQueueSignature() {
83
		$svc = $this->getService();
84
85
		// lets create a new job and add it tio the queue
86
		$job = new TestQueuedJob();
87
		$jobId = $svc->queueJob($job);
88
89
		$newJob = new TestQueuedJob();
90
		$newId = $svc->queueJob($newJob);
91
92
		$this->assertEquals($jobId, $newId);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
93
94
		// now try another, but with different params
95
		$newJob = new TestQueuedJob();
96
		$newJob->randomParam = 'stuff';
0 ignored issues
show
Documentation introduced by
The property randomParam does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
97
		$newId = $svc->queueJob($newJob);
98
99
		$this->assertNotEquals($jobId, $newId);
0 ignored issues
show
Bug introduced by
The method assertNotEquals() does not seem to exist on object<QueuedJobsTest>.

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
	public function testProcessJob() {
103
		$job = new TestQueuedJob();
104
		$job->setup();
105
		$job->process();
106
		// we should now have some  data
107
		$data = $job->getJobData();
108
		$this->assertNotNull($data->messages);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<QueuedJobsTest>.

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...
109
		$this->assertFalse($data->isComplete);
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<QueuedJobsTest>.

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...
110
111
		$jd = $data->jobData;
112
		$this->assertTrue(isset($jd->times));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<QueuedJobsTest>.

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...
113
		$this->assertEquals(1, count($jd->times));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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
115
		// now take the 'saved' data and try restoring the job
116
	}
117
118
	public function testResumeJob() {
119
		$job = new TestQueuedJob();
120
		$job->setup();
121
		$job->process();
122
		// we should now have some  data
123
		$data = $job->getJobData();
124
125
		// so create a new job and restore it from this data
126
127
		$job = new TestQueuedJob();
128
		$job->setup();
129
130
		$job->setJobData($data->totalSteps, $data->currentStep, $data->isComplete, $data->jobData, $data->messages);
131
		$job->process();
132
133
		$data = $job->getJobData();
134
		$this->assertFalse($data->isComplete);
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<QueuedJobsTest>.

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...
135
		$jd = $data->jobData;
136
		$this->assertTrue(isset($jd->times));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<QueuedJobsTest>.

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...
137
		$this->assertEquals(2, count($jd->times));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
138
	}
139
140
	public function testInitialiseJob() {
141
		// okay, lets test it out on the actual service
142
		$svc = $this->getService();
143
		// lets create a new job and add it to the queue
144
		$job = new TestQueuedJob();
145
		$id = $svc->queueJob($job);
146
147
		$descriptor = DataObject::get_by_id('QueuedJobDescriptor', $id);
148
149
		$job = $svc->testInit($descriptor);
150
		$this->assertInstanceOf('TestQueuedJob', $job, 'Job has been triggered');
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<QueuedJobsTest>.

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
		$descriptor = DataObject::get_by_id('QueuedJobDescriptor', $id);
153
154
		$this->assertEquals(QueuedJob::STATUS_INIT, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
155
	}
156
157
	public function testStartJob() {
158
		// okay, lets test it out on the actual service
159
		$svc = $this->getService();
160
		// lets create a new job and add it to the queue
161
162
		$this->logInWithPermission('DUMMYUSER');
163
164
		$job = new TestQueuedJob();
165
		$job->testingStartJob = true;
0 ignored issues
show
Documentation introduced by
The property testingStartJob does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
166
		$id = $svc->queueJob($job);
167
168
		$this->logInWithPermission('ADMIN');
169
170
		$result = $svc->runJob($id);
171
		$this->assertTrue($result);
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<QueuedJobsTest>.

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...
172
173
		// we want to make sure that the current user is the runas user of the job
174
		$descriptor = DataObject::get_by_id('QueuedJobDescriptor', $id);
175
		$this->assertEquals('Complete', $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
176
	}
177
178
	public function testImmediateQueuedJob() {
179
		// okay, lets test it out on the actual service
180
		$svc = $this->getService();
181
		// lets create a new job and add it to the queue
182
183
		$job = new TestQueuedJob(QueuedJob::IMMEDIATE);
184
		$job->firstJob = true;
0 ignored issues
show
Documentation introduced by
The property firstJob does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
185
		$id = $svc->queueJob($job);
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
186
187
		$job = new TestQueuedJob(QueuedJob::IMMEDIATE);
188
		$job->secondJob = true;
0 ignored issues
show
Documentation introduced by
The property secondJob does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
189
		$id = $svc->queueJob($job);
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
190
191
		$jobs = $svc->getJobList(QueuedJob::IMMEDIATE);
192
		$this->assertEquals(2, $jobs->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
193
194
		// now fake a shutdown
195
		$svc->onShutdown();
196
197
		$jobs = $svc->getJobList(QueuedJob::IMMEDIATE);
198
		$this->assertInstanceOf('DataList', $jobs);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<QueuedJobsTest>.

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...
199
		$this->assertEquals(0, $jobs->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
200
	}
201
202
	public function testNextJob() {
203
		$svc = $this->getService();
204
		$list = $svc->getJobList();
205
206
		foreach ($list as $job) {
207
			$job->delete();
208
		}
209
210
		$list = $svc->getJobList();
211
		$this->assertEquals(0, $list->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
212
213
		$job = new TestQueuedJob();
214
		$id1 = $svc->queueJob($job);
215
216
		$job = new TestQueuedJob();
217
		// to get around the signature checks
218
		$job->randomParam = 'me';
0 ignored issues
show
Documentation introduced by
The property randomParam does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
219
		$id2 = $svc->queueJob($job);
0 ignored issues
show
Unused Code introduced by
$id2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
220
221
		$job = new TestQueuedJob();
222
		// to get around the signature checks
223
		$job->randomParam = 'mo';
0 ignored issues
show
Documentation introduced by
The property randomParam does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
224
		$id3 = $svc->queueJob($job);
225
226
		$this->assertEquals(2, $id3 - $id1);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
227
228
		$list = $svc->getJobList();
229
		$this->assertEquals(3, $list->count());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
230
231
		// okay, lets get the first one and initialise it, then make sure that a subsequent init attempt fails
232
		$job = $svc->getNextPendingJob();
233
234
		$this->assertEquals($id1, $job->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
235
		$svc->testInit($job);
236
237
		// now try and get another, it should be === false
238
		$next = $svc->getNextPendingJob();
239
240
		$this->assertFalse($next);
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<QueuedJobsTest>.

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...
241
	}
242
243
	/**
244
	 * Verify that broken jobs are correctly verified for health and restarted as necessary
245
	 *
246
	 * Order of checkJobHealth() and getNextPendingJob() is important
247
	 *
248
	 * Execution of this job is broken into several "loops", each of which represents one invocation
249
	 * of ProcessJobQueueTask
250
	 */
251
	public function testJobHealthCheck() {
252
		// Create a job and add it to the queue
253
		$svc = $this->getService();
254
		$job = new TestQueuedJob(QueuedJob::IMMEDIATE);
255
		$job->firstJob = true;
0 ignored issues
show
Documentation introduced by
The property firstJob does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
256
		$id = $svc->queueJob($job);
257
		$descriptor = QueuedJobDescriptor::get()->byID($id);
258
259
		// Verify initial state is new and LastProcessedCount is not marked yet
260
		$this->assertEquals(QueuedJob::STATUS_NEW, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
261
		$this->assertEquals(0, $descriptor->StepsProcessed);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
262
		$this->assertEquals(-1, $descriptor->LastProcessedCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
263
		$this->assertEquals(0, $descriptor->ResumeCounts);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
264
265
		// Loop 1 - Pick up new job and attempt to run it
266
		// Job health should not attempt to cleanup unstarted jobs
267
		$svc->checkJobHealth(QueuedJob::IMMEDIATE);
268
		$nextJob = $svc->getNextPendingJob(QueuedJob::IMMEDIATE);
269
270
		// Ensure that this is the next job ready to go
271
		$descriptor = QueuedJobDescriptor::get()->byID($id);
272
		$this->assertEquals($nextJob->ID, $descriptor->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
273
		$this->assertEquals(QueuedJob::STATUS_NEW, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
274
		$this->assertEquals(0, $descriptor->StepsProcessed);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
275
		$this->assertEquals(-1, $descriptor->LastProcessedCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
276
		$this->assertEquals(0, $descriptor->ResumeCounts);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
277
278
		// Run 1 - Start the job (no work is done)
279
		$descriptor->JobStatus = QueuedJob::STATUS_INIT;
280
		$descriptor->write();
281
282
		// Assume that something bad happens at this point, the process dies during execution, and
283
		// the task is re-initiated somewhere down the track
284
285
		// Loop 2 - Detect broken job, and mark it for future checking.
286
		$svc->checkJobHealth(QueuedJob::IMMEDIATE);
287
		$nextJob = $svc->getNextPendingJob(QueuedJob::IMMEDIATE);
288
289
		// Note that we don't immediately try to restart it until StepsProcessed = LastProcessedCount
290
		$descriptor = QueuedJobDescriptor::get()->byID($id);
291
		$this->assertFalse($nextJob); // Don't run it this round please!
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<QueuedJobsTest>.

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...
292
		$this->assertEquals(QueuedJob::STATUS_INIT, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
293
		$this->assertEquals(0, $descriptor->StepsProcessed);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
294
		$this->assertEquals(0, $descriptor->LastProcessedCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
295
		$this->assertEquals(0, $descriptor->ResumeCounts);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
296
297
		// Loop 3 - We've previously marked this job as broken, so restart it this round
298
		// If no more work has been done on the job at this point, assume that we are able to
299
		// restart it
300
		$svc->checkJobHealth(QueuedJob::IMMEDIATE);
301
		$nextJob = $svc->getNextPendingJob(QueuedJob::IMMEDIATE);
302
303
		// This job is resumed and exeuction is attempted this round
304
		$descriptor = QueuedJobDescriptor::get()->byID($id);
305
		$this->assertEquals($nextJob->ID, $descriptor->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
306
		$this->assertEquals(QueuedJob::STATUS_WAIT, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
307
		$this->assertEquals(0, $descriptor->StepsProcessed);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
308
		$this->assertEquals(0, $descriptor->LastProcessedCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
309
		$this->assertEquals(1, $descriptor->ResumeCounts);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
310
311
		// Run 2 - First restart (work is done)
312
		$descriptor->JobStatus = QueuedJob::STATUS_RUN;
313
		$descriptor->StepsProcessed++; // Essentially delays the next restart by 1 loop
314
		$descriptor->write();
315
316
		// Once again, at this point, assume the job fails and crashes
317
318
		// Loop 4 - Assuming a job has LastProcessedCount < StepsProcessed we are in the same
319
		// situation as step 2.
320
		// Because the last time the loop ran, StepsProcessed was incremented,
321
		// this indicates that it's likely that another task could be working on this job, so
322
		// don't run this.
323
		$svc->checkJobHealth(QueuedJob::IMMEDIATE);
324
		$nextJob = $svc->getNextPendingJob(QueuedJob::IMMEDIATE);
325
326
		$descriptor = QueuedJobDescriptor::get()->byID($id);
327
		$this->assertFalse($nextJob); // Don't run jobs we aren't sure should be restarted
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<QueuedJobsTest>.

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...
328
		$this->assertEquals(QueuedJob::STATUS_RUN, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
329
		$this->assertEquals(1, $descriptor->StepsProcessed);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
330
		$this->assertEquals(1, $descriptor->LastProcessedCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
331
		$this->assertEquals(1, $descriptor->ResumeCounts);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
332
333
		// Loop 5 - Job is again found to not have been restarted since last iteration, so perform second
334
		// restart. The job should be attempted to run this loop
335
		$svc->checkJobHealth(QueuedJob::IMMEDIATE);
336
		$nextJob = $svc->getNextPendingJob(QueuedJob::IMMEDIATE);
337
338
		// This job is resumed and exeuction is attempted this round
339
		$descriptor = QueuedJobDescriptor::get()->byID($id);
340
		$this->assertEquals($nextJob->ID, $descriptor->ID);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
341
		$this->assertEquals(QueuedJob::STATUS_WAIT, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
342
		$this->assertEquals(1, $descriptor->StepsProcessed);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
343
		$this->assertEquals(1, $descriptor->LastProcessedCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
344
		$this->assertEquals(2, $descriptor->ResumeCounts);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
345
346
		// Run 3 - Second and last restart (no work is done)
347
		$descriptor->JobStatus = QueuedJob::STATUS_RUN;
348
		$descriptor->write();
349
350
		// Loop 6 - As no progress has been made since loop 3, we can mark this as dead
351
		$svc->checkJobHealth(QueuedJob::IMMEDIATE);
352
		$nextJob = $svc->getNextPendingJob(QueuedJob::IMMEDIATE);
353
354
		// Since no StepsProcessed has been done, don't wait another loop to mark this as dead
355
		$descriptor = QueuedJobDescriptor::get()->byID($id);
356
		$this->assertEquals(QueuedJob::STATUS_PAUSED, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
357
		$this->assertEmpty($nextJob);
0 ignored issues
show
Bug introduced by
The method assertEmpty() does not seem to exist on object<QueuedJobsTest>.

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...
358
	}
359
360
    public function testExceptionWithMemoryExhaustion() {
361
        $svc = $this->getService();
362
        $job = new TestExceptingJob();
363
		$job->firstJob = true;
0 ignored issues
show
Documentation introduced by
The property firstJob does not exist on object<TestExceptingJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
364
		$id = $svc->queueJob($job);
365
		$descriptor = QueuedJobDescriptor::get()->byID($id);
0 ignored issues
show
Unused Code introduced by
$descriptor is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
366
367
        // we want to set the memory limit _really_ low so that our first run triggers
368
        $mem = Config::inst()->get('QueuedJobService', 'memory_limit');
369
        Config::inst()->update('QueuedJobService', 'memory_limit', 1);
370
371
        $svc->runJob($id);
372
373
        Config::inst()->update('QueuedJobService', 'memory_limit', $mem);
374
375
        $descriptor = QueuedJobDescriptor::get()->byID($id);
376
377
        $this->assertEquals(QueuedJob::STATUS_BROKEN, $descriptor->JobStatus);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<QueuedJobsTest>.

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...
378
    }
379
}
380
381
// stub class to be able to call init from an external context
382
class TestQJService extends QueuedJobService {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
383
	public function testInit($descriptor) {
384
		return $this->initialiseJob($descriptor);
385
	}
386
}
387
388
class TestExceptingJob extends  AbstractQueuedJob implements QueuedJob {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
Coding Style introduced by
Expected 1 space before "AbstractQueuedJob"; 2 found
Loading history...
389
    private $type = QueuedJob::QUEUED;
390
391
	public function __construct($type = null) {
392
        $this->type = QueuedJob::IMMEDIATE;
393
		$this->times = array();
0 ignored issues
show
Documentation introduced by
The property times does not exist on object<TestExceptingJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
394
	}
395
396
	public function getJobType() {
397
		return $this->type;
398
	}
399
400
	public function getTitle() {
401
		return "A Test job throwing exceptions";
402
	}
403
404
	public function setup() {
405
		$this->totalSteps = 1;
406
	}
407
408
	public function process() {
409
		throw new Exception("just excepted");
410
	}
411
}
412
413
class TestQueuedJob extends AbstractQueuedJob implements QueuedJob {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
414
	private $type = QueuedJob::QUEUED;
415
416
	public function __construct($type = null) {
417
		if ($type) {
418
			$this->type = $type;
419
		}
420
		$this->times = array();
0 ignored issues
show
Documentation introduced by
The property times does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
421
	}
422
423
	public function getJobType() {
424
		return $this->type;
425
	}
426
427
	public function getTitle() {
428
		return "A Test job";
429
	}
430
431
	public function setup() {
432
		$this->totalSteps = 5;
433
	}
434
435 View Code Duplication
	public function process() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
436
		$times = $this->times;
0 ignored issues
show
Documentation introduced by
The property times does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
437
		// needed due to quirks with __set
438
		$times[] = date('Y-m-d H:i:s');
439
		$this->times = $times;
0 ignored issues
show
Documentation introduced by
The property times does not exist on object<TestQueuedJob>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
440
441
		$this->addMessage("Updated time to " . date('Y-m-d H:i:s'));
442
		sleep(1);
443
444
		// make sure we're incrementing
445
		$this->currentStep++;
446
447
		// and checking whether we're complete
448
		if ($this->currentStep == 5) {
449
			$this->isComplete = true;
450
		}
451
	}
452
}
453