From c13758720b64a4836aafc308599c0184e2cfb2bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20HULARD?= Date: Tue, 5 Apr 2016 14:49:08 +0200 Subject: [PATCH] Use a PHP build tool, Phing instead of Grunt. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As I already mentioned in the #35 issue, I think it's more suitable to use a PHP build tool instead of a JS one. I don't tell that Grunt is not a powerful tool but it's a complicated installation process to be able to run tests. Phing is required as a composer package and can be run directly after the composer install. Examples: ``` vendor/bin/phing vendor/bin/phing test vendor/bin/phing clean vendor/bin/phing phplint vendor/bin/phing phpcs vendor/bin/phing phpunit vendor/bin/phing phpunit -Donly.units=true #The travis test process ``` The only difference here is the watch process. Phing doesn't have that kind of feature. It can be emulated with different tasks but require a lot more work. I think that PR is the first step, maybe we can go further if necessary. Signed-off-by: Stéphane HULARD --- .gitignore | 2 + .travis.yml | 4 +- Gruntfile.js | 77 ---------------------------------- README.md | 16 +++---- build.xml | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++ composer.json | 3 +- package.json | 15 ------- src/Api.php | 13 ++---- 8 files changed, 133 insertions(+), 111 deletions(-) delete mode 100644 Gruntfile.js create mode 100644 build.xml delete mode 100644 package.json diff --git a/.gitignore b/.gitignore index 2ef75c1..2a9cd3f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ vendor composer.lock composer.phar /phpunit.xml +/build.properties +/docs diff --git a/.travis.yml b/.travis.yml index c22c542..bf382ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons: language: php php: - hhvm - - 7.0 + - 7.0 - 5.6 - 5.5 - 7.0 @@ -15,4 +15,4 @@ before_script: - composer self-update - composer install -script: phpunit tests/ApiTest.php +script: vendor/bin/phing test -Donly.units=true diff --git a/Gruntfile.js b/Gruntfile.js deleted file mode 100644 index d22b1c4..0000000 --- a/Gruntfile.js +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Gruntfile.js - */ -module.exports = function(grunt) { - grunt.initConfig({ - pkg: grunt.file.readJSON('package.json'), - php: { - dist: { - options: { - port: 8080, - base: 'web', - open: true, - keepalive: true - } - } - }, - phpcs: { - application: { - dir: ['src/'] - }, - options: { - bin: 'vendor/bin/phpcs', - standard: 'PSR2' - } - }, - phplint: { - options: { - swapPath: '/tmp' - }, - all: ['src/*.php'] - }, - phpdocumentor: { - dist: { - options: { - directory: './src/', - bin: 'vendor/bin/phpdoc.php', - target: 'docs/' - } - } - }, - clean: { - phpdocumentor: 'docs/' - }, - phpunit: { - unit: { - dir: 'tests' - }, - options: { - bin: 'vendor/bin/phpunit', - colors: true, - testdox: true - } - }, - watch: { - scripts: { - files: ['src/*.php', 'src/**/*.php', 'tests/*.php', 'tests/**/*.php'], - tasks: ['precommit'], - }, - }, - - }); - - grunt.loadNpmTasks('grunt-phpcs'); - grunt.loadNpmTasks('grunt-php'); - grunt.loadNpmTasks('grunt-phplint'); - grunt.loadNpmTasks('grunt-phpunit'); - grunt.loadNpmTasks('grunt-phpdocumentor'); - grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.registerTask('phpdocs', [ - 'clean:phpdocumentor', - 'phpdocumentor' - ]); - grunt.registerTask('precommit', ['phplint:all', 'phpcs', 'phpunit:unit']); - grunt.registerTask('default', ['phplint:all', 'phpcs', 'phpunit:unit', 'phpdocs']); - grunt.registerTask('server', ['php']); -}; \ No newline at end of file diff --git a/README.md b/README.md index f2fa1bb..0ca929b 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Quickstart To download this wrapper and integrate it inside your PHP application, you can use [Composer](https://getcomposer.org). -Add the repository in your **composer.json** file or, if you don't already have +Add the repository in your **composer.json** file or, if you don't already have this file, create it at the root of your project with this content: ```json @@ -58,7 +58,7 @@ How to login as a user? To communicate with APIs, the SDK uses a token on each request to identify the user. This token is called *Consumer Key*. To have a validated *Consumer Key*, -you need to redirect your user on specific authentication page. Once the user has +you need to redirect your user on specific authentication page. Once the user has logged in, the token is validated and user will be redirected on __$redirection__ url. ```php @@ -173,11 +173,10 @@ you can install local npm project in a clone a project git clone https://github.com/ovh/php-ovh.git cd php-ovh php composer.phar install - npm install To generate documentation, it's possible to use directly: - grunt default + vendor/bin/phing phpdocs Documentation is available in docs/ directory. @@ -190,12 +189,15 @@ local npm project in a clone a project git https://github.com/ovh/php-ovh.git cd php-ovh php composer.phar install - npm install Edit **phpunit.xml** file with your credentials to pass functionals tests. Then, -you can run directly unit and functionals tests with grunt. +you can run directly unit and functionals tests with [phing](http://www.phing.info/). - grunt + vendor/bin/phing test + +To skip functionals and run unit tests only, you can use the `only.units` option : + + vendor/bin/phing test -Donly.units=true Supported APIs -------------- diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..4bcd5bf --- /dev/null +++ b/build.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/composer.json b/composer.json index 8edcdb1..823c769 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,7 @@ "require-dev": { "phpunit/phpunit": "4.*", "phpdocumentor/phpdocumentor": "2.*", - "squizlabs/php_codesniffer": "1.*" + "squizlabs/php_codesniffer": "2.*", + "phing/phing": "^2.14" } } diff --git a/package.json b/package.json deleted file mode 100644 index a47d173..0000000 --- a/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "ovh-ovh", - "version": "1.1.0", - "project": "Ovh", - "dependencies": { - "grunt": "~0.4.1", - "grunt-contrib-clean": "~0.5.0", - "grunt-phpcs": "~0.2.2", - "grunt-php": "~0.3.2", - "grunt-phplint": "~0.0.5", - "grunt-phpunit": "~0.3.3", - "grunt-phpdocumentor": "~0.4.1", - "grunt-contrib-watch ": "~0.6.1" - } -} diff --git a/src/Api.php b/src/Api.php index 3752146..dbee282 100644 --- a/src/Api.php +++ b/src/Api.php @@ -228,13 +228,12 @@ class Api $url = $this->endpoint . $path; $request = new Request($method, $url); if (isset($content) && $method == 'GET') { - $query_string = $request->getUri()->getQuery(); $query = array(); if (!empty($query_string)) { $queries = explode('&', $query_string); - foreach($queries as $element) { + foreach ($queries as $element) { $key_value_query = explode('=', $element, 2); $query[$key_value_query[0]] = $key_value_query[1]; } @@ -243,14 +242,10 @@ class Api $query = array_merge($query, (array)$content); // rewrite query args to properly dump true/false parameters - foreach($query as $key => $value) - { - if ($value === false) - { + foreach ($query as $key => $value) { + if ($value === false) { $query[$key] = "false"; - } - elseif ($value === true) - { + } elseif ($value === true) { $query[$key] = "true"; } }