diff --git a/.travis.yml b/.travis.yml index 806ba15..2d56472 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,15 @@ php: - '5.6' - '7.0' -#install: -# - curl -s http://getcomposer.org/installer | php -# - php composer.phar install --dev --no-interaction -# - composer dump-autoload -# -#script: -# - mkdir -p build/cov -# - mkdir -p build/logs -# - php vendor/bin/phpunit -c phpunit.dist.xml -# -#after_success: -# - travis_retry php vendor/bin/coveralls -v -# - travis_retry php vendor/bin/codacycoverage clover build/logs/clover.xml -# \ No newline at end of file +install: + - curl -s http://getcomposer.org/installer | php + - php composer.phar install --dev --no-interaction + - composer dump-autoload + +script: + - mkdir -p build/cov + - mkdir -p build/logs + - php vendor/bin/phpunit -c phpunit.dist.xml + +after_success: + - travis_retry php vendor/bin/codacycoverage clover build/logs/clover.xml diff --git a/composer.json b/composer.json index 2dc7865..bfbb52f 100644 --- a/composer.json +++ b/composer.json @@ -12,9 +12,14 @@ ], "require" : { "php": ">=5.5.0", - "alphayax/php_utils" : "^1.0.0", + "alphayax/php_utils" : "^1.0.2", "monolog/monolog": "^1.9.1" }, + "require-dev" : { + "phpunit/phpunit": "^5.4.0", + "zf1/zend-reflection": "1.12.*", + "codacy/coverage": "<2.0.0" + }, "autoload": { "psr-4": { "alphayax\\": "./" diff --git a/exemple/AirMedia/AirMedia.php b/exemple/AirMedia/AirMedia.php index 8af9111..1ef017f 100644 --- a/exemple/AirMedia/AirMedia.php +++ b/exemple/AirMedia/AirMedia.php @@ -4,7 +4,7 @@ require_once '../../vendor/autoload.php'; /// Define our application -$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.example_airmedia', 'Freebox PHP API Example (AirMedia)', '1.0.0'); +$App = new \alphayax\freebox\utils\Application( 'com.alphayax.freebox.airmedia', 'PHP API Example (AirMedia)', '1.0.0'); $App->authorize(); $App->openSession(); @@ -13,8 +13,8 @@ $AirMediaService = new \alphayax\freebox\api\v3\services\AirMedia\AirMedia( $App // AirMedia Config $Configuration = $AirMediaService->getConfiguration(); -var_dump( $Configuration); - +print_r( $Configuration); +/* // AirMedia Receivers $Receivers = $AirMediaService->getAirMediaReceivers(); var_dump( $Receivers); @@ -27,3 +27,4 @@ $Request->setMedia( 'http://anon.nasa-global.edgesuite.net/HD_downloads/GRAIL_la $Status = $AirMediaService->sendRequestToAirMediaReceiver( 'Freebox Player', $Request); var_dump( $Status); +*/ \ No newline at end of file diff --git a/phpunit.dist.xml b/phpunit.dist.xml new file mode 100644 index 0000000..00472f1 --- /dev/null +++ b/phpunit.dist.xml @@ -0,0 +1,10 @@ + + + + tests + + + + + + diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..7334e53 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + tests + + + + + + diff --git a/tests/Test.php b/tests/Test.php new file mode 100644 index 0000000..2d81eb0 --- /dev/null +++ b/tests/Test.php @@ -0,0 +1,95 @@ +getFilesByExtension( 'php', true); + foreach ($ModelFiles as $modelFile){ + require_once $modelFile; + } + + /// Get Model subClasses + $LoadedClasses = get_declared_classes(); + $ModelClasses = []; + foreach( $LoadedClasses as $loadedClass){ + if( is_subclass_of( $loadedClass, Model::class)){ + $ModelClasses[] = $loadedClass; + } + } + + /// Test classes + foreach( $ModelClasses as $modelClass){ + $ModelReflect = new \ReflectionClass( $modelClass); + + $ClassArgs = []; + $properties = $ModelReflect->getProperties(); + foreach ( $properties as $property){ + $ClassArgs[$property->getName()] = ''; + } + + + $Model = new $modelClass($ClassArgs); + + $methods = $ModelReflect->getMethods(); + foreach ( $methods as $method){ + + $method = new \Zend_Reflection_Method( $Model, $method->getName()); + $docBlock = $method->getDocblock(); + echo "--" . PHP_EOL; + echo "$modelClass " . $method->getName() . PHP_EOL; + + if( ! $method->isPublic()){ + continue; + } + + $args = []; + if($docBlock->hasTag('param')) { + /** @var \Zend_Reflection_Docblock_Tag_Param[] $tagParams */ + $tagParams = $docBlock->getTags('param'); // $tagReturn is an instance of Zend_Reflection_Docblock_Tag_Return + foreach ( $tagParams as $tagParam){ + echo "Param Type : " . $tagParam->getType() . PHP_EOL; + + switch( $tagParam->getType()){ + case 'string' : $args[] = $tagParam->getName(); break; + case 'bool': + case 'boolean': $args[] = true; break; + case 'array' : $args[] = []; break; + default : print_r( $tagParam); return; + } + } + } + + $a = $method->invokeArgs( $Model, $args); + + if( $docBlock->hasTag('return')) { + /** @var \Zend_Reflection_Docblock_Tag_Return $tagReturn */ + $tagReturn = $docBlock->getTag('return'); + echo "Returns a: " . $tagReturn->getType() . PHP_EOL; + + $this->assertInternalType( $tagReturn->getType(), $a); + /* + switch( $tagReturn->getType()){ + case 'string' : $this->assertInternalType( string); break; + case 'bool': + case 'boolean': $args[] = true; break; + case 'array' : $args[] = []; break; + default : print_r( $tagParam); return; + } + */ + } + + + } + } + } + +} diff --git a/tests/models/AirMediaTest.php b/tests/models/AirMediaTest.php new file mode 100644 index 0000000..9d09c9d --- /dev/null +++ b/tests/models/AirMediaTest.php @@ -0,0 +1,43 @@ + true, + ]; + $AM_Config = new AirMediaConfig( $data); + + $this->assertAttributeEquals( $data['enabled'], 'enabled', $AM_Config); + } + + public function testGetters() { + + $data = [ + 'enabled' => true, + ]; + $AM_Config = new AirMediaConfig( $data); + + $this->assertEquals( $AM_Config->isEnabled(), $data['enabled']); + } + + public function testSetters() { + + $data = [ + 'enabled' => true, + ]; + $AM_Config = new AirMediaConfig( $data); + + $AM_Config->setEnabled( false); + $this->assertAttributeEquals( false, 'enabled', $AM_Config); + + $AM_Config->setPassword( 'azerty'); + $this->assertAttributeEquals( 'azerty', 'password', $AM_Config); + } + +}