Skip to content

Commit 179bc3a

Browse files
committed
Added tests for postres storage.
1 parent 77342c5 commit 179bc3a

File tree

6 files changed

+88
-3
lines changed

6 files changed

+88
-3
lines changed

tests/codeception.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,13 @@ settings:
99
colors: true
1010
suite_class: \PHPUnit_Framework_TestSuite
1111
memory_limit: 1024M
12-
log: true
12+
log: true
13+
modules:
14+
config:
15+
Db:
16+
dsn: 'mysql:host=localhost;dbname=wschat_tests'
17+
# dsn: 'pgsql:host=localhost;dbname=wschat_tests'
18+
user: ''
19+
password: ''
20+
dump: codeception/_data/pgsql.sql
21+
# dump: codeception/_data/mysql.sql

tests/codeception/_data/mysql.sql

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
DROP TABLE IF EXISTS history;
2+
3+
CREATE TABLE history(
4+
id UNSIGNED INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
5+
chat_id VARCHAR(60),
6+
chat_title VARCHAR(60),
7+
user_id VARCHAR(60),
8+
username VARCHAR(60),
9+
avatar_16 VARCHAR(90),
10+
avatar_32 VARCHAR(90),
11+
timestamp UNSIGNED INTEGER NOT NULL DEFAULT 0,
12+
message TEXT
13+
);

tests/codeception/_data/pgsql.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
DROP TABLE IF EXISTS history CASCADE;
2+
3+
CREATE TABLE history(
4+
id SERIAL,
5+
chat_id CHARACTER VARYING(60),
6+
chat_name CHARACTER VARYING(60),
7+
user_id CHARACTER VARYING(60),
8+
username CHARACTER VARYING(60),
9+
avatar_16 CHARACTER VARYING(90),
10+
avatar_32 CHARACTER VARYING(90),
11+
timestamp INTEGER NOT NULL,
12+
message TEXT
13+
);
14+
15+
ALTER TABLE history ADD PRIMARY KEY(id);

tests/codeception/config/unit.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
'mongodb' => [
1010
'class' => '\yii\mongodb\Connection',
1111
'dsn' => 'mongodb://localhost:27017/wschat-tests'
12-
]
12+
],
13+
'db' => [
14+
'class' => 'yii\db\Connection',
15+
'dsn' => 'pgsql:host=localhost;dbname=wschat_tests',
16+
// 'dsn' => 'mysql:host=localhost;dbname=wschat_tests',
17+
'username' => '',
18+
'password' => '',
19+
'charset' => 'utf8',
20+
],
1321
],
1422
];
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace tests\codeception\unit;
3+
4+
use yii\codeception\TestCase;
5+
use jones\wschat\components\AbstractStorage;
6+
7+
class PgsqlStorageTest extends TestCase
8+
{
9+
protected $params = [
10+
'chat_id' => 1,
11+
'chat_title' => 'Pgsql chat room',
12+
'user_id' => 1,
13+
'username' => 'Pgsql user',
14+
'avatar_16' => null,
15+
'avatar_32' => null,
16+
'message' => 'Simple text message',
17+
'timestamp' => 0
18+
];
19+
20+
/**
21+
* @covers \jones\wschat\components\DbStorage::storeMessage
22+
*/
23+
public function testStoreMessage()
24+
{
25+
AbstractStorage::factory('pgsql')->storeMessage($this->params);
26+
}
27+
28+
/**
29+
* @depends testStoreMessage
30+
* @covers \jones\wschat\components\DbStorage::getHistory
31+
*/
32+
public function testGetHistory()
33+
{
34+
$data = AbstractStorage::factory('pgsql')->getHistory($this->params['chat_id']);
35+
$this->assertNotEmpty($data);
36+
$this->assertEquals(1, sizeof($data), 'Only one message should be in history table');
37+
$this->assertEquals($this->params['message'], $data[0]['message']);
38+
}
39+
40+
}

tests/codeception/unit/UnitTester.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php //[STAMP] fdf172ba8533e948a77c75f941094bf8
1+
<?php //[STAMP] 28423caeac2888a162c4d002b6d0c560
22

33
// This class was automatically generated by build task
44
// You should not change it manually as it will be overwritten on next build

0 commit comments

Comments
 (0)