Completed
Push — master ( 2e7ca6...665d5a )
by Ankit
03:17
created

TestCompose::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 4
loc 4
rs 10
c 1
b 0
f 0
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 11 and the first side effect is on line 9.

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
3
namespace ChatApp\Tests;
4
use PHPUnit_Framework_TestCase;
5
use ChatApp\Register;
6
use ChatApp\Compose;
7
use ChatApp\Session;
8
9
session_start();
10
11 View Code Duplication
class TestCompose
0 ignored issues
show
Duplication introduced by
This class 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...
12
extends
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
13
    PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "PHPUnit_Framework_TestCase"; 4 found
Loading history...
14
{
15
16
    protected $obRegister;
17
    protected $obCompose;
18
19
20
    public function setUp()
21
    {
22
        $this->obRegister = new Register();
23
    }
24
25
26
    public function test_authRegister()
27
    {
28
29
        $output = $this->obRegister->authRegister(
30
            [
31
                "name" => 'Test',
32
                "email" => '[email protected]',
33
                "username" => 'test',
34
                "mob" => '1234567890',
35
                "passRegister" => 'testing'
36
            ]
37
        );
38
        $output = (array)json_decode($output);
39
        $this->assertEquals([
40
            'location' => 'http://127.0.0.1/openchat/views/account.php'
41
            ], $output);
42
        $sessionId = session_id();
43
        return $sessionId;
44
    }
45
46
    /**
47
    * @depends test_authRegister
48
    *  Testing for the register with empty username
49
    */
50
    public function test_authRegister2($sessionId)
51
    {
52
        $expectedOutput = [
53
            "Compose" => [
54
                "0" => (object)[
55
                    "login_id" => "1",
56
                    "name" => "Test",
57
                    "email" => "[email protected]",
58
                    "username" => "test",
59
                    "mobile" => "1234567890",
60
                    "login_status" => "0"
61
                ]
62
            ]
63
        ];
64
65
        $output = $this->obRegister->authRegister(
66
            [
67
                "name" => 'Test2',
68
                "email" => '[email protected]',
69
                "username" => 'test2',
70
                "mob" => '1234567890',
71
                "passRegister" => 'testing'
72
            ]
73
        );
74
        $output = (array)json_decode($output);
75
        $this->assertEquals([
76
            'location' => 'http://127.0.0.1/openchat/views/account.php'
77
            ], $output);
78
        $compose = new Compose($sessionId);
79
80
        // Matched not found
81
        $output = $compose->selectUser((object)["value" => "ank"]);
82
        $output = (array)json_decode($output);
83
        $this->assertEquals(["Compose" => "Not Found"], $output);
84
85
        // For suggestion matched
86
        $output = $compose->selectUser((object)["value" => "t"]);
87
        $output = (array)json_decode($output);
88
        $this->assertEquals($expectedOutput, $output);
89
90
        // Not Found
91
        $output = $compose->selectUser((object)["value" => ""]);
92
        $output = (array)json_decode($output);
93
        $this->assertEquals(["Compose" => "Not Found"], $output);
94
95
        // Query Failed
96
        $output = $compose->selectUser((object)["value" => "'"]);
97
        $output = (array)json_decode($output);
98
        $this->assertEquals(["Compose" => "Query Failed"], $output);
99
100
    }
101
102
    /**
103
    *   @depends test_authRegister
104
    *  Empty the DB
105
    */
106
    public function test_EmptyDB()
107
    {
108
        $connect = mysqli_connect(
109
            getenv('DB_HOST'),
110
            getenv('DB_USER'),
111
            getenv('DB_PASSWORD'),
112
            getenv('DB_NAME')
113
        );
114
        $query = "TRUNCATE `login`";
115
        $this->assertTrue($connect->query($query));
116
        $query = "TRUNCATE `profile`";
117
        $this->assertTrue($connect->query($query));
118
        $query = "TRUNCATE `register`";
119
        $this->assertTrue($connect->query($query));
120
    }
121
122
}
123