Passed
Pull Request — master (#9)
by Jim
01:46
created

ProcessorTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
4
namespace Jarobe\TaskRunnerBundle\Tests\Processor;
5
6
7
use Jarobe\TaskRunnerBundle\Driver\Factory\DriverFactory;
8
use Jarobe\TaskRunnerBundle\Driver\TaskDriverInterface;
9
use Jarobe\TaskRunnerBundle\Exception\TaskException;
10
use Jarobe\TaskRunnerBundle\Model\TaskResult;
11
use Jarobe\TaskRunnerBundle\Processor\Processor;
12
use Jarobe\TaskRunnerBundle\Processor\ProcessorInterface;
13
use Jarobe\TaskRunnerBundle\TaskType\TaskTypeInterface;
14
use Prophecy\Prophecy\ObjectProphecy;
15
16
class ProcessorTest extends \PHPUnit_Framework_TestCase
17
{
18
    /** @var DriverFactory|ObjectProphecy */
19
    private $driverFactory;
20
21
    /** @var Processor */
22
    private $processor;
23
24
    public function setUp()
25
    {
26
        $this->driverFactory = $this->prophesize(DriverFactory::class);
27
        $this->processor = new Processor($this->driverFactory->reveal());
28
    }
29
30
    /**
31
     * @test
32
     * @dataProvider processExamples
33
     */
34
    public function it_can_process_tasks(
35
        $success,
36
        array $validationErrors,
37
        array $runErrors
38
    )
39
    {
40
        /** @var TaskDriverInterface|ObjectProphecy $driver */
41
        $driver = $this->prophesize(TaskDriverInterface::class);
42
43
        /** @var TaskTypeInterface|ObjectProphecy $task */
44
        $task = $this->prophesize(TaskTypeInterface::class);
45
46
        //Try for a driver
47
        $driver->canRun($task->reveal())->willReturn($validationErrors);
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Jarobe\TaskRunnerBundle\TaskType\TaskTypeInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method canRun does only exist in Jarobe\TaskRunnerBundle\Driver\TaskDriverInterface, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
48
        $driver->run($task->reveal())->willReturn($runErrors);
0 ignored issues
show
Bug introduced by
The method run does only exist in Jarobe\TaskRunnerBundle\Driver\TaskDriverInterface, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
49
50
        $this->driverFactory->getDriverForTask($task->reveal())->willReturn($driver->reveal());
0 ignored issues
show
Bug introduced by
The method getDriverForTask does only exist in Jarobe\TaskRunnerBundle\...r\Factory\DriverFactory, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Jarobe\TaskRunnerBundle\Driver\TaskDriverInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
51
52
        $result = $this->processor->process($task->reveal());
53
        $this->assertInstanceOf(TaskResult::class, $result);
54
        $this->assertEquals($success, $result->isSuccess());
55
56
        if (count($validationErrors) > 0) {
57
            $this->assertEquals($validationErrors, $result->getErrors());
58
        } else {
59
            $this->assertEquals($runErrors, $result->getErrors());
60
        }
61
    }
62
63
    public function processExamples()
64
    {
65
        return [
66
            [true, [], []],
67
            [false, ['error'], []],
68
            [false, [], ['error']],
69
            [false, ['error'], ['error']]
70
        ];
71
    }
72
73
    /**
74
     * @test
75
     */
76
    public function it_handles_an_unsupported_task()
77
    {
78
        /** @var TaskTypeInterface|ObjectProphecy $task */
79
        $task = $this->prophesize(TaskTypeInterface::class);
80
81
        //Try for a driver that doesn't exist
82
        $this->driverFactory->getDriverForTask($task->reveal())->willThrow(TaskException::class);
0 ignored issues
show
Bug introduced by
The method reveal does only exist in Prophecy\Prophecy\ObjectProphecy, but not in Jarobe\TaskRunnerBundle\TaskType\TaskTypeInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
Bug introduced by
The method getDriverForTask does only exist in Jarobe\TaskRunnerBundle\...r\Factory\DriverFactory, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
83
84
        $result = $this->processor->process($task->reveal());
85
        $this->assertInstanceOf(TaskResult::class, $result);
86
        $this->assertEquals(false, $result->isSuccess());
87
        $this->assertCount(1, $result->getErrors());
88
    }
89
}
90