Passed
Push — master ( be6e91...b708f5 )
by Joël
03:06 queued 14s
created

LibraryTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 2

8 Methods

Rating   Name   Duplication   Size   Complexity  
A _regex() 0 7 2
A testCatalogCodeset() 0 5 1
A testLocaleDir() 0 5 1
A testTextDomain() 0 5 1
A testLocale() 0 5 1
A testEnvironmentLanguage() 0 5 1
A testFileExists() 0 5 1
A _library() 0 17 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 7 and the first side effect is on line 4.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace CodeIgniterGetText\Tests;
3
4
require_once('include/gettext_test_functions.php');
5
require_once('include/gettext_test_constants.php');
6
7
class LibraryTest extends \PHPUnit_Framework_TestCase
8
{
9
10
    private function _regex($expression, $successful = TRUE)
11
    {
12
        $log = ($successful ? 'info' : 'debug');
13
        $regex = '/(' . $log . '|).*(' . $expression . ')/';
14
15
        return ($regex);
16
    }
17
18
    public function testCatalogCodeset()
19
    {
20
        $this->expectOutputRegex($this->_regex('bind text domain code set'));
21
        $this->_library();
22
    }
23
24
    public function testLocaleDir()
25
    {
26
        $this->expectOutputRegex($this->_regex('bind text domain directory'));
27
        $this->_library();
28
    }
29
30
    public function testTextDomain()
31
    {
32
        $this->expectOutputRegex($this->_regex('set text domain'));
33
        $this->_library();
34
    }
35
36
    public function testLocale()
37
    {
38
        $this->expectOutputRegex($this->_regex('set locale'));
39
        $this->_library();
40
    }
41
42
    public function testEnvironmentLanguage()
43
    {
44
        $this->expectOutputRegex($this->_regex('set environment language'));
45
        $this->_library();
46
    }
47
48
    public function testFileExists()
49
    {
50
        $this->expectOutputRegex($this->_regex('check MO file exists'));
51
        $this->_library();
52
    }
53
54
    private function _library()
55
    {
56
        $config = array();
57
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
        $config = array(
59
            'gettext_locale_dir' => $CI->config->item('gettext_locale_dir'),
60
            'gettext_text_domain' => $CI->config->item('gettext_text_domain'),
61
            'gettext_catalog_codeset' => $CI->config->item('gettext_catalog_codeset'),
62
            'gettext_locale' => $CI->config->item('gettext_locale')
63
        );
64
        */
65
66
        // Load default config array
67
        require(realpath(dirname(__FILE__) . '/../') . '/src/config/gettext.php');
68
69
        \Gettext::init($config);
70
    }
71
72
}
73