symbiote /
silverstripe-queuedjobs
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Symbiote\QueuedJobs\Tests; |
||
| 4 | |||
| 5 | use DateTime; |
||
| 6 | use SilverStripe\Dev\SapphireTest; |
||
| 7 | use SilverStripe\ORM\DataObject; |
||
| 8 | use SilverStripe\ORM\FieldType\DBDatetime; |
||
| 9 | use Symbiote\QueuedJobs\Tests\ScheduledExecutionTest\TestScheduledDataObject; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @author [email protected] |
||
| 13 | * @license BSD License http://silverstripe.org/bsd-license/ |
||
| 14 | */ |
||
| 15 | class ScheduledExecutionTest extends AbstractTest |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * We need the DB for this test |
||
| 19 | * |
||
| 20 | * @var bool |
||
| 21 | */ |
||
| 22 | protected $usesDatabase = true; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * {@inheritDoc} |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | protected static $extra_dataobjects = array( |
||
| 29 | TestScheduledDataObject::class |
||
| 30 | ); |
||
| 31 | |||
| 32 | protected function setUp() |
||
| 33 | { |
||
| 34 | parent::setUp(); |
||
| 35 | |||
| 36 | DBDatetime::set_mock_now('2018-05-28 13:15:00'); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function testScheduledExecutionTimes() |
||
| 40 | { |
||
| 41 | $test = new TestScheduledDataObject(); |
||
| 42 | |||
| 43 | $test->Title = 'Test execute of stuff'; |
||
|
0 ignored issues
–
show
|
|||
| 44 | $test->write(); |
||
| 45 | |||
| 46 | $test->FirstExecution = '1980-09-22 09:15:00'; |
||
|
0 ignored issues
–
show
The property
FirstExecution does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 47 | $test->ExecuteEvery = 'Hour'; |
||
|
0 ignored issues
–
show
The property
ExecuteEvery does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 48 | |||
| 49 | $test->write(); |
||
| 50 | |||
| 51 | // should now have a job |
||
| 52 | $this->assertTrue($test->ScheduledJobID > 0, 'Scheduled job has not been created'); |
||
|
0 ignored issues
–
show
The property
ScheduledJobID does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 53 | |||
| 54 | $jobId = $test->ScheduledJobID; |
||
|
0 ignored issues
–
show
The property
ScheduledJobID does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 55 | |||
| 56 | // execute said job |
||
| 57 | $job = $test->ScheduledJob(); |
||
|
0 ignored issues
–
show
The method
ScheduledJob does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 58 | |||
| 59 | $job->execute(); |
||
| 60 | |||
| 61 | // reload the test object and make sure its job has now changed |
||
| 62 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
| 63 | |||
| 64 | $this->assertNotEquals($test->ScheduledJobID, $jobId); |
||
| 65 | $this->assertEquals('EXECUTED', $test->Message); |
||
| 66 | } |
||
| 67 | |||
| 68 | public function testScheduledExecutionInterval() |
||
| 69 | { |
||
| 70 | $test = new TestScheduledDataObject(); |
||
| 71 | |||
| 72 | $test->Title = 'Test execute at custom interval sizes'; |
||
|
0 ignored issues
–
show
The property
Title does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 73 | $test->write(); |
||
| 74 | |||
| 75 | $test->FirstExecution = '1980-09-22 09:15:00'; |
||
|
0 ignored issues
–
show
The property
FirstExecution does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 76 | $test->ExecuteEvery = 'Minute'; |
||
|
0 ignored issues
–
show
The property
ExecuteEvery does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 77 | |||
| 78 | $test->write(); |
||
| 79 | |||
| 80 | // should now have a job |
||
| 81 | $this->assertTrue($test->ScheduledJobID > 0, 'Scheduled job has not been created'); |
||
|
0 ignored issues
–
show
The property
ScheduledJobID does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 82 | // should default the ExecuteInterval |
||
| 83 | $this->assertEquals(1, $test->ExecuteInterval, 'ExecuteInterval did not default to 1'); |
||
|
0 ignored issues
–
show
The property
ExecuteInterval does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __get, maybe consider adding a @property annotation.
Since your code implements the magic getter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
If the property has read access only, you can use the @property-read annotation instead. Of course, you may also just have mistyped another name, in which case you should fix the error. See also the PhpDoc documentation for @property. Loading history...
|
|||
| 84 | |||
| 85 | // should check the interval in code also |
||
| 86 | $test->ExecuteInterval = 0; |
||
|
0 ignored issues
–
show
The property
ExecuteInterval does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 87 | $test->write(); |
||
| 88 | |||
| 89 | $jobId = $test->ScheduledJobID; |
||
|
0 ignored issues
–
show
The property
ScheduledJobID does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>. Since you implemented __set, maybe consider adding a @property annotation.
Since your code implements the magic setter <?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...
|
|||
| 90 | |||
| 91 | // execute said job |
||
| 92 | $job = $test->ScheduledJob(); |
||
|
0 ignored issues
–
show
The method
ScheduledJob does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>? Since you implemented __call, maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
| 93 | $job->execute(); |
||
| 94 | |||
| 95 | // reload the test object and make sure its job has now changed |
||
| 96 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
| 97 | |||
| 98 | $this->assertNotEquals($test->ScheduledJobID, $jobId); |
||
| 99 | $this->assertEquals('EXECUTED', $test->Message); |
||
| 100 | |||
| 101 | $job = $test->ScheduledJob(); |
||
| 102 | |||
| 103 | $expected = new DateTime('+1 minute'); |
||
| 104 | $actual = new DateTime($job->StartAfter); |
||
| 105 | |||
| 106 | // Allow within 1 second. |
||
| 107 | $this->assertLessThanOrEqual(1, abs($actual->diff($expected)->s), 'Did not reschedule 1 minute later'); |
||
| 108 | |||
| 109 | // test a custom interval of 3 minutes |
||
| 110 | |||
| 111 | $test->ExecuteInterval = 3; |
||
| 112 | $test->write(); |
||
| 113 | |||
| 114 | $job = $test->ScheduledJob(); |
||
| 115 | $job->execute(); |
||
| 116 | |||
| 117 | $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID); |
||
| 118 | |||
| 119 | $job = $test->ScheduledJob(); |
||
| 120 | |||
| 121 | $expected = new DateTime('+3 minutes'); |
||
| 122 | $actual = new DateTime($job->StartAfter); |
||
| 123 | |||
| 124 | $this->assertLessThanOrEqual(1, abs($actual->diff($expected)->s), 'Did not reschedule 3 minutes later'); |
||
| 125 | } |
||
| 126 | } |
||
| 127 |
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@propertyannotation to your class or interface to document the existence of this variable.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.