Skip to content

Commit c137587

Browse files
committed
Use a PHP build tool, Phing instead of Grunt.
As I already mentioned in the ovh#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 <[email protected]>
1 parent 815b07b commit c137587

File tree

8 files changed

+133
-111
lines changed

8 files changed

+133
-111
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ vendor
33
composer.lock
44
composer.phar
55
/phpunit.xml
6+
/build.properties
7+
/docs

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ addons:
66
language: php
77
php:
88
- hhvm
9-
- 7.0
9+
- 7.0
1010
- 5.6
1111
- 5.5
1212
- 7.0
@@ -15,4 +15,4 @@ before_script:
1515
- composer self-update
1616
- composer install
1717

18-
script: phpunit tests/ApiTest.php
18+
script: vendor/bin/phing test -Donly.units=true

Gruntfile.js

-77
This file was deleted.

README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Quickstart
2727

2828
To download this wrapper and integrate it inside your PHP application, you can use [Composer](https://getcomposer.org).
2929

30-
Add the repository in your **composer.json** file or, if you don't already have
30+
Add the repository in your **composer.json** file or, if you don't already have
3131
this file, create it at the root of your project with this content:
3232

3333
```json
@@ -58,7 +58,7 @@ How to login as a user?
5858

5959
To communicate with APIs, the SDK uses a token on each request to identify the
6060
user. This token is called *Consumer Key*. To have a validated *Consumer Key*,
61-
you need to redirect your user on specific authentication page. Once the user has
61+
you need to redirect your user on specific authentication page. Once the user has
6262
logged in, the token is validated and user will be redirected on __$redirection__ url.
6363

6464
```php
@@ -173,11 +173,10 @@ you can install local npm project in a clone a project
173173
git clone https://github.com/ovh/php-ovh.git
174174
cd php-ovh
175175
php composer.phar install
176-
npm install
177176

178177
To generate documentation, it's possible to use directly:
179178

180-
grunt default
179+
vendor/bin/phing phpdocs
181180

182181
Documentation is available in docs/ directory.
183182

@@ -190,12 +189,15 @@ local npm project in a clone a project
190189
git https://github.com/ovh/php-ovh.git
191190
cd php-ovh
192191
php composer.phar install
193-
npm install
194192

195193
Edit **phpunit.xml** file with your credentials to pass functionals tests. Then,
196-
you can run directly unit and functionals tests with grunt.
194+
you can run directly unit and functionals tests with [phing](http://www.phing.info/).
197195

198-
grunt
196+
vendor/bin/phing test
197+
198+
To skip functionals and run unit tests only, you can use the `only.units` option :
199+
200+
vendor/bin/phing test -Donly.units=true
199201

200202
Supported APIs
201203
--------------

build.xml

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?xml version="1.0"?>
2+
<project name="ovh/ovh" default="all">
3+
<property name="base" value="${project.basedir}/" />
4+
<property environment="env" />
5+
6+
<if>
7+
<available file="${base}build.properties" property="" />
8+
<then>
9+
<property file="${base}build.properties" override="true" />
10+
</then>
11+
</if>
12+
13+
<!--##########################################################################################################-->
14+
<target name="help">
15+
<echo message="${phing.project.name} on [${git.branch}]" />
16+
<echo message=" Available commands are:" />
17+
<echo message=" test -> Run unit tests" />
18+
<echo message=" clean -> Clean current environment" />
19+
<echo message=" server -> Launch PHP built-in server" />
20+
<echo message=" watch -> Run precommit task on every file changed" />
21+
<echo message=" precommit -> Source code validation before commit" />
22+
<echo message=" Specific tools tasks:" />
23+
<echo message=" phpcs -> Run PHP Code Sniffer" />
24+
<echo message=" phplint -> Run PHP Lint" />
25+
<echo message=" phpdocs -> Run PHP Documentor" />
26+
<echo message=" phpunit -> Run PHPUnit" />
27+
</target>
28+
<!--##########################################################################################################-->
29+
<target name="test" description="Run unit tests">
30+
<phingcall target="phpunit" />
31+
</target>
32+
<target name="clean" description="Clean current environment">
33+
<delete dir="docs" includeemptydirs="true" verbose="true" failonerror="true" />
34+
</target>
35+
<target name="precommit" description="Source code validation before commit">
36+
<phingcall target="phplint" />
37+
<phingcall target="phpcs" />
38+
<phingcall target="phpunit" />
39+
</target>
40+
<target name="all" description="Make a full integration check">
41+
<phingcall target="phplint" />
42+
<phingcall target="phpcs" />
43+
<phingcall target="phpunit" />
44+
<phingcall target="phpdocs" />
45+
</target>
46+
<!--##########################################################################################################-->
47+
<target name="phpcs" description="Run PHP Code Sniffer">
48+
<phpcodesniffer
49+
standard="PSR2"
50+
format="summary"
51+
>
52+
<fileset dir=".">
53+
<include name="src/**/*.php"/>
54+
<include name="test/**/*.php"/>
55+
</fileset>
56+
</phpcodesniffer>
57+
</target>
58+
<target name="phpcbf" description="Run PHP Code Sniffer">
59+
<exec command="vendor/bin/phpcbf --standard=PSR2 src" logoutput="true" />
60+
</target>
61+
<target name="phplint" description="Run PHP Lint">
62+
<phplint deprecatedAsError="true">
63+
<fileset dir=".">
64+
<include name="src/**/*.php"/>
65+
<include name="test/**/*.php"/>
66+
</fileset>
67+
</phplint>
68+
</target>
69+
<target name="phpdocs" description="Run PHP Documentor" depends="clean">
70+
<if>
71+
<not><available file="docs" /></not>
72+
<then>
73+
<mkdir dir="docs" />
74+
</then>
75+
</if>
76+
77+
<phpdoc2 destdir="docs">
78+
<fileset dir="src">
79+
<include name="**/*.php" />
80+
</fileset>
81+
</phpdoc2>
82+
</target>
83+
<target name="phpunit" description="Run PHPUnit">
84+
<if>
85+
<and>
86+
<isset property="only.units" />
87+
<equals arg1="${only.units}" arg2="true" />
88+
</and>
89+
<then>
90+
<fileset dir="tests" id="tests">
91+
<include name="ApiTest.php"/>
92+
</fileset>
93+
</then>
94+
<else>
95+
<fileset dir="tests" id="tests">
96+
<include name="**/*.php"/>
97+
</fileset>
98+
</else>
99+
</if>
100+
101+
<phpunit
102+
haltonfailure="true"
103+
haltonerror="true"
104+
bootstrap="tests/bootstrap.php"
105+
printsummary="true"
106+
>
107+
<formatter type="plain" usefile="false"/>
108+
<batchtest>
109+
<fileset refid="tests" />
110+
</batchtest>
111+
</phpunit>
112+
</target>
113+
<!--##########################################################################################################-->
114+
</project>

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"require-dev": {
1212
"phpunit/phpunit": "4.*",
1313
"phpdocumentor/phpdocumentor": "2.*",
14-
"squizlabs/php_codesniffer": "1.*"
14+
"squizlabs/php_codesniffer": "2.*",
15+
"phing/phing": "^2.14"
1516
}
1617
}

package.json

-15
This file was deleted.

src/Api.php

+4-9
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,12 @@ private function rawCall($method, $path, $content = null, $is_authenticated = tr
228228
$url = $this->endpoint . $path;
229229
$request = new Request($method, $url);
230230
if (isset($content) && $method == 'GET') {
231-
232231
$query_string = $request->getUri()->getQuery();
233232

234233
$query = array();
235234
if (!empty($query_string)) {
236235
$queries = explode('&', $query_string);
237-
foreach($queries as $element) {
236+
foreach ($queries as $element) {
238237
$key_value_query = explode('=', $element, 2);
239238
$query[$key_value_query[0]] = $key_value_query[1];
240239
}
@@ -243,14 +242,10 @@ private function rawCall($method, $path, $content = null, $is_authenticated = tr
243242
$query = array_merge($query, (array)$content);
244243

245244
// rewrite query args to properly dump true/false parameters
246-
foreach($query as $key => $value)
247-
{
248-
if ($value === false)
249-
{
245+
foreach ($query as $key => $value) {
246+
if ($value === false) {
250247
$query[$key] = "false";
251-
}
252-
elseif ($value === true)
253-
{
248+
} elseif ($value === true) {
254249
$query[$key] = "true";
255250
}
256251
}

0 commit comments

Comments
 (0)