Completed
Push — master ( 40b87c...f82b1c )
by Matthew
04:37
created

JobTest::testToFromMessage()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 30
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
        try {
23
            $job->setArgs(array($job));
24
            self::fail('Invalid job argument passed');
25
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
26
        }
27
28
        try {
29
            $job->setArgs(array(1, array($job)));
30
            self::fail('Invalid job argument passed');
31
        } catch (\Exception $e) {
32
            self::assertTrue(true);
33
        }
34
    }
35
36
    public function testGettersSetters()
37
    {
38
        $this->runGetterSetterTests('\Dtc\QueueBundle\Model\Job');
39
    }
40
41
    public function testChainJobCall()
42
    {
43
        $jobManager = new StaticJobManager();
44
        $worker = new FibonacciWorker();
45
        $worker->setJobManager($jobManager);
46
47
        $job = new Job($worker, false, null);
48
        self::assertNull($job->getId(), 'Job id should be null');
49
50
        $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...
51
        self::assertNotNull($job->getId(), 'Job id should be generated');
52
53
        try {
54
            $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...
55
            self::fail('invalid chain, should fail');
56
        } catch (\Exception $e) {
57
            self::assertTrue(true);
58
        }
59
    }
60
}
61