testGetBucketOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace WebPTTest\ZendCouchbaseModule;
4
5
use WebPT\ZendCouchbaseModule\AbstractCouchbaseBucketFactory;
6
use WebPT\ZendCouchbaseModule\BucketOptions;
7
use WebPT\ZendCouchbaseModule\ClusterOptions;
8
use WebPT\ZendCouchbaseModule\Module;
9
use Zend\Mvc\Service\ServiceManagerConfig;
10
use Zend\ServiceManager\ServiceLocatorInterface;
11
use Zend\ServiceManager\ServiceManager;
12
13
/**
14
 * @covers \WebPT\ZendCouchbaseModule\AbstractCouchbaseBucketFactory
15
 */
16
class AbstractCouchbaseBucketFactoryTest extends \PHPUnit_Framework_TestCase
17
{
18
    /** @var ServiceLocatorInterface */
19
    private $serviceLocator;
20
    
21
    protected function setUp()
22
    {
23
        $config = (new Module())->getConfig();
24
    
25
        $serviceManager = new ServiceManager();
26
        
27
        (new ServiceManagerConfig(\igorw\get_in($config, ['service_manager'], [])))
0 ignored issues
show
Bug introduced by
It seems like $config defined by (new \WebPT\ZendCouchbas...\Module())->getConfig() on line 23 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...
28
            ->configureServiceManager($serviceManager);
29
        
30
        $serviceManager->setService('config', $config);
31
        
32
        $this->serviceLocator = $serviceManager;
33
    }
34
    
35
    /**
36
     * @group integration
37
     */
38
    public function testCreateService()
39
    {
40
        $bucket = $this->serviceLocator->get('couchbase.localhost.default');
41
42
        self::assertInstanceOf(\CouchbaseBucket::class, $bucket);
43
    }
44
    
45
    public function testCanCreateFromRequestedName()
46
    {
47
        $name = 'FooBar';
48
        $requestedName = 'couchbase.localhost.default';
49
    
50
        $canCreate = (new AbstractCouchbaseBucketFactory())->canCreateServiceWithName(
51
            new ServiceManager(),
52
            $name,
53
            $requestedName
54
        );
55
    
56
        self::assertTrue($canCreate);
57
    }
58
    
59
    /**
60
     * @return array
61
     */
62
    public function testGetModuleConfig()
63
    {
64
        $moduleConfig = (new AbstractCouchbaseBucketFactory())->getModuleConfig($this->serviceLocator);
65
        self::assertInternalType('array', $moduleConfig);
66
        
67
        return $moduleConfig;
68
    }
69
    
70
    /**
71
     * @return BucketOptions
72
     */
73
    public function testGetBucketOptions()
74
    {
75
        $moduleConfig = $this->testGetModuleConfig();
76
        
77
        $bucketOptions = (new AbstractCouchbaseBucketFactory())->getBucketOptions($moduleConfig, 'default');
78
        self::assertInstanceOf(BucketOptions::class, $bucketOptions);
79
        
80
        return $bucketOptions;
81
    }
82
    
83
    /**
84
     * @return ClusterOptions
85
     */
86
    public function testGetClusterOptions()
87
    {
88
        $moduleConfig = $this->testGetModuleConfig();
89
        
90
        $clusterOptions = (new AbstractCouchbaseBucketFactory())->getClusterOptions($moduleConfig, 'localhost');
91
        
92
        self::assertInstanceOf(ClusterOptions::class, $clusterOptions);
93
        
94
        return $clusterOptions;
95
    }
96
    
97
    /**
98
     * @group integration
99
     */
100
    public function testCreateCouchbaseCluster()
101
    {
102
        $clusterOptions = $this->testGetClusterOptions();
103
        
104
        $cluster = (new AbstractCouchbaseBucketFactory())->createCouchbaseCluster($clusterOptions);
105
        
106
        self::assertInstanceOf(\CouchbaseCluster::class, $cluster);
107
        
108
        return $cluster;
109
    }
110
    
111
    /**
112
     * @group integration
113
     */
114
    public function testCreateCouchbaseBucket()
115
    {
116
        $cluster = $this->testCreateCouchbaseCluster();
117
    
118
        $bucketOptions = $this->testGetBucketOptions();
119
        
120
        $bucket = (new AbstractCouchbaseBucketFactory())->createCouchbaseBucket($cluster, $bucketOptions);
121
        
122
        self::assertInstanceOf(\CouchbaseBucket::class, $bucket);
123
    }
124
}
125