Overview

Namespaces

  • ApiAxle
    • Api
    • Shared
  • ApiAxleTest
    • Api
    • Shared
  • PHP

Classes

  • Api_AllTests
  • ApiTests
  • KeyringTests
  • KeyTests
  • Overview
  • Namespace
  • Class
  • Tree
  • Todo
  1: <?php
  2: namespace ApiAxleTest\Api;
  3: 
  4: require_once __DIR__.'/../../vendor/autoload.php';
  5: 
  6: use ApiAxle\Shared\Config;
  7: use ApiAxle\Api\Key;
  8: use ApiAxle\Api\Api;
  9: use ApiAxle\Api\Keyring;
 10: use ApiAxle\Shared\ApiException;
 11: 
 12: class KeyringTests extends \PHPUnit_Framework_TestCase
 13: {
 14:     public static function tearDownAfterClass()
 15:     {
 16:         try {
 17:             $keyring = new Keyring();
 18:             $keyringList = $keyring->getList();
 19:             foreach($keyringList as $item){
 20:                 if(strpos($item->getName(),'test-') !== false){
 21:                     $keyring->delete($item->getName());
 22:                 }
 23:             }
 24:             
 25:             $key = new Key();
 26:             $keyList = $key->getList();
 27:             foreach($keyList as $item){
 28:                 if(strpos($item->getKey(),'test-') !== false){
 29:                     $key->delete($item->getKey());
 30:                 }
 31:             }
 32:         } catch(ApiException $ae){
 33:             echo $ae;
 34:         } catch(\Exception $e){
 35:             echo $e;
 36:         }
 37:     }
 38:     
 39:     public function testCreateKeyring()
 40:     {
 41:         $keyringName = 'test-'.str_replace(array(' ','.'),'',microtime());
 42:         $keyring = new Keyring();
 43:         $keyring->create($keyringName);
 44:         $this->assertInternalType('integer', $keyring->getCreatedAt());
 45:     }
 46:     
 47:     public function testGetKeyringList()
 48:     {
 49:         $keyring = new Keyring();
 50:         $keyringList = $keyring->getList();
 51:         //print_r($keyringList);
 52:         $this->assertInstanceOf('ApiAxle\Shared\ItemList', $keyringList);
 53:     }
 54:     
 55:     public function testCreateDeleteKeyring()
 56:     {
 57:         $keyringName = 'test-'.str_replace(array(' ','.'),'',microtime());
 58:         $keyring = new Keyring();
 59:         $keyring->create($keyringName);
 60:         $this->assertInternalType('integer', $keyring->getCreatedAt());
 61:         $keyringList = $keyring->getList();
 62:         $hasKeyring = false;
 63:         foreach($keyringList as $item){
 64:             if($item->getName() == $keyringName){
 65:                 $hasKeyring = true;
 66:                 break;
 67:             }
 68:         }
 69:         $this->assertTrue($hasKeyring,'Keyring not found after create');
 70:         $keyring->delete();
 71:         $keyringList = $keyring->getList();
 72:         $hasKeyring = false;
 73:         foreach($keyringList as $item){
 74:             if($item->getName() == $keyringName){
 75:                 $hasKeyring = true;
 76:                 break;
 77:             }
 78:         }
 79:         $this->assertFalse($hasKeyring,'Keyring still found after delete');
 80:     }
 81:     
 82:     public function testLinkUnlinkKey()
 83:     {
 84:         $keyValue = 'test-'.str_replace(array(' ','.'),'',microtime());
 85:         $key = new Key();
 86:         $key->create($keyValue);
 87:         
 88:         $keyringName = 'test-'.str_replace(array(' ','.'),'',microtime());
 89:         $keyring = new Keyring();
 90:         $keyring->create($keyringName);
 91:         $keyring->linkKey($key);
 92:         
 93:         $keyList = $keyring->getKeyList();
 94:         $hasKey = false;
 95:         foreach($keyList as $item){
 96:             if($item->getKey() == $keyValue){
 97:                 $hasKey = true;
 98:                 break;
 99:             }
100:         }
101:         $this->assertTrue($hasKey,'Key not found after linking');
102:         
103:         $keyring->unLinkKey($key);
104:         $keyList = $keyring->getKeyList();
105:         $hasKey = false;
106:         foreach($keyList as $item){
107:             if($item->getKey() == $keyValue){
108:                 $hasKey = true;
109:                 break;
110:             }
111:         }
112:         $this->assertFalse($hasKey,'Key still found after unlinking');
113:     }
114:     
115:     public function testGetStats()
116:     {
117:         $keyringName = 'test-'.str_replace(array(' ','.'),'',microtime());
118:         $keyring = new Keyring();
119:         $keyring->create($keyringName);
120:         $stats = $keyring->getStats();
121:         $this->assertInstanceOf('\stdClass', $stats);
122:     }
123:     
124:     public function testBatchLinkKeys()
125:     {
126:         $key1 = new Key();
127:         $key1->create('test-1'.str_replace(array(' ','.'),'',microtime()));
128:         
129:         $key2 = new Key();
130:         $key2->create('test-2'.str_replace(array(' ','.'),'',microtime()));
131:         
132:         $key3 = new Key();
133:         $key3->create('test-3'.str_replace(array(' ','.'),'',microtime()));
134:         
135:         $keys = array($key1,$key2,$key3);
136:         
137:         $keyring = new Keyring();
138:         $keyring->create('test-r'.str_replace(array(' ','.'),'',microtime()), $keys);
139:         
140:         $keyList = $keyring->getKeyList();
141:         $this->assertInstanceOf('ApiAxle\Shared\ItemList', $keyList);
142:         $this->assertCount(3, $keyList);
143:     }
144: }
145: 
fillup/apiaxle API documentation generated by ApiGen 2.8.0