FormatterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddOrRemoveS() 0 6 1
A testGenerateUnnamedPlaceholders() 0 5 1
A testTokenize() 0 4 1
A testMakeAssociativeArray() 0 4 1
1
<?php
2
3
/**
4
 * @package A simple ORM that performs basic CRUD operations
5
 * @author Surajudeen AKANDE <[email protected]>
6
 * @license MIT <https://opensource.org/licenses/MIT>
7
 * @link http://www.github.com/andela-sakande
8
 * */
9
namespace Sirolad\Test;
10
11
use Sirolad\Libraries\Formatter;
12
13
/**
14
 * Test for Formatter class
15
 **/
16
class FormatterTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * Test for singularize or pluralize
20
     * */
21
    public function testAddOrRemoveS()
22
    {
23
        $this->assertEquals('user', Formatter::addOrRemoveS('users'));
24
        $this->assertEquals('cars', Formatter::addOrRemoveS('car'));
25
        $this->assertNotEquals('cars', Formatter::addOrRemoveS('cars'));
26
    }
27
28
    /**
29
     * Test for SQL query placeholders
30
     **/
31
    public function testGenerateUnnamedPlaceholders()
32
    {
33
        $this->assertEquals(['?', '?', '?', '?'], Formatter::generateUnnamedPlaceholders(['username', 'password', 'email', 'date_created']));
34
        $this->assertNotEquals(['?', '?', '?', '?'], Formatter::generateUnnamedPlaceholders(['username', 'password', 'email']));
35
    }
36
37
    /**
38
     * Test to tokenize values of SQL query
39
     * */
40
    public function testTokenize()
41
    {
42
        $this->assertEquals('username,password,email', Formatter::tokenize('username,password,email', ','));
43
    }
44
45
    /**
46
     * Test that SQL query is used associatively
47
     * */
48
    public function testMakeAssociativeArray()
49
    {
50
        $this->assertEquals(["token=NULL", 'token_expire="today"'], Formatter::makeAssociativeArray(['' => '', 'token' => null, 'token_expire' => 'today']));
51
    }
52
}
53