Completed
Push — master ( 7ef82a...af1ef9 )
by Ankit
37:21 queued 32:47
created

TestReply::test_EmptyDB()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 16
nc 1
nop 0
dl 0
loc 19
rs 9.4285
c 0
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 15 and the first side effect is on line 11.

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\Search;
7
use ChatApp\Reply;
8
use ChatApp\Session;
9
10
use Dotenv\Dotenv;
11
$dotenv = new Dotenv(dirname(__DIR__));
12
$dotenv->load();
13
session_start();
14
15
class TestReply
16
extends
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
17
    PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style introduced by
Expected 1 space before "PHPUnit_Framework_TestCase"; 4 found
Loading history...
18
{
19
20
    protected $obRegister;
21
    protected $obCompose;
22
    protected $obReply;
23
24
    public function setUp()
25
    {
26
        $this->obRegister = new Register();
27
    }
28
29
30
    public function test_authRegister()
31
    {
32
33
        $output = $this->obRegister->authRegister(
34
            [
35
                "name" => 'Test',
36
                "email" => '[email protected]',
37
                "username" => 'test',
38
                "mob" => '1234567890',
39
                "passRegister" => 'testing'
40
            ]
41
        );
42
        $output = (array)json_decode($output);
43
        $this->assertEquals([
44
            'location' => 'http://127.0.0.1/openchat/views/account.php'
45
            ], $output);
46
        $userId = Session::get('start');
47
        return $userId;
48
    }
49
50
    /**
51
    * @depends test_authRegister
52
    *  Testing for the register with empty username
53
    */
54
    public function test_authRegister2($userId)
55
    {
56
        $msg = [
57
            "name" => $userId,
58
            "reply" => [
59
                0 => "Hello World"
60
            ]
61
        ];
62
63
        $msg = json_encode($msg);
64
65
        $expectedOutput = [
0 ignored issues
show
Unused Code introduced by
$expectedOutput is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
            "Compose" => [
67
                "0" => (object)[
68
                    "login_id" => "1",
69
                    "name" => "Test",
70
                    "email" => "[email protected]",
71
                    "username" => "test",
72
                    "mobile" => "1234567890",
73
                    "login_status" => "0"
74
                ]
75
            ]
76
        ];
77
78
        $output = $this->obRegister->authRegister(
79
            [
80
                "name" => 'Test2',
81
                "email" => '[email protected]',
82
                "username" => 'test2',
83
                "mob" => '1234567890',
84
                "passRegister" => 'testing'
85
            ]
86
        );
87
88
        $output = (array)json_decode($output);
89
        $this->assertEquals([
90
            'location' => 'http://127.0.0.1/openchat/views/account.php'
91
            ], $output);
92
93
        $sessionId = session_id();
94
        $search = new Reply($sessionId);
95
96
        $output = $search->replyTo($msg);
97
        $this->assertEquals("Messages is sent", $output);
98
99
        $output = $search->replyTo(json_encode([]));
100
        $this->assertEquals("Failed", $output);
101
102
        $output = $search->replyTo(json_encode([
103
            "name" => -1,
104
            "reply" => [
105
                0 => "Hello World"
106
            ]
107
        ]));
108
        $this->assertEquals("Invalid Authentication", $output);
109
110
        $output = $search->replyTo(json_encode([
111
            "name" => $userId,
112
            "reply" => [
113
                0 => "Hello"
114
            ]
115
        ]));
116
        $this->assertEquals("Messages is sent", $output);
117
118
        // For suggestion matched but not in total messages
119
        // $output = $search->replyTo((object)["value" => "T"]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
120
        // $output = (array)json_decode($output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
121
        // $this->assertEquals(["Search" => "Not Found"], $output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
122
123
        // // Not Found
124
        // $output = $search->replyTo((object)["value" => ""]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
125
        // $output = (array)json_decode($output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
126
        // $this->assertEquals(["Search" => "Not Found"], $output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
127
128
        // // Query Failed
129
        // $output = $search->replyTo((object)["value" => "'"]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% 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...
130
        // $output = (array)json_decode($output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% 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...
131
        // $this->assertEquals(["Search" => "Not Found"], $output);
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% 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...
132
133
    }
134
135
    /**
136
    *   @depends test_authRegister2
137
    *  Empty the DB
138
    */
139
    public function test_EmptyDB()
140
    {
141
        $connect = mysqli_connect(
142
            getenv('DB_HOST'),
143
            getenv('DB_USER'),
144
            getenv('DB_PASSWORD'),
145
            getenv('DB_NAME')
146
        );
147
        $query = "TRUNCATE `login`";
148
        $this->assertTrue($connect->query($query));
149
        $query = "TRUNCATE `profile`";
150
        $this->assertTrue($connect->query($query));
151
        $query = "TRUNCATE `messages`";
152
        $this->assertTrue($connect->query($query));
153
        $query = "TRUNCATE `total_message`";
154
        $this->assertTrue($connect->query($query));
155
        $query = "TRUNCATE `register`";
156
        $this->assertTrue($connect->query($query));
157
    }
158
159
}
160