TransformerPluginManagerTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B testCreateTransformerViaModuleConfig() 0 26 1
1
<?php
2
3
namespace AbacaphiliacTest\Zend\Transformer\PluginManager;
4
5
use Abacaphiliac\Zend\Transformer\Module;
6
use Abacaphiliac\Zend\Transformer\PluginManager\TransformerPluginManager;
7
use Abacaphiliac\Zend\Transformer\TransformerInterface;
8
use AbacaphiliacTest\FizBuz;
9
use AbacaphiliacTest\FooBar;
10
use Zend\Mvc\Service\ServiceManagerConfig;
11
use Zend\ServiceManager\ServiceManager;
12
13
/**
14
 * @covers \Abacaphiliac\Zend\Transformer\PluginManager\TransformerPluginManager
15
 */
16
class TransformerPluginManagerTest extends \PHPUnit_Framework_TestCase
17
{
18
    public function testCreateTransformerViaModuleConfig()
19
    {
20
        $module = new Module();
21
        $config = $module->getConfig();
22
        
23
        $config['abacaphiliac/zend-transformer']['transformers']['FooBarToFizBuz'] = [
24
            'inputClass' => FooBar::class,
25
            'keyMap' => [
26
                'foo' => 'fiz',
27
                'bar' => 'buz',
28
            ],
29
            'outputClass' => FizBuz::class,
30
        ];
31
        
32
        $serviceManagerConfig = new ServiceManagerConfig(\igorw\get_in($config, ['service_manager'], []));
0 ignored issues
show
Bug introduced by
It seems like $config defined by $module->getConfig() on line 21 can also be of type object<Traversable>; however, igorw\get_in() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
33
        
34
        $container = new ServiceManager();
35
        $serviceManagerConfig->configureServiceManager($container);
36
        $container->setService('config', $config);
37
    
38
        $transformers = $container->get('TransformerManager');
39
        self::assertInstanceOf(TransformerPluginManager::class, $transformers);
40
    
41
        $transformer = $transformers->get('FooBarToFizBuz');
42
        self::assertInstanceOf(TransformerInterface::class, $transformer);
43
    }
44
}
45