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 ( 1aa213...c15ef7 )
by
unknown
02:04 queued 11s
created

QueuedJobsAdminTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 9
dl 0
loc 95
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 17 1
A testConstructorParamsShouldBeATextarea() 0 5 1
A testCreateJobWithConstructorParams() 0 15 2
A testCreateJobWithStartAfterOption() 0 22 1
1
<?php
2
3
namespace Symbiote\QueuedJobs\Tests;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Control\HTTPRequest;
7
use SilverStripe\Dev\FunctionalTest;
8
use SilverStripe\Forms\FieldList;
9
use SilverStripe\Forms\TextareaField;
10
use SilverStripe\ORM\FieldType\DBDatetime;
11
use Symbiote\QueuedJobs\Controllers\QueuedJobsAdmin;
12
use Symbiote\QueuedJobs\Jobs\PublishItemsJob;
13
use Symbiote\QueuedJobs\Services\QueuedJobService;
14
15
/**
16
 * Tests for the QueuedJobsAdmin ModelAdmin clas
17
 *
18
 * @coversDefaultClass \Symbiote\QueuedJobs\Controllers\QueuedJobsAdmin
19
 * @package queuedjobs
20
 * @author  Robbie Averill <[email protected]>
21
 */
22
class QueuedJobsAdminTest extends FunctionalTest
23
{
24
    /**
25
     * {@inheritDoc}
26
     * @var string
27
     */
28
    // protected static $fixture_file = 'QueuedJobsAdminTest.yml';
29
30
    protected $usesDatabase = true;
31
32
    /**
33
     * @var QueuedJobsAdmin
34
     */
35
    protected $admin;
36
37
    /**
38
     * Get a test class, and mock the job queue for it
39
     *
40
     * {@inheritDoc}
41
     */
42
    protected function setUp()
43
    {
44
        parent::setUp();
45
46
        // The shutdown handler doesn't play nicely with SapphireTest's database handling
47
        QueuedJobService::config()->set('use_shutdown_function', false);
48
49
        $this->admin = new QueuedJobsAdmin();
50
        $this->admin->setRequest(new HTTPRequest('GET', '/'));
51
        $this->admin->getRequest()->setSession($this->session());
52
53
        $mockQueue = $this->createMock(QueuedJobService::class);
54
        $this->admin->jobQueue = $mockQueue;
0 ignored issues
show
Documentation Bug introduced by
It seems like $mockQueue of type object<PHPUnit_Framework_MockObject_MockObject> is incompatible with the declared type object<Symbiote\QueuedJo...vices\QueuedJobService> of property $jobQueue.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
56
        $this->logInWithPermission('ADMIN');
57
        $this->admin->doInit();
58
    }
59
60
    /**
61
     * Ensure that the JobParams field is added as a Textarea
62
     */
63
    public function testConstructorParamsShouldBeATextarea()
64
    {
65
        $fields = $this->admin->getEditForm('foo', new FieldList())->Fields();
66
        $this->assertInstanceOf(TextareaField::class, $fields->fieldByName('JobParams'));
67
    }
68
69
    /**
70
     * Ensure that when a multi-line value is entered for JobParams, it is split by new line and each value
71
     * passed to the constructor of the JobType that is created by the reflection in createjob()
72
     *
73
     * @covers ::createjob
74
     */
75
    public function testCreateJobWithConstructorParams()
76
    {
77
        $this->admin->jobQueue
0 ignored issues
show
Documentation Bug introduced by
The method expects does not exist on object<Symbiote\QueuedJo...vices\QueuedJobService>? 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...
78
            ->expects($this->once())
79
            ->method('queueJob')
80
            ->with($this->callback(function ($job) {
81
                return $job instanceof PublishItemsJob && $job->rootID === 'foo123';
0 ignored issues
show
Documentation introduced by
The property rootID does not exist on object<Symbiote\QueuedJobs\Jobs\PublishItemsJob>. 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...
82
            }));
83
84
        $form = $this->admin->getEditForm('foo', new FieldList());
85
        $form->Fields()->fieldByName('JobParams')->setValue(implode(PHP_EOL, ['foo123', 'bar']));
86
        $form->Fields()->fieldByName('JobType')->setValue(PublishItemsJob::class);
87
88
        $this->admin->createjob($form->getData(), $form);
89
    }
90
91
    /**
92
     * @covers ::createjob
93
     */
94
    public function testCreateJobWithStartAfterOption()
95
    {
96
        $startTimeAfter = DBDatetime::now();
97
98
        $this->admin->jobQueue
0 ignored issues
show
Documentation Bug introduced by
The method expects does not exist on object<Symbiote\QueuedJo...vices\QueuedJobService>? 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...
99
            ->expects($this->once())
100
            ->method('queueJob')
101
            ->with(
102
                $this->callback(static function ($job) {
103
                    return $job instanceof PublishItemsJob;
104
                }),
105
                $this->callback(static function ($givenStartAfter) use ($startTimeAfter) {
106
                    return $givenStartAfter === $startTimeAfter->forTemplate();
107
                })
108
            );
109
110
        $form = $this->admin->getEditForm('foo', new FieldList());
111
        $form->Fields()->fieldByName('JobType')->setValue(PublishItemsJob::class);
112
        $form->Fields()->fieldByName('JobStart')->setValue($startTimeAfter);
113
114
        $this->admin->createjob($form->getData(), $form);
115
    }
116
}
117