Skip to content
This repository was archived by the owner on Oct 29, 2025. It is now read-only.

Commit e9fa22b

Browse files
authored
Merge pull request #13 from MichaelJ2324/master
Fixed Issue #12 + PHP 5.5+ Testing
2 parents 4db1fc5 + c7a5b7f commit e9fa22b

File tree

8 files changed

+47
-16
lines changed

8 files changed

+47
-16
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.iml
22
.idea/
33
vendor/
4+
5+
composer.lock

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ language: php
33
php:
44
- '5.3'
55
- '5.4'
6+
- '5.5'
7+
- '5.6'
8+
- '7.0'
9+
- '7.1'
610

711
install:
812
- composer require satooshi/php-coveralls:~1.0@stable
@@ -13,7 +17,7 @@ before_script:
1317
- composer install --prefer-source --no-interaction --dev
1418

1519
script:
16-
- phpunit --coverage-clover build/logs/clover.xml
20+
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
1721

1822
after_success:
1923
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;'

src/Endpoint/POST/ModuleRecordFileField.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ protected function configureData($data)
6464
protected function setFileFieldValue($value)
6565
{
6666
if (version_compare(PHP_VERSION, '5.5.0') >= 0){
67-
$value = new \CURLFile($value);
67+
if (!($value instanceof \CURLFile)){
68+
$value = str_replace("@",'',$value);
69+
$value = new \CURLFile($value);
70+
}
6871
} else {
6972
if (strpos($value, '@') === false) {
7073
$value = '@'.$value;

src/Helpers/Helpers.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ class Helpers
1919
public static function configureAPIURL($instance, $version = null)
2020
{
2121
$url = 0;
22-
$instance = strtolower(rtrim($instance, "/"));
2322
$version = ($version === null ? self::API_VERSION : intval($version));
24-
if (preg_match('/^(http|https):\/\//i', $instance) === 0) {
25-
$instance = "http://".$instance;
26-
}
2723
$instance = preg_replace('/\/rest\/v\d+/', '', $instance);
28-
$url = $instance.sprintf(self::API_URL, $version);
24+
$url = rtrim($instance,"/").sprintf(self::API_URL, $version);
25+
if (preg_match('/^(http|https):\/\//i', $url) === 0) {
26+
$url = "http://".$url;
27+
}
2928
return $url;
3029
}
3130

tests/Clients/AbstractSugarClientTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,14 @@ public function testSetServer($Stub){
122122
$Stub->setServer('https://tester.test.com');
123123
$this->assertEquals('https://tester.test.com',$Stub->getServer());
124124
$this->assertEquals("https://tester.test.com/rest/v10/",$Stub->getAPIUrl());
125+
$Stub->setServer('https://tester.test.com/SugarTest');
126+
$this->assertEquals('https://tester.test.com/SugarTest',$Stub->getServer());
127+
$this->assertEquals("https://tester.test.com/SugarTest/rest/v10/",$Stub->getAPIUrl());
125128
$Stub->setServer($this->server);
126129
$this->assertEquals($this->server,$Stub->getServer());
127130
$this->assertEquals("http://".$this->server."/rest/v10/",$Stub->getAPIUrl());
128131

132+
129133
return $Stub;
130134
}
131135

tests/Endpoint/POST/ModuleRecordFileFieldTest.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public static function tearDownAfterClass()
2929
'1234abc',
3030
'filename'
3131
);
32-
protected $data;
32+
protected $data = '';
3333

3434
public function setUp()
3535
{
36-
$this->data = __FILE__;
36+
$this->data = realpath(__FILE__);
3737
parent::setUp();
3838
}
3939

@@ -51,11 +51,20 @@ public function testConfigureData(){
5151
$EP = new ModuleRecordFileField($this->url,$this->options);
5252
$EP->execute($this->data);
5353

54-
$configuredData = array(
55-
'filename' => '@'.__FILE__,
56-
'format' => 'sugar-html-json',
57-
'delete_if_fails' => false
58-
);
54+
if (version_compare(PHP_VERSION, '5.5.0') >= 0){
55+
$configuredData = array(
56+
'filename' => new \CURLFile(__FILE__),
57+
'format' => 'sugar-html-json',
58+
'delete_if_fails' => false
59+
);
60+
} else {
61+
$configuredData = array(
62+
'filename' => '@'.__FILE__,
63+
'format' => 'sugar-html-json',
64+
'delete_if_fails' => false
65+
);
66+
}
67+
5968
$this->assertEquals($configuredData,$EP->getData());
6069
unset($EP);
6170

@@ -74,6 +83,7 @@ public function testConfigureData(){
7483
unset($EP);
7584

7685
$EP = new ModuleRecordFileField($this->url,$this->options);
86+
7787
$data = array(
7888
'filename' => '@'.$this->data,
7989
'delete_if_fails' => true

tests/Helpers/HelpersTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ public function testConfigureAPIUrl()
7575
$this->assertEquals('http://localhost/rest/v10/',Helpers::configureAPIURL('http://localhost/rest/v10/rest/v10/rest/v10','10'));
7676
$this->assertEquals('http://localhost/rest/v10/',Helpers::configureAPIURL('http://localhost/rest/v10/rest/v10/rest/v10',10));
7777
$this->assertEquals('http://localhost/rest/v11/',Helpers::configureAPIURL('http://localhost/rest/v10/rest/v10/rest/v10',11));
78+
$this->assertEquals('https://localhost/SugarTest/rest/v11/',Helpers::configureAPIURL('https://localhost/SugarTest/rest/v10/',11));
79+
$this->assertEquals('http://localhost/Sugar/Test/rest/v10/',Helpers::configureAPIURL('http://localhost/Sugar/Test/rest/v10/rest/v10/rest/v10','10'));
80+
$this->assertEquals('http://localhost/SugarTest/rest/v10/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10',10));
81+
$this->assertEquals('http://localhost/SugarTest/rest/v11/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10',11));
82+
7883
}
7984

8085
/**

tests/Request/AbstractRequestTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,9 @@ public function testCurl(){
203203
$this->assertEquals(RequestStub::STATUS_INIT,$Stub->getCurlStatus());
204204
$Stub->close();
205205
$this->assertEquals(RequestStub::STATUS_CLOSED,$Stub->getCurlStatus());
206-
$this->assertNotEquals('resource',gettype($CurlObject));
206+
if (strpos(PHP_VERSION,'7.0') === FALSE) {
207+
$this->assertNotEquals('curl', get_resource_type($CurlObject));
208+
}
207209
$Stub->start();
208210
$this->assertEquals(RequestStub::STATUS_INIT,$Stub->getCurlStatus());
209211
$this->assertNotEquals($CurlObject,$Stub->getCurlObject());
@@ -237,6 +239,8 @@ public function testDestructor(){
237239
$Stub = new RequestStub($this->url);
238240
$CurlObject = $Stub->getCurlObject();
239241
unset($Stub);
240-
$this->assertNotEquals('resource',gettype($CurlObject));
242+
if (strpos(PHP_VERSION,'7.0') === FALSE){
243+
$this->assertEquals(FALSE,is_resource($CurlObject));
244+
}
241245
}
242246
}

0 commit comments

Comments
 (0)