GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

FilterManagerTest   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 6

Importance

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

8 Methods

Rating   Name   Duplication   Size   Complexity  
A SetUp() 0 7 1
A testFilterNotFoundException() 0 9 1
A testExceptionWithNoFilterType() 0 11 1
A testExceptionWithNoFilterOptions() 0 11 1
A testGetFilterOptions() 0 11 1
A testGetFilter() 0 16 1
A testAddFilter() 0 11 1
A testApplyFilter() 0 22 1
1
<?php
2
3
namespace HtImgModuleTest\Imagine\Filter;
4
5
use HtImgModule\Options\ModuleOptions;
6
use HtImgModule\Imagine\Filter\FilterManager;
7
use Zend\ServiceManager\ServiceManager;
8
9
class FilterManagerTest extends \PHPUnit_Framework_TestCase
10
{
11
    protected $filterManager;
12
13
    public function SetUp()
14
    {
15
        $this->filterManager = new FilterManager(
16
            new ModuleOptions,
17
            new ServiceManager
18
        );
19
    }
20
21
    public function testFilterNotFoundException()
22
    {
23
        $filterManager = new FilterManager(
24
            new ModuleOptions,
25
            new ServiceManager
26
        );
27
        $this->setExpectedException('HtImgModule\Exception\FilterNotFoundException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
28
        $filterManager->getFilter('not_available');
29
    }
30
31
    public function testExceptionWithNoFilterType()
32
    {
33
        $options = new ModuleOptions;
34
        $filterManager = new FilterManager(
35
            $options,
36
            new ServiceManager
37
        );
38
        $options->addFilter('hello', ['options' => 'hello']);
39
        $this->setExpectedException('HtImgModule\Exception\InvalidArgumentException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
40
        $filterManager->getFilter('hello');
41
    }
42
43
    public function testExceptionWithNoFilterOptions()
44
    {
45
        $options = new ModuleOptions;
46
        $filterManager = new FilterManager(
47
            $options,
48
            new ServiceManager
49
        );
50
        $options->addFilter('hello', ['type' => 'hello']);
51
        $this->setExpectedException('HtImgModule\Exception\InvalidArgumentException');
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::setExpectedException() has been deprecated with message: Method deprecated since Release 5.2.0; use expectException() instead

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
52
        $filterManager->getFilter('hello');
53
    }
54
55
    public function testGetFilterOptions()
56
    {
57
        $options = new ModuleOptions;
58
        $filterManager = new FilterManager(
59
            $options,
60
            new ServiceManager
61
        );
62
        $options->addFilter('filter_name', ['type' => 'hello', 'options' => ['key' => 'value']]);
63
        $filterOptions = $filterManager->getFilterOptions('filter_name');
64
        $this->assertEquals(['key' => 'value'], $filterOptions);
65
    }
66
67
    public function testGetFilter()
68
    {
69
        $options = new ModuleOptions;
70
        $filterLoaders = new ServiceManager;
71
        $loader = $this->createMock('HtImgModule\Imagine\Filter\Loader\LoaderInterface');
72
        $loader->expects($this->any())
73
            ->method('load')
74
            ->will($this->returnValue('sample_loader'));
75
        $filterLoaders->setService('hello123', $loader);
76
        $filterManager = new FilterManager(
77
            $options,
78
            $filterLoaders
79
        );
80
        $options->addFilter('filter_name', ['type' => 'hello123', 'options' => ['key' => 'value']]);
81
        $this->assertEquals('sample_loader', $filterManager->getFilter('filter_name'));
82
    }
83
84
    public function testAddFilter()
85
    {
86
        $options = new ModuleOptions;
87
        $filterLoaders = new ServiceManager;
88
        $filterManager = new FilterManager(
89
            $options,
90
            $filterLoaders
91
        );
92
        $filterManager->addFilter('foo_filter', ['foo3' => 'bar3']);
93
        $this->assertEquals( ['foo3' => 'bar3'], $options->getFilters()['foo_filter']);
94
    }
95
96
    /**
97
     * @covers HtImgModule\Imagine\Filter\FilterManager::applyFilter
98
     */
99
    public function testApplyFilter()
100
    {
101
        $options = new ModuleOptions;
102
        $filterLoaders = new ServiceManager;
103
        $loader = $this->createMock('HtImgModule\Imagine\Filter\Loader\LoaderInterface');
104
        $filter = $this->createMock('Imagine\Filter\FilterInterface');
105
        $image = $this->createMock('Imagine\Image\ImageInterface');
106
        $filteredImage = $this->createMock('Imagine\Image\ImageInterface');
107
        $loader->expects($this->any())
108
            ->method('load')
109
            ->will($this->returnValue($filter));
110
        $filter->expects($this->once())
111
            ->method('apply')
112
            ->will($this->returnValue($filteredImage));
113
        $filterLoaders->setService('bar_filter', $loader);
114
        $filterManager = new FilterManager(
115
            $options,
116
            $filterLoaders
117
        );
118
        $options->addFilter('bar_filter', ['type' => 'bar_filter', 'options' => ['key' => 'value']]);
119
        $this->assertEquals($filteredImage, $filterManager->applyFilter($image, 'bar_filter'));
120
    }
121
}
122