@@ -22,101 +22,68 @@ protected function tearDown() {
22
22
$ this ->cache_file and unlink ($ this ->cache_file );
23
23
}
24
24
25
+ public function testGet () {
26
+ $ quandl = new Quandl ($ this ->api_key );
27
+ $ r = $ quandl ->get ("datasets/GOOG/NASDAQ_AAPL " , ['rows ' => 5 ]);
28
+
29
+ $ this ->assertEquals ('GOOG ' , $ r ->dataset ->database_code , "TEST get database_code " );
30
+ $ this ->assertEquals (5 , count ($ r ->dataset ->data ), "TEST get data count " );
31
+ }
32
+
25
33
public function testCsv () {
26
34
$ this ->_testGetSymbol ("csv " , 2800 );
27
- $ this ->_testGetSymbol ("csv " , 2800 , true );
28
35
}
29
36
30
37
public function testXml () {
31
38
$ this ->_testGetSymbol ("xml " , 14000 );
32
- $ this ->_testGetSymbol ("xml " , 14000 , true );
33
39
}
34
40
35
41
public function testJson () {
36
42
$ this ->_testGetSymbol ("json " , 4200 );
37
- $ this ->_testGetSymbol ("json " , 4200 , true );
38
43
}
39
44
40
45
public function testObject () {
41
46
$ this ->_testGetSymbol ("object " , 7400 );
42
- $ this ->_testGetSymbol ("object " , 7400 , true );
43
- }
44
-
45
- public function testInvalidUrl () {
46
- $ this ->_testInvalidUrl ();
47
- $ this ->_testInvalidUrl (true );
48
- }
49
-
50
- public function testGetList () {
51
- $ this ->_testGetList ();
52
- $ this ->_testGetList (true );
53
- }
54
-
55
- public function testGetSearch () {
56
- $ this ->_testGetSearch ();
57
- $ this ->_testGetSearch (true );
58
- }
59
-
60
- public function testGetMeta () {
61
- $ this ->_testGetMeta ();
62
- $ this ->_testGetMeta (true );
63
47
}
64
48
65
- public function testCache () {
66
- $ this ->_testCache ();
67
- $ this ->cache_file and unlink ($ this ->cache_file );
68
- $ this ->_testCache (true );
69
- }
70
-
71
- public function cacheHandler ($ action , $ url , $ data =null ) {
72
- $ cache_key = md5 ("quandl: $ url " );
73
- $ cache_file = __DIR__ . "/ $ cache_key " ;
74
-
75
- if ($ action == "get " and file_exists ($ cache_file ))
76
- return file_get_contents ($ cache_file );
77
- else if ($ action == "set " )
78
- file_put_contents ($ cache_file , $ data );
79
-
80
- $ this ->cache_file = $ cache_file ;
81
-
82
- return false ;
49
+ public function testCurl () {
50
+ $ this ->_testGetSymbol ("csv " , 2800 , true );
83
51
}
84
52
85
- private function _testInvalidUrl ( $ force_curl = false ) {
53
+ public function testInvalidUrl ( ) {
86
54
$ quandl = new Quandl ($ this ->api_key , "json " );
87
- $ quandl ->force_curl = $ quandl ->no_ssl_verify = $ force_curl ;
88
55
$ r = $ quandl ->getSymbol ("INVALID/SYMBOL " , $ this ->dates );
89
- $ this ->assertEquals ($ quandl ->error , "Invalid URL " ,
90
- "TEST invalidUrl response " );
56
+ $ this ->assertEquals ($ quandl ->error , "Invalid URL " , "TEST invalidUrl response " );
91
57
}
92
58
93
- private function _testGetList ( $ force_curl = false ) {
59
+ public function testGetList ( ) {
94
60
$ quandl = new Quandl ($ this ->api_key );
95
- $ quandl ->force_curl = $ quandl ->no_ssl_verify = $ force_curl ;
96
61
$ r = $ quandl ->getList ("WIKI " , 1 , 10 );
97
- $ this ->assertEquals (10 , count ($ r ->datasets ),
98
- "TEST getList count " );
62
+ $ this ->assertEquals (10 , count ($ r ->datasets ), "TEST getList count " );
99
63
}
100
64
101
- private function _testGetMeta ($ force_curl =false ) {
65
+ public function testGetSearch () {
66
+ $ quandl = new Quandl ($ this ->api_key );
67
+ $ r = $ quandl ->getSearch ("crud oil " , 1 , 10 );
68
+ $ this ->assertEquals (10 , count ($ r ->datasets ), "TEST getSearch count " );
69
+ }
70
+
71
+ public function testGetMeta () {
102
72
$ quandl = new Quandl ($ this ->api_key );
103
- $ quandl ->force_curl = $ quandl ->no_ssl_verify = $ force_curl ;
104
73
$ r = $ quandl ->getMeta ("GOOG/NASDAQ_AAPL " );
105
74
$ this ->assertEquals ('NASDAQ_AAPL ' , $ r ->dataset ->dataset_code , "TEST getMeta dataset_code " );
106
75
$ this ->assertEquals ('GOOG ' , $ r ->dataset ->database_code , "TEST getMeta database_code " );
107
76
}
108
77
109
- private function _testGetSearch ( $ force_curl = false ) {
78
+ public function testGetDatabases ( ) {
110
79
$ quandl = new Quandl ($ this ->api_key );
111
- $ quandl ->force_curl = $ quandl ->no_ssl_verify = $ force_curl ;
112
- $ r = $ quandl ->getSearch ("crud oil " , 1 , 10 );
113
- $ this ->assertEquals (10 , count ($ r ->datasets ),
114
- "TEST getSearch count " );
80
+ $ r = $ quandl ->getDatabases (1 , 5 );
81
+ $ this ->assertEquals (5 , count ($ r ->databases ), "TEST getDatabases count " );
82
+ $ this ->assertTrue (array_key_exists ('database_code ' , $ r ->databases [0 ]), "TEST getDatabases keys " );
115
83
}
116
84
117
- private function _testCache ( $ force_curl = false ) {
85
+ public function testCache ( ) {
118
86
$ quandl = new Quandl ($ this ->api_key );
119
- $ quandl ->force_curl = $ quandl ->no_ssl_verify = $ force_curl ;
120
87
$ quandl ->cache_handler = array ($ this , "cacheHandler " );
121
88
$ r = $ quandl ->getSymbol ($ this ->symbol , $ this ->dates );
122
89
$ count = count ($ r ->dataset ->data );
@@ -131,6 +98,22 @@ private function _testCache($force_curl=false) {
131
98
"TEST was_cache should be true " );
132
99
}
133
100
101
+ // ---
102
+
103
+ public function cacheHandler ($ action , $ url , $ data =null ) {
104
+ $ cache_key = md5 ("quandl: $ url " );
105
+ $ cache_file = __DIR__ . "/ $ cache_key " ;
106
+
107
+ if ($ action == "get " and file_exists ($ cache_file ))
108
+ return file_get_contents ($ cache_file );
109
+ else if ($ action == "set " )
110
+ file_put_contents ($ cache_file , $ data );
111
+
112
+ $ this ->cache_file = $ cache_file ;
113
+
114
+ return false ;
115
+ }
116
+
134
117
private function _testGetSymbol ($ format , $ length , $ force_curl =false ) {
135
118
$ quandl = new Quandl ($ this ->api_key , $ format );
136
119
$ quandl ->force_curl = $ quandl ->no_ssl_verify = $ force_curl ;
@@ -151,5 +134,6 @@ private function _testGetSymbol($format, $length, $force_curl=false) {
151
134
$ quandl ->last_url ,
152
135
"TEST $ format url " );
153
136
}
137
+
154
138
}
155
139
?>
0 commit comments