GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 6956e2...9a55f0 )
by
unknown
02:08
created

testScheduledExecutionTimes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tests;
4
5
use SilverStripe\Dev\SapphireTest;
6
use SilverStripe\ORM\DataObject;
7
use SilverStripe\ORM\FieldType\DBDatetime;
8
use Symbiote\QueuedJobs\Tests\ScheduledExecutionTest\TestScheduledDataObject;
9
10
/**
11
 * @author [email protected]
12
 * @license BSD License http://silverstripe.org/bsd-license/
13
 */
14
class ScheduledExecutionTest extends AbstractTest
15
{
16
    /**
17
     * We need the DB for this test
18
     *
19
     * @var bool
20
     */
21
    protected $usesDatabase = true;
22
23
    /**
24
     * {@inheritDoc}
25
     * @var array
26
     */
27
    protected static $extra_dataobjects = array(
28
        TestScheduledDataObject::class
29
    );
30
31
    protected function setUp()
32
    {
33
        parent::setUp();
34
35
        DBDatetime::set_mock_now('2018-05-28 13:15:00');
36
    }
37
38
    public function testScheduledExecutionTimes()
39
    {
40
        $test = new TestScheduledDataObject;
41
42
        $test->Title = 'Test execute of stuff';
0 ignored issues
show
Documentation introduced by
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 _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...
43
        $test->write();
44
45
        $test->FirstExecution = '1980-09-22 09:15:00';
0 ignored issues
show
Documentation introduced by
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 _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...
46
        $test->ExecuteEvery = 'Hour';
0 ignored issues
show
Documentation introduced by
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 _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...
47
48
        $test->write();
49
50
        // should now have a job
51
        $this->assertTrue($test->ScheduledJobID > 0, 'Scheduled job has not been created');
0 ignored issues
show
Documentation introduced by
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 _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
52
53
        $jobId = $test->ScheduledJobID;
0 ignored issues
show
Documentation introduced by
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 _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...
54
55
        // execute said job
56
        $job = $test->ScheduledJob();
0 ignored issues
show
Documentation Bug introduced by
The method ScheduledJob does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
57
58
        $job->execute();
59
60
        // reload the test object and make sure its job has now changed
61
        $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID);
62
63
        $this->assertNotEquals($test->ScheduledJobID, $jobId);
64
        $this->assertEquals('EXECUTED', $test->Message);
65
    }
66
67
    public function testScheduledExecutionInterval()
68
    {
69
        $test = new TestScheduledDataObject;
70
71
        $test->Title = 'Test execute at custom interval sizes';
0 ignored issues
show
Documentation introduced by
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 _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...
72
        $test->write();
73
74
        $test->FirstExecution = '1980-09-22 09:15:00';
0 ignored issues
show
Documentation introduced by
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 _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...
75
        $test->ExecuteEvery = 'Minute';
0 ignored issues
show
Documentation introduced by
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 _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...
76
77
        $test->write();
78
79
        // should now have a job
80
        $this->assertTrue($test->ScheduledJobID > 0, 'Scheduled job has not been created');
0 ignored issues
show
Documentation introduced by
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 _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
81
        // should default the ExecuteInterval
82
        $this->assertEquals(1, $test->ExecuteInterval, 'ExecuteInterval did not default to 1');
0 ignored issues
show
Documentation introduced by
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 _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

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

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

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

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

}

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

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

See also the PhpDoc documentation for @property.

Loading history...
83
84
        // should check the interval in code also
85
        $test->ExecuteInterval = 0;
0 ignored issues
show
Documentation introduced by
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 _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...
86
        $test->write();
87
88
        $jobId = $test->ScheduledJobID;
0 ignored issues
show
Documentation introduced by
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 _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...
89
90
        // execute said job
91
        $job = $test->ScheduledJob();
0 ignored issues
show
Documentation Bug introduced by
The method ScheduledJob does not exist on object<Symbiote\QueuedJo...estScheduledDataObject>? Since you implemented __call, maybe consider adding a @method annotation.

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

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

class ParentClass {
    private $data = array();

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

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

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
92
        $job->execute();
93
94
        // reload the test object and make sure its job has now changed
95
        $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID);
96
97
        $this->assertNotEquals($test->ScheduledJobID, $jobId);
98
        $this->assertEquals('EXECUTED', $test->Message);
99
100
        $job = $test->ScheduledJob();
101
102
        // should reschedule in 1 minute time
103
        $expectedMinutes = date('i', time());
104
        $expectedMinutes = intval($expectedMinutes, 10);
105
        if ($expectedMinutes + 1 > 59) { // Wrap around the hour
106
            $expectedMinutes = $expectedMinutes - 59;
107
        }
108
        $scheduledMinutes = substr($job->StartAfter, 14, 2);
109
        $scheduledMinutes = intval($scheduledMinutes, 10);
110
111
        $this->assertEquals($expectedMinutes + 1, $scheduledMinutes, 'Did not reschedule 1 minute later');
112
113
        // test a custom interval of 3 minutes
114
115
        $test->ExecuteInterval = 3;
116
        $test->write();
117
118
        $job = $test->ScheduledJob();
119
        $job->execute();
120
121
        $test = DataObject::get_by_id(TestScheduledDataObject::class, $test->ID);
122
123
        $job = $test->ScheduledJob();
124
125
        // should reschedule in 3 minutes time
126
        $expectedMinutes = date('i', time());
127
        $expectedMinutes = intval($expectedMinutes, 10);
128
        if ($expectedMinutes + 3 > 59) {
129
            $expectedMinutes = $expectedMinutes - 59;
130
        }
131
        $scheduledMinutes = substr($job->StartAfter, 14, 2);
132
        $scheduledMinutes = intval($scheduledMinutes, 10);
133
134
        $this->assertEquals($expectedMinutes + 3, $scheduledMinutes, 'Did not reschedule 3 minutes later');
135
    }
136
}
137