Completed
Pull Request — 2.9 (#116)
by
unknown
01:57
created

QueuedJobsTest   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 455
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 8
dl 0
loc 455
rs 10
c 0
b 0
f 0

15 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A tearDown() 0 4 1
A getService() 0 3 1
A testQueueJob() 0 23 3
A testJobRunAs() 0 19 2
A testQueueSignature() 0 19 1
A testProcessJob() 0 15 1
A testResumeJob() 0 21 1
A testInitialiseJob() 0 16 1
A testStartJob() 0 20 1
A testImmediateQueuedJob() 0 23 1
B testNextJob() 0 40 2
B testJobHealthCheck() 0 108 1
A testExceptionWithMemoryExhaustion() 0 19 1
B testCheckdefaultJobs() 0 81 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
	public function testCheckdefaultJobs() {
381
		// Create a job and add it to the queue
382
		$svc = $this->getService();
383
		$testDefaultJobsArray = array(
384
			'ArbitraryName' => array(
385
				# I'll get restarted and create an alert email
386
				'type' => 'TestQueuedJob',
387
				'filter' => array(
388
					'JobTitle' => "A Test job"
389
				),
390
				'recreate' => 1,
391
				'construct' => array(
392
					'queue' => QueuedJob::QUEUED
393
				),
394
				'startDateFormat' => 'Y-m-d 02:00:00',
395
				'startTimeString' => 'tomorrow',
396
				'email' => '[email protected]'
397
		));
398
		$svc->defaultJobs = $testDefaultJobsArray;
399
		$jobConfig = $testDefaultJobsArray['ArbitraryName'];
400
401
		$activeJobs = QueuedJobDescriptor::get()->filter(
402
				'JobStatus', array(
403
					QueuedJob::STATUS_NEW,
404
					QueuedJob::STATUS_INIT,
405
					QueuedJob::STATUS_RUN,
406
					QueuedJob::STATUS_WAIT,
407
				)
408
		);
409
		//assert no jobs currently active
410
		$this->assertEquals(0, $activeJobs->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...
411
412
		//add a default job to the queue
413
		$svc->checkdefaultJobs();
414
		$this->assertEquals(1, $activeJobs->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...
415
		$descriptor = $activeJobs->filter(array_merge(
416
								array('Implementation' => $jobConfig['type']), $jobConfig['filter']
417
				))->first();
418
		// Verify initial state is new
419
		$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...
420
421
		//update Job to broken
422
		$descriptor->JobStatus = QueuedJob::STATUS_BROKEN;
423
		$descriptor->write();
424
		//check and add job for broken job
425
		$svc->checkdefaultJobs();
426
		$this->assertEquals(1, $activeJobs->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...
427
		//assert we now have 2 of our job (one good one broken)
428
		$this->assertEquals(2, QueuedJobDescriptor::get()->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...
429
430
		//test not adding a job when job is there already
431
		$svc->checkdefaultJobs();
432
		$this->assertEquals(1, $activeJobs->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...
433
		//assert we now have 2 of our job (one good one broken)
434
		$this->assertEquals(2, QueuedJobDescriptor::get()->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...
435
436
		//test add jobs with various start dates
437
		$job = $activeJobs->first();
438
		date('Y-m-d 02:00:00', strtotime('+1 day'));
439
		$this->assertEquals(date('Y-m-d 02:00:00', strtotime('+1 day')), $job->StartAfter);
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...
440
		//swap start time to midday
441
		$testDefaultJobsArray['ArbitraryName']['startDateFormat'] = 'Y-m-d 12:00:00';
442
		//clean up then add new jobs
443
		$svc->defaultJobs = $testDefaultJobsArray;
444
		$activeJobs->removeAll();
445
		$svc->checkdefaultJobs();
446
		//assert one jobs currently active
447
		$this->assertEquals(1, $activeJobs->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...
448
		$job = $activeJobs->first();
449
		$this->assertEquals(date('Y-m-d 12:00:00', strtotime('+1 day')), $job->StartAfter);
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...
450
		//test alert email
451
		$email = $this->findEmail('[email protected]');
452
		$this->assertNotNull($email);
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...
453
454
		//test broken job config
455
		unset($testDefaultJobsArray['ArbitraryName']['startDateFormat']);
456
		//clean up then add new jobs
457
		$svc->defaultJobs = $testDefaultJobsArray;
458
		$activeJobs->removeAll();
459
		$svc->checkdefaultJobs();
460
	}
461
462
}
463
464
// stub class to be able to call init from an external context
465
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...
466
	public function testInit($descriptor) {
467
		return $this->initialiseJob($descriptor);
468
	}
469
}
470
471
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...
472
    private $type = QueuedJob::QUEUED;
473
474
	public function __construct($type = null) {
475
        $this->type = QueuedJob::IMMEDIATE;
476
		$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...
477
	}
478
479
	public function getJobType() {
480
		return $this->type;
481
	}
482
483
	public function getTitle() {
484
		return "A Test job throwing exceptions";
485
	}
486
487
	public function setup() {
488
		$this->totalSteps = 1;
489
	}
490
491
	public function process() {
492
		throw new Exception("just excepted");
493
	}
494
}
495
496
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...
497
	private $type = QueuedJob::QUEUED;
498
499
	public function __construct($type = null) {
500
		if ($type) {
501
			$this->type = $type;
502
		}
503
		$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...
504
	}
505
506
	public function getJobType() {
507
		return $this->type;
508
	}
509
510
	public function getTitle() {
511
		return "A Test job";
512
	}
513
514
	public function setup() {
515
		$this->totalSteps = 5;
516
	}
517
518 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...
519
		$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...
520
		// needed due to quirks with __set
521
		$times[] = date('Y-m-d H:i:s');
522
		$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...
523
524
		$this->addMessage("Updated time to " . date('Y-m-d H:i:s'));
525
		sleep(1);
526
527
		// make sure we're incrementing
528
		$this->currentStep++;
529
530
		// and checking whether we're complete
531
		if ($this->currentStep == 5) {
532
			$this->isComplete = true;
533
		}
534
	}
535
}
536