Completed
Push — master ( bf1f19...1204eb )
by Matthew
07:02
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
        $failed = false;
23
        try {
24
            $job->setArgs(array($job));
25
            $failed = true;
26
        } catch (\Exception $e) {
27
            self::assertTrue(true);
28
        }
29
        self::assertFalse($failed);
30
31
        try {
32
            $job->setArgs(array(1, array($job)));
33
            $failed = true;
34
        } catch (\Exception $e) {
35
            self::assertTrue(true);
36
        }
37
        self::assertFalse($failed);
38
    }
39
40
    public function testGettersSetters()
41
    {
42
        $this->runGetterSetterTests('\Dtc\QueueBundle\Model\Job');
43
    }
44
45
    public function testChainJobCall()
46
    {
47
        $jobManager = new StaticJobManager();
48
        $worker = new FibonacciWorker();
49
        $worker->setJobManager($jobManager);
50
51
        $job = new Job($worker, false, null);
52
        self::assertNull($job->getId(), 'Job id should be null');
53
54
        $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...
55
        self::assertNotNull($job->getId(), 'Job id should be generated');
56
57
        $failed = false;
58
        try {
59
            $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...
60
            $failed = true;
61
        } catch (\Exception $e) {
62
            self::assertTrue(true);
63
        }
64
        self::assertFalse($failed);
65
    }
66
}
67