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

TestSearch::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 14 and the first side effect is on line 10.

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