Completed
Push — master ( ef5eaa...6d70d2 )
by Lars
03:21 queued 30s
created

ConfigTest53   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 29.41 %

Coupling/Cohesion

Components 0
Dependencies 3
Metric Value
wmc 3
lcom 0
cbo 3
dl 10
loc 34
rs 10

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
use idiorm\orm\ORM;
4
5
class ConfigTest53 extends PHPUnit_Framework_TestCase {
6
7
    public function setUp() {
8
        // Enable logging
9
        ORM::configure('logging', true);
10
11
        // Set up the dummy database connection
12
        $db = new MockPDO('sqlite::memory:');
13
        ORM::set_db($db);
14
15
        ORM::configure('id_column', 'primary_key');
16
    }
17
18
    public function tearDown() {
19
        ORM::configure('logging', false);
20
        ORM::set_db(null);
21
22
        ORM::configure('id_column', 'id');
23
    }
24
25
    public function testLoggerCallback() {
26
        ORM::configure('logger', function($log_string) {
27
            return $log_string;
28
        });
29
        $function = ORM::get_config('logger');
30
        $this->assertTrue(is_callable($function));
31
32
        $log_string = "UPDATE `widget` SET `added` = NOW() WHERE `id` = '1'";
33
        $this->assertEquals($log_string, $function($log_string));
34
35
        ORM::configure('logger', null);
36
    }
37
38
}