Completed
Pull Request — master (#20)
by Wachter
05:08
created

TestHandler   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
lcom 0
cbo 0
dl 0
loc 10
rs 10
c 1
b 0
f 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\Tests\Unit\Handler;
13
14
use Task\Handler\TaskHandlerInterface;
15
use Task\Handler\TaskHandlerNotExistsException;
16
use Task\TaskBundle\Handler\TaskHandlerFactory;
17
18
/**
19
 * Tests for class TaskHandlerFactory.
20
 */
21
class TaskHandlerFactoryTest extends \PHPUnit_Framework_TestCase
22
{
23
    public function testCreate()
24
    {
25
        $handler = new TestHandler();
26
        $taskHandlerFactory = new TaskHandlerFactory([TestHandler::class => $handler]);
27
28
        $this->assertEquals($handler, $taskHandlerFactory->create(TestHandler::class));
29
    }
30
31
    public function testCreateNotExists()
32
    {
33
        $this->setExpectedException(TaskHandlerNotExistsException::class);
34
35
        $taskHandlerFactory = new TaskHandlerFactory([TestHandler::class => new TestHandler()]);
36
37
        $taskHandlerFactory->create(\stdClass::class);
38
    }
39
40
    public function testCreateNoHandler()
41
    {
42
        $this->setExpectedException(TaskHandlerNotExistsException::class);
43
44
        $taskHandlerFactory = new TaskHandlerFactory([]);
45
46
        $taskHandlerFactory->create(\stdClass::class);
47
    }
48
}
49
50
class TestHandler implements TaskHandlerInterface
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
51
{
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function handle($workload)
56
    {
57
        return strrev($workload);
58
    }
59
}
60