Completed
Push — master ( 1204eb...5574d8 )
by Matthew
05:57
created

JobTest::testGettersSetters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Dtc\QueueBundle\Tests\Model;
4
5
use Dtc\QueueBundle\Model\Job;
6
use Dtc\QueueBundle\Tests\FibonacciWorker;
7
use Dtc\QueueBundle\Tests\GetterSetterTrait;
8
use Dtc\QueueBundle\Tests\StaticJobManager;
9
use PHPUnit\Framework\TestCase;
10
11
class JobTest extends TestCase
12
{
13
    use GetterSetterTrait;
14
15
    public function testSetArgs()
16
    {
17
        $worker = new FibonacciWorker();
18
        $job = new Job($worker, false, null);
19
        $job->setArgs(array(1));
20
        $job->setArgs(array(1, array(1, 2)));
21
22
        $this->callSetArgs($job, array($job));
23
        $this->callSetArgs($job, array(1, array($job)));
24
    }
25
26 View Code Duplication
    protected function callSetArgs(Job $job, $args)
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...
27
    {
28
        $failed = false;
29
        try {
30
            $job->setArgs($args);
31
            $failed = true;
32
        } catch (\Exception $e) {
33
            self::assertTrue(true);
34
        }
35
        self::assertFalse($failed);
36
    }
37
38
    public function testGettersSetters()
39
    {
40
        $this->runGetterSetterTests('\Dtc\QueueBundle\Model\Job');
41
    }
42
43
    public function testChainJobCall()
44
    {
45
        $jobManager = new StaticJobManager();
46
        $worker = new FibonacciWorker();
47
        $worker->setJobManager($jobManager);
48
49
        $job = new Job($worker, false, null);
50
        self::assertNull($job->getId(), 'Job id should be null');
51
52
        $job->fibonacci(1);
0 ignored issues
show
Documentation Bug introduced by
The method fibonacci does not exist on object<Dtc\QueueBundle\Model\Job>? 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...
53
        self::assertNotNull($job->getId(), 'Job id should be generated');
54
55
        $failed = false;
56
        try {
57
            $job->invalidFunctionCall();
0 ignored issues
show
Documentation Bug introduced by
The method invalidFunctionCall does not exist on object<Dtc\QueueBundle\Model\Job>? 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...
58
            $failed = true;
59
        } catch (\Exception $e) {
60
            self::assertTrue(true);
61
        }
62
        self::assertFalse($failed);
63
    }
64
}
65