Development

/plugins/sfAmazonSimpleDBPlugin/trunk/test/unit/sfAmazonSimpleDBTest.php

You must first sign up to be able to contribute.

root/plugins/sfAmazonSimpleDBPlugin/trunk/test/unit/sfAmazonSimpleDBTest.php

Revision 6818, 9.3 kB (checked in by nicolas, 5 months ago)

sfAmazonSimpleDBPlugin:

  • Added pagination capabilities
  • Removed unused files provided with the official Amazon SimpleDB PHP library
Line 
1 <?php
2 // initializes testing framework
3 $app = 'main';
4 $sf_root = dirname(__FILE__).'/../../../..';
5 include($sf_root.'/test/bootstrap/functional.php');
6 require_once($sf_root.'/lib/symfony/vendor/lime/lime.php');
7
8 $t = new lime_test(54, new lime_output_color());
9
10 $service = sfAmazonSimpleDBClient::getInstance();
11 $t->isa_ok($service, 'sfAmazonSimpleDBClient', 'getClient() retrieve an Amazon_SimpleDB_Client instance');
12
13 $t->diag('Test domain creation');
14 try
15 {
16   $domainCreation1 = $service->createDomain('sfAmazonSimpleDBPluginTestDomain');
17   $domainCreation2 = $service->createDomain('sfAmazonSimpleDBPluginTestDomain2');
18   $domainCreation3 = $service->createDomain('sfAmazonSimpleDBPluginTestDomain3');
19   $t->ok($domainCreation1 && $domainCreation2 && $domainCreation3, 'createDomain() confirms domain has been created');
20   $t->pass('createDomain() does not throw an exception');
21 }
22 catch (Exception $e)
23 {
24   $t->fail('createDomain() throwed an exception: '.$e->getMessage());
25 }
26
27 $t->diag('Test domain list');
28 try
29 {
30   $domainsResults = $service->listDomains();
31   $domainsList = $domainsResults['results'];
32   $t->isa_ok($domainsList, 'array', 'listDomains() returns an array');
33   $t->ok(in_array('sfAmazonSimpleDBPluginTestDomain', $domainsList), 'listDomains() lists new created domain');
34   $t->ok(in_array('sfAmazonSimpleDBPluginTestDomain2', $domainsList), 'listDomains() lists new created domain');
35   $t->ok(in_array('sfAmazonSimpleDBPluginTestDomain3', $domainsList), 'listDomains() lists new created domain');
36  
37   $t->diag('Testing limit and offseting for domains list');
38   $domainsResults = $service->listDomains(2);
39   $domainsList = $domainsResults['results'];
40   $t->is(count($domainsList), 2, 'listDomains() retrieves the correct limited number of results');
41   $t->ok(isset($domainsResults['next_token']), 'listDomains() returns a next token');
42  
43   $domainsResultsNext = $service->listDomains(2, $domainsResults['next_token']);
44   $domainsResultsListNext = $domainsResultsNext['results'];
45   $t->is(count($domainsResultsListNext), 1, 'listDomains() retrieves the correct limited number of results with an offset');
46  
47   $t->pass('listDomains() does not throw an exception');
48 }
49 catch (Exception $e)
50 {
51   $t->fail('listDomains() throwed an exception: '.$e->getMessage());
52 }
53
54 $t->diag('Test domain selection');
55 $t->is($service->getSelectedDomain(), null, 'getSelectedDomain() is not prefilled');
56 $service->selectDomain('sfAmazonSimpleDBPluginTestDomain');
57 $t->is($service->getSelectedDomain(), 'sfAmazonSimpleDBPluginTestDomain', 'selectDomain() and getSelectedDomain() works');
58
59 $t->diag('Test data attributes creation');
60 try
61 {
62   $service->putAttributes('Entry #1', array('Color' => 'Blue', 'Size' => 'Big'));
63   $service->putAttributes('Entry #2', array('Color' => 'Red', 'Size' => 'Medium'));
64   $service->putAttributes('Entry #3', array('Color' => array('Yellow', 'Green', 'Purple'), 'Size' => 'Small'));
65   $t->pass('putAttributes() does not throw an exception');
66 }
67 catch (Exception $e)
68 {
69   $t->fail('putAttributes() throwed an exception: '.$e->getMessage());
70 }
71
72 $t->diag('Test data attributes retrieval');
73 try
74 {
75   $entry1 = $service->getAttributes('Entry #1');
76   $t->is($entry1['Color'], 'Blue', 'getAttributes() retrieve attribute correctly');
77   $t->is($entry1['Size'],  'Big''getAttributes() retrieve attribute correctly');
78  
79   $entry2 = $service->getAttributes('Entry #2');
80   $t->is($entry2['Color'], 'Red',    'getAttributes() retrieve attribute correctly');
81   $t->is($entry2['Size'],  'Medium', 'getAttributes() retrieve attribute correctly');
82  
83   $t->diag('Test multi-attributes data retrieval');
84   $entry3 = $service->getAttributes('Entry #3');
85   $t->ok(in_array('Yellow', $entry3['Color']), 'getAttributes() retrieve one of multiple attribute correctly');
86   $t->ok(in_array('Green'$entry3['Color']), 'getAttributes() retrieve one of multiple attribute correctly');
87   $t->ok(in_array('Purple', $entry3['Color']), 'getAttributes() retrieve one of multiple attribute correctly');
88   $t->is($entry3['Size'],  'Small''getAttributes() retrieve attribute correctly');
89  
90   $t->pass('getAttributes() does not throw an exception');
91 }
92 catch (Exception $e)
93 {
94   $t->fail('getAttributes() throwed an exception: '.$e->getMessage());
95 }
96
97 $t->diag('Test querying');
98 try
99 {
100   $t->diag(' 1. Getting all data');
101   $queryResults = $service->query();
102   $queryResultsList = $queryResults['results'];
103   $t->isa_ok($queryResultsList, 'array', 'query() retrieves results as an array');
104   $t->is(count($queryResultsList), 3, 'query() retrieves the correct number of results');
105  
106   $t->diag(' 2. Filtering one attribute');
107   $queryResults = $service->query("['Color' = 'Red']");
108   $queryResultsList = $queryResults['results'];
109   $t->isa_ok($queryResultsList, 'array', 'query() retrieves results as an array');
110   $t->is(count($queryResultsList), 1, 'query() retrieves the correct number of results');
111   $t->is($queryResultsList[0], 'Entry #2', 'query() retrieves the correct result');
112  
113   $t->diag(' 3. Filtering multiple attributes');
114   $queryResults = $service->query("['Color' = 'Green'] intersection ['Size' = 'Small']");
115   $queryResultsList = $queryResults['results'];
116   $t->is(count($queryResultsList), 1, 'query() retrieves the correct number of results');
117   $t->is($queryResultsList[0], 'Entry #3', 'query() retrieves the correct result');
118  
119   $t->diag(' 4. Testing limit and offseting for results list');
120   $queryResults = $service->query(null, 2);
121   $queryResultsList = $queryResults['results'];
122   $t->is(count($queryResultsList), 2, 'query() retrieves the correct limited number of results');
123   $t->ok(isset($queryResults['next_token']), 'query() retrieves a next token attribute');
124     
125   $queryResultsNext = $service->query(null, 2, $queryResults['next_token']);
126   $queryResultsListNext = $queryResultsNext['results'];
127   $t->is(count($queryResultsListNext), 1, 'query() retrieves the correct limited number of results with an offset');
128  
129   $t->pass('query() does not throw an exception');
130 }
131 catch (Exception $e)
132 {
133   $t->fail('query() throwed an exception: '.$e->getMessage());
134 }
135
136 $t->diag('Test attribute replacement');
137 try
138 {
139   $replacement = $service->putAttributes('Entry #2', array('Color' => 'Black',
140                                                            'Size'  => 'Tiny'), true);
141   $t->ok($replacement, 'putAttributes() declares replacement done');
142   $entry2 = $service->getAttributes('Entry #2');
143   $t->is($entry2['Color'], 'Black', 'getAttributes() retrieve attribute correctly');
144   $t->is($entry2['Size'],  'Tiny''getAttributes() retrieve attribute correctly');
145   $t->pass('putAttributes() does not throw an exception');
146 }
147 catch (Exception $e)
148 {
149   $t->fail('putAttributes() throwed an exception: '.$e->getMessage());
150 }
151
152 $t->diag('Test attribute deletion');
153 try
154 {
155   $t->diag(' 1. by attribute name and value');
156   $attributesDeletion = $service->deleteAttributes('Entry #3', 'Color', 'Green');
157   $t->ok($attributesDeletion, 'deleteAttributes() declares deletion by name and value has been done');
158   $entry3 = $service->getAttributes('Entry #3');
159   $t->ok(!in_array('Green', $entry3['Color']), 'getAttributes() does not retrieve a deleted attribute');
160   $t->ok(in_array('Yellow', $entry3['Color']), 'getAttributes() still retrieve other attribute correctly');
161   $t->ok(in_array('Purple', $entry3['Color']), 'getAttributes() still retrieve other attribute correctly');
162  
163   $t->diag(' 2. by attribute name');
164   $attributesDeletion = $service->deleteAttributes('Entry #3', 'Color');
165   $t->ok($attributesDeletion, 'deleteAttributes() declares deletion by name has been done');
166   $entry3 = $service->getAttributes('Entry #3');
167   $t->ok(!array_key_exists('Color', $entry3), 'getAttributes() retrieves no values for deleted attribute name');
168  
169   $t->pass('deleteAttributes() does not throw an exception');
170 }
171 catch (Exception $e)
172 {
173   $t->fail('deleteAttributes() throwed an exception: '.$e->getMessage());
174 }
175
176 $t->diag('Test item deletion');
177 try
178 {
179   $entryDeletion = $service->deleteAttributes('Entry #2');
180   $t->ok($entryDeletion, 'deleteAttributes() confirms entry has been deleted');
181   $entry2 = $service->getAttributes('Entry #2');
182   $t->is(count($entry2), 0, 'deleteAttributes() Entry no more exists');
183   $t->pass('deleteAttributes() does not throw an exception');
184 }
185 catch (Exception $e)
186 {
187   $t->fail('deleteAttributes() throwed an exception: '.$e->getMessage());
188 }
189
190 $t->diag('Test domain deletion');
191 try
192 {
193   $domainDeletion1 = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain');
194   $domainDeletion2 = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain2');
195   $domainDeletion3 = $service->deleteDomain('sfAmazonSimpleDBPluginTestDomain3');
196   $t->ok($domainDeletion1 && $domainDeletion2 && $domainDeletion3, 'deleteDomain() confirms domain has been deleted');
197   $t->pass('deleteDomain() does not throw an exception');
198 }
199 catch (Exception $e)
200 {
201   $t->fail('deleteDomain() throwed an exception: '.$e->getMessage());
202 }
203
204 $domainsResults = $service->listDomains();
205 $domainsList = $domainsResults['results'];
206 $t->ok(!in_array('sfAmazonSimpleDBPluginTestDomain', $domainsList), 'listDomains() no more lists deleted domain');
207 $t->ok(!in_array('sfAmazonSimpleDBPluginTestDomain2', $domainsList), 'listDomains() no more lists deleted domain');
208 $t->ok(!in_array('sfAmazonSimpleDBPluginTestDomain3', $domainsList), 'listDomains() no more lists deleted domain');
209 $t->is($service->getSelectedDomain(), null, 'getSelectedDomain() no more returns a deleted domain as selected');
Note: See TracBrowser for help on using the browser.