a tiny mvc framework for php using php-activerecord
1<?php
2use ActiveRecord\Connection;
3
4include 'helpers/config.php';
5
6// Only use this to test static methods in Connection that are not specific
7// to any database adapter.
8
9class ConnectionTest extends SnakeCase_PHPUnit_Framework_TestCase
10{
11 /**
12 * @expectedException ActiveRecord\DatabaseException
13 */
14 public function test_connection_info_from_should_throw_exception_when_no_host()
15 {
16 ActiveRecord\Connection::parse_connection_url('mysql://user:pass@');
17 }
18
19 public function test_connection_info()
20 {
21 $info = ActiveRecord\Connection::parse_connection_url('mysql://user:pass@127.0.0.1:3306/dbname');
22 $this->assert_equals('mysql',$info->protocol);
23 $this->assert_equals('user',$info->user);
24 $this->assert_equals('pass',$info->pass);
25 $this->assert_equals('127.0.0.1',$info->host);
26 $this->assert_equals(3306,$info->port);
27 $this->assert_equals('dbname',$info->db);
28 }
29
30 public function test_gh_103_sqlite_connection_string_relative()
31 {
32 $info = ActiveRecord\Connection::parse_connection_url('sqlite://../some/path/to/file.db');
33 $this->assert_equals('../some/path/to/file.db', $info->host);
34 }
35
36 /**
37 * @expectedException ActiveRecord\DatabaseException
38 */
39 public function test_gh_103_sqlite_connection_string_absolute()
40 {
41 $info = ActiveRecord\Connection::parse_connection_url('sqlite:///some/path/to/file.db');
42 }
43
44 public function test_gh_103_sqlite_connection_string_unix()
45 {
46 $info = ActiveRecord\Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)');
47 $this->assert_equals('/some/path/to/file.db', $info->host);
48
49 $info = ActiveRecord\Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)/');
50 $this->assert_equals('/some/path/to/file.db', $info->host);
51
52 $info = ActiveRecord\Connection::parse_connection_url('sqlite://unix(/some/path/to/file.db)/dummy');
53 $this->assert_equals('/some/path/to/file.db', $info->host);
54 }
55
56 public function test_gh_103_sqlite_connection_string_windows()
57 {
58 $info = ActiveRecord\Connection::parse_connection_url('sqlite://windows(c%3A/some/path/to/file.db)');
59 $this->assert_equals('c:/some/path/to/file.db', $info->host);
60 }
61
62 public function test_parse_connection_url_with_unix_sockets()
63 {
64 $info = ActiveRecord\Connection::parse_connection_url('mysql://user:password@unix(/tmp/mysql.sock)/database');
65 $this->assert_equals('/tmp/mysql.sock',$info->host);
66 }
67
68 public function test_parse_connection_url_with_decode_option()
69 {
70 $info = ActiveRecord\Connection::parse_connection_url('mysql://h%20az:h%40i@127.0.0.1/test?decode=true');
71 $this->assert_equals('h az',$info->user);
72 $this->assert_equals('h@i',$info->pass);
73 }
74
75 public function test_encoding()
76 {
77 $info = ActiveRecord\Connection::parse_connection_url('mysql://test:test@127.0.0.1/test?charset=utf8');
78 $this->assert_equals('utf8', $info->charset);
79 }
80}
81?>