DbTest4DisConnect   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 142
Duplicated Lines 54.23 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 4
Bugs 3 Features 2
Metric Value
wmc 13
c 4
b 3
f 2
lcom 0
cbo 1
dl 77
loc 142
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getDataSet() 0 4 1
A testPreCondition() 0 4 1
C setUp() 22 22 7
A getConnection() 7 7 1
A test_DisConnect() 16 16 1
A test_DisConnect_with_force() 16 16 1
A test_DisConnect_without_force() 16 16 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * DbTest4DisConnect
4
 *
5
 * Db::disConnect()用テストケース
6
 *
7
 * @package           risoluto
8
 * @author            Risoluto Developers
9
 * @license           http://opensource.org/licenses/bsd-license.php new BSD license
10
 * @copyright     (C) 2008-2015 Risoluto Developers / All Rights Reserved.
11
 */
12
13
//------------------------------------------------------//
14
// 名前空間の定義
15
//------------------------------------------------------//
16
namespace Risoluto;
17
18
//------------------------------------------------------//
19
// テストクラス定義
20
//------------------------------------------------------//
21
class DbTest4DisConnect extends \PHPUnit_Extensions_Database_TestCase
22
{
23
    //------------------------------------------------------//
24
    // テストクラス変数定義
25
    //------------------------------------------------------//
26
    /**
27
     * $instance
28
     * @access protected
29
     * @var    object    テスト対象インスタンスを保持
30
     */
31
    protected $instance;
32
33
    //------------------------------------------------------//
34
    // テストメソッド定義
35
    //------------------------------------------------------//
36
    /**
37
     * setUp()
38
     *
39
     * テストに必要な準備を実施
40
     */
41 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
    {
43
        // 拡張モジュールがロードされているかをチェック
44
        if (!extension_loaded( 'mysqli' )) {
45
            $this->markTestSkipped( 'Cannot use mysqli expansion module.' );
46
        }
47
48
        if (!isset( $GLOBALS[ 'DB_DRIVER' ] )) {
49
            $this->markTestSkipped( 'DB_DRIVER was not defined. Check phpunit.xml' );
50
        } elseif (!isset( $GLOBALS[ 'DB_USER' ] )) {
51
            $this->markTestSkipped( 'DB_USER was not defined. Check phpunit.xml' );
52
        } elseif (!isset( $GLOBALS[ 'DB_PASSWORD' ] )) {
53
            $this->markTestSkipped( 'DB_PASSWORD was not defined. Check phpunit.xml' );
54
        } elseif (!isset( $GLOBALS[ 'DB_DBNAME' ] )) {
55
            $this->markTestSkipped( 'DB_DBNAME was not defined. Check phpunit.xml' );
56
        } elseif (!isset( $GLOBALS[ 'DB_HOST' ] )) {
57
            $this->markTestSkipped( 'DB_HOST was not defined. Check phpunit.xml' );
58
        }
59
60
        // DB周りの初期化を行う為に元々のsetUp()をコールする
61
        parent::setUp();
62
    }
63
64
    /**
65
     * getConnection()
66
     *
67
     * DBテストに必要な接続を実施
68
     */
69 View Code Duplication
    public function getConnection()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $dsn = $GLOBALS[ 'DB_DRIVER' ] . ':dbname=' . $GLOBALS[ 'DB_DBNAME' ] . ';host=' . $GLOBALS[ 'DB_HOST' ];
72
        $pdo = new \PDO( $dsn, $GLOBALS[ 'DB_USER' ], $GLOBALS[ 'DB_PASSWORD' ] );
73
74
        return $this->createDefaultDBConnection( $pdo, $GLOBALS[ 'DB_DBNAME' ] );
75
    }
76
77
    /**
78
     * getDataSet()
79
     *
80
     * DBテストに必要なデータセットを実施
81
     */
82
    public function getDataSet()
83
    {
84
        return $this->createXMLDataSet( dirname( __FILE__ ) . '/../../../risoluto_db_test.xml' );
85
    }
86
87
    /**
88
     * testPreCondition()
89
     *
90
     * テスト開始前に前提条件をチェックする
91
     */
92
    public function testPreCondition()
93
    {
94
        $this->assertEquals( 2, $this->getConnection()->getRowCount( 'risoluto_db_test' ) );
95
    }
96
97
    /**
98
     * test_DisConnect()
99
     *
100
     * disConnect()のテスト(force未設定時)
101
     */
102 View Code Duplication
    public function test_DisConnect()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        $params = [
105
            "driver" => $GLOBALS[ 'DB_DRIVER' ],
106
            "user" => $GLOBALS[ 'DB_USER' ],
107
            "pass" => $GLOBALS[ 'DB_PASSWORD' ],
108
            "dbname" => $GLOBALS[ 'DB_DBNAME' ],
109
            "host" => $GLOBALS[ 'DB_HOST' ],
110
            "persistent" => false,
111
        ];
112
113
        $instance = new Db;
114
        $instance->connect( $params );
115
        $this->assertTrue( $instance->disConnect() );
116
        unset( $instance );
117
    }
118
119
    /**
120
     * test_DisConnect_with_force()
121
     *
122
     * disConnect()のテスト(force = true時)
123
     */
124 View Code Duplication
    public function test_DisConnect_with_force()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
125
    {
126
        $params = [
127
            "driver" => $GLOBALS[ 'DB_DRIVER' ],
128
            "user" => $GLOBALS[ 'DB_USER' ],
129
            "pass" => $GLOBALS[ 'DB_PASSWORD' ],
130
            "dbname" => $GLOBALS[ 'DB_DBNAME' ],
131
            "host" => $GLOBALS[ 'DB_HOST' ],
132
            "persistent" => false,
133
        ];
134
135
        $instance = new Db;
136
        $instance->connect( $params );
137
        $this->assertTrue( $instance->disConnect( true ) );
138
        unset( $instance );
139
    }
140
141
    /**
142
     * test_DisConnect_without_force()
143
     *
144
     * disConnect()のテスト(force = false時)
145
     */
146 View Code Duplication
    public function test_DisConnect_without_force()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
147
    {
148
        $params = [
149
            "driver" => $GLOBALS[ 'DB_DRIVER' ],
150
            "user" => $GLOBALS[ 'DB_USER' ],
151
            "pass" => $GLOBALS[ 'DB_PASSWORD' ],
152
            "dbname" => $GLOBALS[ 'DB_DBNAME' ],
153
            "host" => $GLOBALS[ 'DB_HOST' ],
154
            "persistent" => false,
155
        ];
156
157
        $instance = new Db;
158
        $instance->connect( $params );
159
        $this->assertTrue( $instance->disConnect( false ) );
160
        unset( $instance );
161
    }
162
}
163