Skip to content

Commit

Permalink
Merge pull request #13 from MichaelJ2324/master
Browse files Browse the repository at this point in the history
Fixed Issue #12 + PHP 5.5+ Testing
  • Loading branch information
geraldclark committed Mar 25, 2017
2 parents 4db1fc5 + c7a5b7f commit e9fa22b
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.iml
.idea/
vendor/

composer.lock
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ language: php
php:
- '5.3'
- '5.4'
- '5.5'
- '5.6'
- '7.0'
- '7.1'

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

script:
- phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml

after_success:
- sh -c 'if [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php vendor/bin/coveralls -v; fi;'
5 changes: 4 additions & 1 deletion src/Endpoint/POST/ModuleRecordFileField.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ protected function configureData($data)
protected function setFileFieldValue($value)
{
if (version_compare(PHP_VERSION, '5.5.0') >= 0){
$value = new \CURLFile($value);
if (!($value instanceof \CURLFile)){
$value = str_replace("@",'',$value);
$value = new \CURLFile($value);
}
} else {
if (strpos($value, '@') === false) {
$value = '@'.$value;
Expand Down
9 changes: 4 additions & 5 deletions src/Helpers/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ class Helpers
public static function configureAPIURL($instance, $version = null)
{
$url = 0;
$instance = strtolower(rtrim($instance, "/"));
$version = ($version === null ? self::API_VERSION : intval($version));
if (preg_match('/^(http|https):\/\//i', $instance) === 0) {
$instance = "http://".$instance;
}
$instance = preg_replace('/\/rest\/v\d+/', '', $instance);
$url = $instance.sprintf(self::API_URL, $version);
$url = rtrim($instance,"/").sprintf(self::API_URL, $version);
if (preg_match('/^(http|https):\/\//i', $url) === 0) {
$url = "http://".$url;
}
return $url;
}

Expand Down
4 changes: 4 additions & 0 deletions tests/Clients/AbstractSugarClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,14 @@ public function testSetServer($Stub){
$Stub->setServer('https://tester.test.com');
$this->assertEquals('https://tester.test.com',$Stub->getServer());
$this->assertEquals("https://tester.test.com/rest/v10/",$Stub->getAPIUrl());
$Stub->setServer('https://tester.test.com/SugarTest');
$this->assertEquals('https://tester.test.com/SugarTest',$Stub->getServer());
$this->assertEquals("https://tester.test.com/SugarTest/rest/v10/",$Stub->getAPIUrl());
$Stub->setServer($this->server);
$this->assertEquals($this->server,$Stub->getServer());
$this->assertEquals("http://".$this->server."/rest/v10/",$Stub->getAPIUrl());


return $Stub;
}

Expand Down
24 changes: 17 additions & 7 deletions tests/Endpoint/POST/ModuleRecordFileFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public static function tearDownAfterClass()
'1234abc',
'filename'
);
protected $data;
protected $data = '';

public function setUp()
{
$this->data = __FILE__;
$this->data = realpath(__FILE__);
parent::setUp();
}

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

$configuredData = array(
'filename' => '@'.__FILE__,
'format' => 'sugar-html-json',
'delete_if_fails' => false
);
if (version_compare(PHP_VERSION, '5.5.0') >= 0){
$configuredData = array(
'filename' => new \CURLFile(__FILE__),
'format' => 'sugar-html-json',
'delete_if_fails' => false
);
} else {
$configuredData = array(
'filename' => '@'.__FILE__,
'format' => 'sugar-html-json',
'delete_if_fails' => false
);
}

$this->assertEquals($configuredData,$EP->getData());
unset($EP);

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

$EP = new ModuleRecordFileField($this->url,$this->options);

$data = array(
'filename' => '@'.$this->data,
'delete_if_fails' => true
Expand Down
5 changes: 5 additions & 0 deletions tests/Helpers/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ public function testConfigureAPIUrl()
$this->assertEquals('http://localhost/rest/v10/',Helpers::configureAPIURL('http://localhost/rest/v10/rest/v10/rest/v10','10'));
$this->assertEquals('http://localhost/rest/v10/',Helpers::configureAPIURL('http://localhost/rest/v10/rest/v10/rest/v10',10));
$this->assertEquals('http://localhost/rest/v11/',Helpers::configureAPIURL('http://localhost/rest/v10/rest/v10/rest/v10',11));
$this->assertEquals('https://localhost/SugarTest/rest/v11/',Helpers::configureAPIURL('https://localhost/SugarTest/rest/v10/',11));
$this->assertEquals('http://localhost/Sugar/Test/rest/v10/',Helpers::configureAPIURL('http://localhost/Sugar/Test/rest/v10/rest/v10/rest/v10','10'));
$this->assertEquals('http://localhost/SugarTest/rest/v10/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10',10));
$this->assertEquals('http://localhost/SugarTest/rest/v11/',Helpers::configureAPIURL('http://localhost/SugarTest/rest/v10/rest/v10/rest/v10',11));

}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/Request/AbstractRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,9 @@ public function testCurl(){
$this->assertEquals(RequestStub::STATUS_INIT,$Stub->getCurlStatus());
$Stub->close();
$this->assertEquals(RequestStub::STATUS_CLOSED,$Stub->getCurlStatus());
$this->assertNotEquals('resource',gettype($CurlObject));
if (strpos(PHP_VERSION,'7.0') === FALSE) {
$this->assertNotEquals('curl', get_resource_type($CurlObject));
}
$Stub->start();
$this->assertEquals(RequestStub::STATUS_INIT,$Stub->getCurlStatus());
$this->assertNotEquals($CurlObject,$Stub->getCurlObject());
Expand Down Expand Up @@ -237,6 +239,8 @@ public function testDestructor(){
$Stub = new RequestStub($this->url);
$CurlObject = $Stub->getCurlObject();
unset($Stub);
$this->assertNotEquals('resource',gettype($CurlObject));
if (strpos(PHP_VERSION,'7.0') === FALSE){
$this->assertEquals(FALSE,is_resource($CurlObject));
}
}
}

0 comments on commit e9fa22b

Please sign in to comment.