Skip to content

Commit 86b32ee

Browse files
author
Benjamin Wilson Friedman
authored
Expanded Travis CI Tests (Curl/Non-Curl)
1 parent 3cc33dc commit 86b32ee

9 files changed

+146
-87
lines changed

.travis.yml

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: php
2+
dist: trusty
23
php:
34
- '5.4'
45
- '5.5'
@@ -7,21 +8,35 @@ php:
78
- '7.1'
89
# - hhvm # on Trusty only
910
# - nightly
11+
cache:
12+
directories:
13+
- node_modules
14+
- vendor
15+
16+
matrix:
17+
include:
18+
- php: '5.6'
19+
env: STREAM_CLIENT_ONLY=1
20+
1021
before_install:
1122
- nvm install 6.11
1223
- sudo apt-get install graphviz
24+
1325
install:
1426
# fix for jms/serializer 1.7.1 not being able to run on 5.4
1527
- if [[ ${TRAVIS_PHP_VERSION:0:3} == "5.4" ]]; then composer require jms/serializer; fi
1628
- composer install
1729
- npm install
1830
before_script:
31+
- npm stop # clean up cached PID file from prior parse-server
1932
- npm start 1>&2
2033
- sleep 3
2134
- npm run lint
2235
script:
23-
- npm run test:coverage
36+
- if [[ ${STREAM_CLIENT_ONLY} == 1 ]]; then npm run test-stream:coverage; fi
37+
- if [[ ! ${STREAM_CLIENT_ONLY} ]]; then npm run test:coverage; fi
2438
- npm run document-check && if [[ `cat "output/checkstyle.xml" | grep "<error "` != "" ]]; then exit 1; fi
39+
2540
before_deploy:
2641
- npm run document
2742
deploy:
@@ -34,3 +49,4 @@ deploy:
3449
php: '7.1'
3550
after_success:
3651
- bash <(curl -s https://codecov.io/bash)
52+

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"scripts": {
44
"test": "./vendor/bin/phpunit",
55
"test:coverage": "./vendor/bin/phpunit --coverage-clover=coverage.xml",
6+
"test-stream:coverage": "./vendor/bin/phpunit --bootstrap=./tests/bootstrap-stream.php --coverage-clover=coverage.xml",
67
"lint": "./vendor/bin/phpcs --standard=./phpcs.xml.dist ./src/Parse ./tests/Parse",
78
"lint:fix": "./vendor/bin/phpcbf --standard=./phpcs.xml.dist ./src/Parse ./tests/Parse",
89
"start" : "./node_modules/parse-server-test/run-server",

tests/Parse/Helper.php

+12-4
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,20 @@ public static function setHttpClient()
6363
// ParseStreamHttpClient
6464
//
6565

66-
if (function_exists('curl_init')) {
67-
// cURL client
68-
ParseClient::setHttpClient(new ParseCurlHttpClient());
69-
} else {
66+
global $USE_CLIENT_STREAM;
67+
68+
if (isset($USE_CLIENT_STREAM)) {
7069
// stream client
7170
ParseClient::setHttpClient(new ParseStreamHttpClient());
71+
} else {
72+
// default client set
73+
if (function_exists('curl_init')) {
74+
// cURL client
75+
ParseClient::setHttpClient(new ParseCurlHttpClient());
76+
} else {
77+
// stream client
78+
ParseClient::setHttpClient(new ParseStreamHttpClient());
79+
}
7280
}
7381
}
7482

tests/Parse/ParseClientTest.php

+44-39
Original file line numberDiff line numberDiff line change
@@ -374,17 +374,18 @@ public function testNoCurlExceptions()
374374
*/
375375
public function testCurlException()
376376
{
377+
if (function_exists('curl_init')) {
378+
ParseClient::setHttpClient(new ParseCurlHttpClient());
377379

378-
ParseClient::setHttpClient(new ParseCurlHttpClient());
379-
380-
$this->setExpectedException('\Parse\ParseException', '', 6);
380+
$this->setExpectedException('\Parse\ParseException', '', 6);
381381

382-
ParseClient::setServerURL('http://404.example.com', 'parse');
383-
ParseClient::_request(
384-
'GET',
385-
'not-a-real-endpoint-to-reach',
386-
null
387-
);
382+
ParseClient::setServerURL('http://404.example.com', 'parse');
383+
ParseClient::_request(
384+
'GET',
385+
'not-a-real-endpoint-to-reach',
386+
null
387+
);
388+
}
388389
}
389390

390391
/**
@@ -436,19 +437,21 @@ public function testBadStreamRequest()
436437
*/
437438
public function testCurlBadRequest()
438439
{
439-
$this->setExpectedException(
440-
'\Parse\ParseException',
441-
"Bad Request"
442-
);
443-
444-
ParseClient::setHttpClient(new ParseCurlHttpClient());
445-
446-
ParseClient::setServerURL('http://example.com', '/');
447-
ParseClient::_request(
448-
'GET',
449-
'',
450-
null
451-
);
440+
if (function_exists('curl_init')) {
441+
$this->setExpectedException(
442+
'\Parse\ParseException',
443+
"Bad Request"
444+
);
445+
446+
ParseClient::setHttpClient(new ParseCurlHttpClient());
447+
448+
ParseClient::setServerURL('http://example.com', '/');
449+
ParseClient::_request(
450+
'GET',
451+
'',
452+
null
453+
);
454+
}
452455
}
453456

454457
/**
@@ -476,23 +479,25 @@ public function testGetDefaultHttpClient()
476479
*/
477480
public function testCurlCAFile()
478481
{
479-
// set a curl client
480-
ParseClient::setHttpClient(new ParseCurlHttpClient());
481-
482-
// not a real ca file, just testing setting
483-
ParseClient::setCAFile("not-real-ca-file");
484-
485-
$this->setExpectedException(
486-
'\Parse\ParseException',
487-
"Bad Request"
488-
);
489-
490-
ParseClient::setServerURL('http://example.com', '/');
491-
ParseClient::_request(
492-
'GET',
493-
'',
494-
null
495-
);
482+
if (function_exists('curl_init')) {
483+
// set a curl client
484+
ParseClient::setHttpClient(new ParseCurlHttpClient());
485+
486+
// not a real ca file, just testing setting
487+
ParseClient::setCAFile("not-real-ca-file");
488+
489+
$this->setExpectedException(
490+
'\Parse\ParseException',
491+
"Bad Request"
492+
);
493+
494+
ParseClient::setServerURL('http://example.com', '/');
495+
ParseClient::_request(
496+
'GET',
497+
'',
498+
null
499+
);
500+
}
496501
}
497502

498503
/**

tests/Parse/ParseCurlHttpClientTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ class ParseCurlHttpClientTest extends \PHPUnit_Framework_TestCase
1414
{
1515
public function testResponseStatusCode()
1616
{
17-
$client = new ParseCurlHttpClient();
18-
$client->setup();
19-
$client->send("http://example.com");
17+
if (function_exists('curl_init')) {
18+
$client = new ParseCurlHttpClient();
19+
$client->setup();
20+
$client->send("http://example.com");
2021

21-
$this->assertEquals(200, $client->getResponseStatusCode());
22+
$this->assertEquals(200, $client->getResponseStatusCode());
23+
}
2224
}
2325
}

tests/Parse/ParseObjectTest.php

+24-20
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,17 @@ public function testDeleteStream()
112112

113113
public function testDeleteCurl()
114114
{
115-
ParseClient::setHttpClient(new ParseCurlHttpClient());
115+
if (function_exists('curl_init')) {
116+
ParseClient::setHttpClient(new ParseCurlHttpClient());
116117

117-
$obj = ParseObject::create('TestObject');
118-
$obj->set('foo', 'bar');
119-
$obj->save();
120-
$obj->destroy();
121-
$query = new ParseQuery('TestObject');
122-
$this->setExpectedException('Parse\ParseException', 'Object not found');
123-
$out = $query->get($obj->getObjectId());
118+
$obj = ParseObject::create('TestObject');
119+
$obj->set('foo', 'bar');
120+
$obj->save();
121+
$obj->destroy();
122+
$query = new ParseQuery('TestObject');
123+
$this->setExpectedException('Parse\ParseException', 'Object not found');
124+
$out = $query->get($obj->getObjectId());
125+
}
124126
}
125127

126128
public function testFind()
@@ -959,19 +961,21 @@ public function testSaveAllStream()
959961

960962
public function testSaveAllCurl()
961963
{
962-
ParseClient::setHttpClient(new ParseCurlHttpClient());
963-
964-
Helper::clearClass('TestObject');
965-
$objs = [];
966-
for ($i = 1; $i <= 90; $i++) {
967-
$obj = ParseObject::create('TestObject');
968-
$obj->set('test', 'test');
969-
$objs[] = $obj;
964+
if (function_exists('curl_init')) {
965+
ParseClient::setHttpClient(new ParseCurlHttpClient());
966+
967+
Helper::clearClass('TestObject');
968+
$objs = [];
969+
for ($i = 1; $i <= 90; $i++) {
970+
$obj = ParseObject::create('TestObject');
971+
$obj->set('test', 'test');
972+
$objs[] = $obj;
973+
}
974+
ParseObject::saveAll($objs);
975+
$query = new ParseQuery('TestObject');
976+
$result = $query->find();
977+
$this->assertEquals(90, count($result));
970978
}
971-
ParseObject::saveAll($objs);
972-
$query = new ParseQuery('TestObject');
973-
$result = $query->find();
974-
$this->assertEquals(90, count($result));
975979
}
976980

977981
/**

tests/Parse/ParseSchemaTest.php

+21-19
Original file line numberDiff line numberDiff line change
@@ -162,26 +162,28 @@ public function testUpdateSchemaStream()
162162

163163
public function testUpdateSchemaCurl()
164164
{
165-
ParseClient::setHttpClient(new ParseCurlHttpClient());
166-
167-
// create
168-
$schema = self::$schema;
169-
$schema->addString('name');
170-
$schema->save();
171-
// update
172-
$schema->deleteField('name');
173-
$schema->addNumber('quantity');
174-
$schema->addField('status', 'Boolean');
175-
$schema->update();
176-
// get
177-
$getSchema = new ParseSchema('SchemaTest');
178-
$result = $getSchema->get();
179-
180-
if (isset($result['fields']['name'])) {
181-
$this->fail('Field not deleted in update action');
165+
if (function_exists('curl_init')) {
166+
ParseClient::setHttpClient(new ParseCurlHttpClient());
167+
168+
// create
169+
$schema = self::$schema;
170+
$schema->addString('name');
171+
$schema->save();
172+
// update
173+
$schema->deleteField('name');
174+
$schema->addNumber('quantity');
175+
$schema->addField('status', 'Boolean');
176+
$schema->update();
177+
// get
178+
$getSchema = new ParseSchema('SchemaTest');
179+
$result = $getSchema->get();
180+
181+
if (isset($result['fields']['name'])) {
182+
$this->fail('Field not deleted in update action');
183+
}
184+
$this->assertNotNull($result['fields']['quantity']);
185+
$this->assertNotNull($result['fields']['status']);
182186
}
183-
$this->assertNotNull($result['fields']['quantity']);
184-
$this->assertNotNull($result['fields']['status']);
185187
}
186188

187189
public function testUpdateWrongFieldType()

tests/bootstrap-stream.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
/*
4+
* Used by the PHPUnit Test Suite to load dependencies and configure the main
5+
* application path.
6+
*
7+
* Additionally indicates that the stream client should be used when possible
8+
*/
9+
10+
namespace Parse;
11+
12+
require_once dirname(__DIR__).'/vendor/autoload.php';
13+
14+
define('APPLICATION_PATH', dirname(__DIR__));
15+
16+
// use the steam client
17+
$USE_CLIENT_STREAM = true;
18+
19+
echo "[ testing with stream client ]\n";

tests/bootstrap.php

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@
1010
require_once dirname(__DIR__).'/vendor/autoload.php';
1111

1212
define('APPLICATION_PATH', dirname(__DIR__));
13+
14+
echo "[ testing with curl client ]\n";

0 commit comments

Comments
 (0)