Permalink
Browse files

added unitary examples; implemented Test::RunAll

  • Loading branch information...
1 parent 1ff3e60 commit 88afa203fad1a03cae9f7effc6224131a040e8d7 @nocive committed Mar 18, 2012
View
@@ -6,7 +6,7 @@
* You should NOT edit this file!
* This file was automatically generated by PHP.
*
- * Generated at: Sat, 17 Mar 2012 19:36:34 +0100
+ * Generated at: Sun, 18 Mar 2012 00:26:00 +0000
*
***********************************************************/
@@ -40,7 +40,7 @@
*/
class Freesound extends Freesound_Base
{
- protected $_interfaces;
+ public $interfaces;
public function __construct( $apiKey = null, $config = null )
@@ -50,10 +50,10 @@ public function __construct( $apiKey = null, $config = null )
$this->_config->Set( self::CFG_API_KEY, $apiKey );
}
- $this->_interfaces = new StdClass();
+ $this->interfaces = new StdClass();
foreach( Freesound_API_Base::$interfaceNames as $iname ) {
$class = 'Freesound_API_' . ucfirst( strtolower( $iname ) );
- $this->_interfaces->{$iname} = new $class( $apiKey, $this->_config );
+ $this->interfaces->{$iname} = new $class( $apiKey, $this->_config );
}
}
@@ -66,17 +66,17 @@ public function Config()
public function __call( $method, $args )
{
- foreach( get_object_vars( $this->_interfaces ) as $var => $value ) {
+ foreach( get_object_vars( $this->interfaces ) as $var => $value ) {
if (strtolower( $method ) === $var) {
if (count( $args ) === 1) {
- $this->_interfaces->{$var}->id = $args[0];
+ $this->interfaces->{$var}->id = $args[0];
}
- return $this->_interfaces->{$var};
+ return $this->interfaces->{$var};
}
$realMethod = substr( $method, strlen( $var ) );
- if (stripos( $method, $var ) === 0 && method_exists( $this->_interfaces->{$var}, $realMethod )) {
- return call_user_func_array( array( $this->_interfaces->{$var}, $realMethod ), $args );
+ if (stripos( $method, $var ) === 0 && method_exists( $this->interfaces->{$var}, $realMethod )) {
+ return call_user_func_array( array( $this->interfaces->{$var}, $realMethod ), $args );
}
}
@@ -129,6 +129,7 @@ class Freesound_Bootstrap
'Freesound_API_Pack' => 'API/Pack',
'Freesound_API_Sound' => 'API/Sound',
'Freesound_API_User' => 'API/User',
+ 'Freesound_Test' => 'Test/Test',
'Freesound_CommunicationException' => 'Exception/Exception',
'Freesound_MalformedResponseException' => 'Exception/Exception',
'Freesound_APIErrorException' => 'Exception/Exception'
@@ -252,9 +253,9 @@ public function Reset()
*/
class Freesound_Utils
{
- public static function BundleBuild( $file )
+ public static function BundleBuild( $file, $overwrite = false )
{
- if (is_file( $file )) {
+ if (! $overwrite && is_file( $file )) {
throw new Exception( "File '$file' already exists, please remove it before trying to build a new bundle" );
}
@@ -556,6 +557,45 @@ public function GetPacks( $username = null )
+class Freesound_Test
+{
+ protected $_params;
+ protected $_class;
+
+ public function __construct( $class, $params = null )
+ {
+ if (! is_object( $class )) {
+ throw new InvalidArgumentException( '$class must be a valid object' );
+ }
+
+ $this->_params = $params;
+ $this->_class = $class;
+
+ }
+
+
+ public function RunAll()
+ {
+ $r = array();
+ foreach( get_object_vars( $this->_class->interfaces ) as $var => $value ) {
+ foreach( get_class_methods( $value ) as $method ) {
+ if (substr( $method, 0, 1 ) !== '_' ) {
+ $classmethod = ucfirst( $var ) . $method;
+ $args = ! empty( $this->_params[$classmethod] ) ? $this->_params[$classmethod] : array();
+ $r[$classmethod] = call_user_func_array( array( $value, $method ), $args );
+ }
+ }
+ }
+ return $r;
+ }
+
+
+ // TODO implement __call for unit tests
+}
+
+
+
+
class Freesound_Exception extends Exception {}
class Freesound_CommunicationException extends Freesound_Exception {}
class Freesound_MalformedResponseException extends Freesound_Exception {}
@@ -564,4 +604,4 @@ class Freesound_APIErrorException extends Freesound_Exception {}
-?>
+?>
View
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->PackGet( 5107 );
+//$r = $fs->Pack()->Get( 5107 );
+$r = $fs->Pack( 5107 )->Get();
+var_dump( $r );
+
+?>
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->PackGetSounds( 5107 );
+//$r = $fs->Pack()->GetSounds( 5107 );
+$r = $fs->Pack( 5107 )->GetSounds();
+var_dump( $r );
+
+?>
View
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->SoundGet( 120597 );
+//$r = $fs->Sound()->Get( 120597 );
+$r = $fs->Sound( 120597 )->Get();
+var_dump( $r );
+
+?>
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->SoundGetAnalysis( 120597 );
+//$r = $fs->Sound()->GetAnalysis( 120597 );
+$r = $fs->Sound( 120597 )->GetAnalysis();
+var_dump( $r );
+
+?>
@@ -0,0 +1,11 @@
+
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->SoundGetSimilar( 120597 );
+//$r = $fs->Sound()->GetSimilar( 120597 );
+$r = $fs->Sound( 120597 )->GetSimilar();
+var_dump( $r );
+
+?>
@@ -0,0 +1,9 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->SoundSearch( 'foo' );
+$r = $fs->Sound()->Search( 'foo' );
+var_dump( $r );
+
+?>
@@ -0,0 +1,9 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->SoundSearchGeo( 41.3265528618605, 41.4504467428547, 2.005176544189453, 2.334766387939453 );
+$r = $fs->Sound()->SearchGeo( 41.3265528618605, 41.4504467428547, 2.005176544189453, 2.334766387939453 );
+var_dump( $r );
+
+?>
View
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->UserGet( 'antigonia' );
+//$r = $fs->User()->Get( 'antigonia' );
+$r = $fs->User( 'antigonia' )->Get();
+var_dump( $r );
+
+?>
View
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->UserGetPacks( 'antigonia' );
+//$r = $fs->User()->GetPacks( 'antigonia' );
+$r = $fs->User( 'antigonia' )->GetPacks();
+var_dump( $r );
+
+?>
@@ -0,0 +1,10 @@
+<?php
+
+require_once( 'config.php' );
+
+//$r = $fs->UserGetSounds( 'antigonia' );
+//$r = $fs->User()->GetSounds( 'antigonia' );
+$r = $fs->User( 'antigonia' )->GetSounds();
+var_dump( $r );
+
+?>
@@ -1,27 +1,6 @@
<?php
-require_once( __DIR__ . '/../lib/Freesound.php' );
-//require_once( __DIR__ . '/../bundle/Freesound.php' );
-
-
-#####################################################################################
-
-//$fs = new Freesound();
-//$fs->Config( array(
-// 'api_key' => '77bbf1a63bc84ccc9d80a38d6345ef60',
-// 'fetch_connect_timeout' => 30,
-// 'fetch_timeout' => 20,
-// 'debug' => 1,
-// 'json_decode_assoc' => false
-//));
-
-$fs = new Freesound( '77bbf1a63bc84ccc9d80a38d6345ef60' );
-$fs->Config( 'debug', 1 );
-
-
-
-
-#####################################################################################
+require_once( 'config.php' );
//$r = $fs->SoundSearch( 'foo' );
$r = $fs->Sound()->Search( 'foo' );
View
@@ -0,0 +1,17 @@
+<?php
+
+require_once( __DIR__ . '/../lib/Freesound.php' );
+
+$apiKey = '77bbf1a63bc84ccc9d80a38d6345ef60';
+
+$fs = new Freesound( $apiKey );
+$fs->Config( 'debug', 1 );
+//$fs->Config( array(
+// 'api_key' => $apiKey,
+// 'fetch_connect_timeout' => 30,
+// 'fetch_timeout' => 20,
+// 'debug' => 1,
+// 'json_decode_assoc' => true
+//));
+
+?>
View
@@ -78,8 +78,6 @@ public function SearchGeo( $minLat = null, $maxLat = null, $minLon = null, $maxL
'fields' => $fields
));
}
-
-
}
?>
@@ -18,6 +18,7 @@ class Freesound_Bootstrap
'Freesound_API_Pack' => 'API/Pack',
'Freesound_API_Sound' => 'API/Sound',
'Freesound_API_User' => 'API/User',
+ 'Freesound_Test' => 'Test/Test',
'Freesound_CommunicationException' => 'Exception/Exception',
'Freesound_MalformedResponseException' => 'Exception/Exception',
'Freesound_APIErrorException' => 'Exception/Exception'
View
@@ -30,7 +30,7 @@
*/
class Freesound extends Freesound_Base
{
- protected $_interfaces;
+ public $interfaces;
public function __construct( $apiKey = null, $config = null )
@@ -40,10 +40,10 @@ public function __construct( $apiKey = null, $config = null )
$this->_config->Set( self::CFG_API_KEY, $apiKey );
}
- $this->_interfaces = new StdClass();
+ $this->interfaces = new StdClass();
foreach( Freesound_API_Base::$interfaceNames as $iname ) {
$class = 'Freesound_API_' . ucfirst( strtolower( $iname ) );
- $this->_interfaces->{$iname} = new $class( $apiKey, $this->_config );
+ $this->interfaces->{$iname} = new $class( $apiKey, $this->_config );
}
}
@@ -56,17 +56,17 @@ public function Config()
public function __call( $method, $args )
{
- foreach( get_object_vars( $this->_interfaces ) as $var => $value ) {
+ foreach( get_object_vars( $this->interfaces ) as $var => $value ) {
if (strtolower( $method ) === $var) {
if (count( $args ) === 1) {
- $this->_interfaces->{$var}->id = $args[0];
+ $this->interfaces->{$var}->id = $args[0];
}
- return $this->_interfaces->{$var};
+ return $this->interfaces->{$var};
}
$realMethod = substr( $method, strlen( $var ) );
- if (stripos( $method, $var ) === 0 && method_exists( $this->_interfaces->{$var}, $realMethod )) {
- return call_user_func_array( array( $this->_interfaces->{$var}, $realMethod ), $args );
+ if (stripos( $method, $var ) === 0 && method_exists( $this->interfaces->{$var}, $realMethod )) {
+ return call_user_func_array( array( $this->interfaces->{$var}, $realMethod ), $args );
}
}
View
@@ -2,7 +2,38 @@
class Freesound_Test
{
- // TODO
+ protected $_params;
+ protected $_class;
+
+ public function __construct( $class, $params = null )
+ {
+ if (! is_object( $class )) {
+ throw new InvalidArgumentException( '$class must be a valid object' );
+ }
+
+ $this->_params = $params;
+ $this->_class = $class;
+
+ }
+
+
+ public function RunAll()
+ {
+ $r = array();
+ foreach( get_object_vars( $this->_class->interfaces ) as $var => $value ) {
+ foreach( get_class_methods( $value ) as $method ) {
+ if (substr( $method, 0, 1 ) !== '_' ) {
+ $classmethod = ucfirst( $var ) . $method;
+ $args = ! empty( $this->_params[$classmethod] ) ? $this->_params[$classmethod] : array();
+ $r[$classmethod] = call_user_func_array( array( $value, $method ), $args );
+ }
+ }
+ }
+ return $r;
+ }
+
+
+ // TODO implement __call for unit tests
}
?>
View
@@ -8,9 +8,9 @@
*/
class Freesound_Utils
{
- public static function BundleBuild( $file )
+ public static function BundleBuild( $file, $overwrite = false )
{
- if (is_file( $file )) {
+ if (! $overwrite && is_file( $file )) {
throw new Exception( "File '$file' already exists, please remove it before trying to build a new bundle" );
}
Oops, something went wrong.

0 comments on commit 88afa20

Please sign in to comment.