├── .gitignore ├── .travis.yml ├── README.md ├── bootstrap.php ├── composer.json ├── docs └── soap │ ├── company │ ├── CompanyAPI_1.wsdl │ └── wsdl-report.html │ ├── configuration │ ├── ConfigurationAPI_1.wsdl │ └── wsdl-report.html │ ├── contact │ ├── ContactAPI_1.wsdl │ └── wsdl-report.html │ ├── reporting │ ├── ReportingAPI_1.wsdl │ └── wsdl-report.html │ └── service_ticket │ ├── ServiceTicketApi_1.wsdl │ └── wsdl-report.html ├── integrationTest.sh ├── phpunit.xml ├── src └── LabtechSoftware │ └── ConnectwisePsaSdk │ ├── ApiException.php │ ├── Company.php │ ├── ConfigLoader.php │ ├── Configuration.php │ ├── ConnectWiseApi.php │ ├── ConnectwiseApiFactory.php │ ├── Contact.php │ ├── Document.php │ ├── IntegrationIO.php │ ├── Laravel │ ├── ConnectwiseFactory.php │ └── ConnectwiseSdkServiceProvider.php │ ├── Member.php │ ├── Overrides │ └── SoapClient.php │ ├── Reporting.php │ ├── Rest │ ├── Client.php │ ├── ContactApi.php │ └── MarketingContactApi.php │ ├── ServiceTicket.php │ ├── SoapApiRequester.php │ └── config │ └── config.php └── tests └── ConnectWise ├── integration ├── CompanyIntegrationTest.php ├── ConfigurationIntegrationTest.php ├── ContactIntegrationTest.php ├── DocumentIntegrationTest.php ├── PsaTestCase.php ├── ReportingIntegrationTest.php └── ServiceTicketIntegrationTest.php └── unit ├── ApiExceptionTest.php ├── CompanyTest.php ├── ConfigLoaderTest.php ├── ConfigurationTest.php ├── ConnectwiseApiFactoryTest.php ├── ContactTest.php ├── DocumentTest.php ├── ReportingTest.php ├── ServiceTicketTest.php └── SoapApiRequesterTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | # Numerous always-ignore extensions 2 | *.diff 3 | *.err 4 | *.orig 5 | *.log 6 | *.rej 7 | *.swo 8 | *.swp 9 | *.vi 10 | *~ 11 | *.sass-cache 12 | 13 | # OS or Editor folders 14 | .DS_Store 15 | Thumbs.db 16 | .cache 17 | .project 18 | .settings 19 | .tmproj 20 | *.esproj 21 | nbproject 22 | 23 | # Dreamweaver added files 24 | _notes 25 | dwsync.xml 26 | 27 | # Komodo 28 | *.komodoproject 29 | .komodotools 30 | 31 | # etc 32 | .hg 33 | .svn 34 | .CVS 35 | intermediate 36 | publish 37 | .idea 38 | sftp-config.json 39 | /app/config/app.php 40 | /app/config/workbench.php 41 | /app/config/database.php 42 | /bootstrap/compiled.php 43 | /vendor 44 | /workbench 45 | composer.phar 46 | composer.lock 47 | test.php 48 | /config/credentials.php -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.3 5 | - 5.4 6 | - 5.5 7 | 8 | before_script: 9 | - curl -s http://getcomposer.org/installer | php 10 | - php composer.phar install --dev 11 | 12 | script: phpunit -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Unofficial ConnectWise PSA Api SDK [![Build Status](https://travis-ci.org/LabTechSoftware/ConnectWisePSA-SDK.png)](https://travis-ci.org/LabTechSoftware/ConnectWisePSA-SDK) 2 | ================== 3 | 4 | The beginnings of an unofficial ConnectWise PSA Api SDK :) -------------------------------------------------------------------------------- /bootstrap.php: -------------------------------------------------------------------------------- 1 | =5.3.0", 12 | "guzzlehttp/guzzle": "6.1.*" 13 | }, 14 | "require-dev": { 15 | "mikey179/vfsStream": "1.*" 16 | }, 17 | "autoload": { 18 | "psr-0": { 19 | "LabtechSoftware\\ConnectwisePsaSdk": "src/" 20 | } 21 | }, 22 | "minimum-stability": "dev" 23 | } 24 | -------------------------------------------------------------------------------- /docs/soap/reporting/ReportingAPI_1.wsdl: -------------------------------------------------------------------------------- 1 | 2 | 3 | ConnectWise Reporting API 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | Gets the list of available reports. 204 | 205 | 206 | 207 | 208 | Gets the list of fields for a particular report. 209 | 210 | 211 | 212 | 213 | Gets the list of reports accessible via the customer portal. 214 | 215 | 216 | 217 | 218 | Run a protal report with the given set of condiitons. 219 | 220 | 221 | 222 | 223 | Runs a particular report with a given set of conditions. 224 | 225 | 226 | 227 | 228 | Runs a particular report with a given set of conditions. Returnss the # of records that would be returned. 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | ConnectWise Reporting API 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | -------------------------------------------------------------------------------- /integrationTest.sh: -------------------------------------------------------------------------------- 1 | #------------------------------------------------------------------ 2 | # The export statements below are NOT REQUIRED to run integration 3 | # tests but instead can be set optionally to override the default 4 | # values found in the config.php file included in this package 5 | #------------------------------------------------------------------ 6 | # export SOAP_VERSION = 1 7 | # export EXCEPTIONS = true 8 | # export TRACE = 1 9 | # export CACHE_WSDL = 1 10 | # export CW_API_MAIN='https://%s/v4_6_release/apis/1.5/%s.asmx?wsdl' 11 | #------------------------------------------------------------------ 12 | # The export statements below are REQUIRED to run integration tests 13 | #------------------------------------------------------------------ 14 | #export DOMAIN="" 15 | #export COMPANYID="" 16 | #export INTEGRATORLOGINID="" 17 | #export INTEGRATORPASSWORD="" 18 | phpunit tests/ConnectWise/integration -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | ./tests/ConnectWise/integration 16 | 17 | 18 | ./tests/ConnectWise/unit 19 | 20 | 21 | ./tests/ConnectWise 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/ApiException.php: -------------------------------------------------------------------------------- 1 | client = $client; 15 | } 16 | 17 | 18 | /** 19 | * Add or update a company to/in CW 20 | * 21 | * @throws ApiException 22 | * @param array $company 23 | * @return array 24 | */ 25 | public function addOrUpdateCompany(array $company) 26 | { 27 | // Check for empty data array 28 | if (count($company) <= 0) { 29 | throw new ApiException('No data found in company array.'); 30 | } 31 | 32 | $params = array( 33 | 'company' => $company 34 | ); 35 | 36 | return $this->client->makeRequest('AddOrUpdateCompany', $params); 37 | } 38 | 39 | 40 | /** 41 | * Get a company by ID from CW 42 | * 43 | * @throws ApiException 44 | * @param int $companyId 45 | * @return array 46 | */ 47 | public function getCompany($companyId) 48 | { 49 | // Make sure company ID is numeric and not zero 50 | if (is_numeric($companyId) === false || $companyId <= 0) { 51 | throw new ApiException('Invalid company ID value.'); 52 | } 53 | 54 | $params = array( 55 | 'id' => $companyId 56 | ); 57 | 58 | return $this->client->makeRequest('GetCompany', $params); 59 | } 60 | 61 | /** 62 | * Delete a company by ID fom CW 63 | * 64 | * @param int $companyId 65 | * @return array 66 | * @throws ApiException 67 | */ 68 | public function deleteCompany($companyId) 69 | { 70 | if (is_numeric($companyId) === false) { 71 | throw new ApiException('Invalid company ID value.'); 72 | } 73 | 74 | $params = array( 75 | 'id' => $companyId 76 | ); 77 | 78 | return $this->client->makeRequest('DeleteCompany', $params); 79 | } 80 | 81 | 82 | /** 83 | * Finds contact information by a set of conditions 84 | * 85 | * @throws ApiException 86 | * @param int $limit 87 | * @param int $skip 88 | * @param string $orderBy 89 | * @param string $conditions 90 | * @return array 91 | */ 92 | public function findCompanies($limit = 0, $skip = 0, $orderBy = '', $conditions = '') 93 | { 94 | if (is_numeric($limit) === false) { 95 | throw new ApiException('Limit value must be numeric.'); 96 | } 97 | 98 | if (is_numeric($skip) === false) { 99 | throw new ApiException('Skip value must be numeric.'); 100 | } 101 | 102 | if (is_string($orderBy) === false) { 103 | throw new ApiException('Order by must be a string.'); 104 | } 105 | 106 | if (is_string($conditions) === false) { 107 | throw new ApiException('Conditions must be a string.'); 108 | } 109 | 110 | $params = array( 111 | 'skip' => $skip, 112 | 'conditions' => $conditions, 113 | 'orderBy' => $orderBy 114 | ); 115 | 116 | // only set limit if there is a limit, limit 0 will return no results 117 | if ($limit > 0) { 118 | $params['limit'] = $limit; 119 | } 120 | 121 | return $this->client->makeRequest('FindCompanies', $params); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/ConfigLoader.php: -------------------------------------------------------------------------------- 1 | isValidPath($config); 30 | $config = $this->load($config); 31 | } 32 | 33 | $this->validateConfigItems($config); 34 | $this->config = $config; 35 | } 36 | 37 | protected function validateConfigItems(array $configValues) 38 | { 39 | // soap array 40 | if (!array_key_exists('soap', $configValues) || !is_array($configValues['soap'])) { 41 | throw new ApiException( 42 | 'Configuration array must be indexed with soap and its type must be array' 43 | ); 44 | } 45 | 46 | if (!array_key_exists('soap_version', $configValues['soap']) || 47 | !is_integer($configValues['soap']['soap_version']) 48 | ) { 49 | throw new ApiException( 50 | 'soap array must be indexed with soap_version and its type must be integer' 51 | ); 52 | } 53 | 54 | if (!array_key_exists('exceptions', $configValues['soap']) || 55 | !is_bool($configValues['soap']['exceptions']) 56 | ) { 57 | throw new ApiException( 58 | 'soap array must be indexed with exceptions and its type must be boolean' 59 | ); 60 | } 61 | 62 | if (!array_key_exists('trace', $configValues['soap']) || !is_integer($configValues['soap']['trace'])) { 63 | throw new ApiException( 64 | 'soap array must be indexed with trace and its type must be integer' 65 | ); 66 | } 67 | 68 | if (!array_key_exists('cache_wsdl', $configValues['soap']) || 69 | !is_integer($configValues['soap']['cache_wsdl']) 70 | ) { 71 | throw new ApiException( 72 | 'soap array must be indexed with cache_wsdl and its type must be integer' 73 | ); 74 | } 75 | 76 | // url array 77 | if (!array_key_exists('url', $configValues) || !is_array($configValues['url'])) { 78 | throw new ApiException( 79 | 'Configuration array must be indexed with url and its type must be array' 80 | ); 81 | } 82 | 83 | if (!array_key_exists('cw_api_main', $configValues['url']) || 84 | !is_string($configValues['url']['cw_api_main']) || 85 | empty($configValues['url']['cw_api_main']) 86 | ) { 87 | throw new ApiException( 88 | 'url array must be indexed with cw_api_main and its type must be string' 89 | ); 90 | } 91 | 92 | // credentials array 93 | if (!array_key_exists('credentials', $configValues) ||!is_array($configValues['credentials'])) { 94 | throw new ApiException( 95 | 'Configuration array must be indexed with credentials and its type must be array' 96 | ); 97 | } 98 | 99 | if (!array_key_exists('domain', $configValues['credentials']) || 100 | !is_string($configValues['credentials']['domain']) || 101 | empty($configValues['credentials']['domain']) 102 | ) { 103 | throw new ApiException( 104 | 'credentials array must be indexed with domain and its type must be string' 105 | ); 106 | } 107 | 108 | if (!array_key_exists('CompanyId', $configValues['credentials']) || 109 | !is_string($configValues['credentials']['CompanyId']) || 110 | empty($configValues['credentials']['CompanyId']) 111 | ) { 112 | throw new ApiException( 113 | 'credentials array must be indexed with CompanyId and its type must be string' 114 | ); 115 | } 116 | 117 | if (!array_key_exists('IntegratorLoginId', $configValues['credentials']) || 118 | !is_string($configValues['credentials']['IntegratorLoginId']) || 119 | empty($configValues['credentials']['IntegratorLoginId']) 120 | ) { 121 | throw new ApiException( 122 | 'credentials array must be indexed with IntegratorLoginId and its type must be string' 123 | ); 124 | } 125 | 126 | if (!array_key_exists('IntegratorPassword', $configValues['credentials']) || 127 | !is_string($configValues['credentials']['IntegratorPassword']) || 128 | empty($configValues['credentials']['IntegratorPassword']) 129 | ) { 130 | throw new ApiException( 131 | 'credentials array must be indexed with IntegratorPassword and its type must be string' 132 | ); 133 | } 134 | 135 | return true; 136 | } 137 | 138 | /** 139 | * @param string $path 140 | * @return array 141 | * @throws ApiException 142 | */ 143 | protected function load($path = '') 144 | { 145 | $config = include $path; 146 | 147 | if (!is_array($config)) { 148 | throw new ApiException('config file is not formatted correctly'); 149 | } 150 | 151 | return $config; 152 | } 153 | 154 | protected function isValidPath($fullPath) 155 | { 156 | // Check for invalid path via is_file() 157 | // Throw exception if false (path invalid) 158 | if (is_file($fullPath) === false) { 159 | throw new ApiException('Config file not found.'); 160 | } 161 | 162 | return true; 163 | } 164 | 165 | public function getSoapOptions() 166 | { 167 | return $this->config['soap']; 168 | } 169 | 170 | public function getSoapAddress($apiName) 171 | { 172 | return sprintf($this->config['url']['cw_api_main'], $this->config['credentials']['domain'], $apiName); 173 | } 174 | 175 | public function getSoapCredentials() 176 | { 177 | return $this->config['credentials']; 178 | } 179 | } 180 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Configuration.php: -------------------------------------------------------------------------------- 1 | client = $client; 15 | } 16 | 17 | /** 18 | * Adds or updates a configuration 19 | * 20 | * @throws ApiException 21 | * @param array $config 22 | * @return array 23 | */ 24 | public function addOrUpdateConfiguration(array $config) 25 | { 26 | $params = array( 27 | 'configuration' => $config 28 | ); 29 | 30 | return $this->client->makeRequest('AddOrUpdateConfiguration', $params); 31 | } 32 | 33 | /** 34 | * Adds a configuration 35 | * 36 | * @throws ApiException 37 | * @param array $config 38 | * @return array 39 | */ 40 | public function addConfiguration(array $config) 41 | { 42 | $params = array( 43 | 'configuration' => $config 44 | ); 45 | 46 | return $this->client->makeRequest('AddConfiguration', $params); 47 | } 48 | 49 | /** 50 | * Updates a configuration 51 | * 52 | * @throws ApiException 53 | * @param array $config 54 | * @return array 55 | */ 56 | public function updateConfiguration(array $config) 57 | { 58 | $params = array( 59 | 'configuration' => $config 60 | ); 61 | 62 | return $this->client->makeRequest('UpdateConfiguration', $params); 63 | } 64 | 65 | /** 66 | * Adds or updates a configuration type 67 | * 68 | * @throws ApiException 69 | * @param array $configType 70 | * @return array 71 | */ 72 | public function addOrUpdateConfigurationType(array $configType) 73 | { 74 | $params = array( 75 | 'configurationType' => $configType 76 | ); 77 | 78 | return $this->client->makeRequest('AddOrUpdateConfigurationType', $params); 79 | } 80 | 81 | /** 82 | * Finds configuration types 83 | * 84 | * @throws ApiException 85 | * @param int $limit 86 | * @param int $skip 87 | * @param mixed string $conditions 88 | * @param string $orderBy 89 | * @return array 90 | */ 91 | public function findConfigurationTypes($limit = 0, $skip = 0, $conditions = '', $orderBy = '') 92 | { 93 | if (is_numeric($limit) === false) { 94 | throw new ApiException('Limit value must be numeric.'); 95 | } 96 | 97 | if (is_numeric($skip) === false) { 98 | throw new ApiException('Skip value must be numeric.'); 99 | } 100 | 101 | if (is_string($conditions) === false) { 102 | throw new ApiException('Conditions must be a string.'); 103 | } 104 | 105 | if (is_string($orderBy) === false) { 106 | throw new ApiException('Order by must be a string.'); 107 | } 108 | 109 | $params = array( 110 | 'skip' => $skip, 111 | 'conditions' => $conditions, 112 | 'orderBy' => $orderBy 113 | ); 114 | 115 | // only set limit if there is a limit, limit 0 will return no results 116 | if ($limit > 0) { 117 | $params['limit'] = $limit; 118 | } 119 | 120 | return $this->client->makeRequest('FindConfigurationTypes', $params); 121 | } 122 | 123 | /** 124 | * Find configurations 125 | * 126 | * @throws ApiException 127 | * @param int $limit 128 | * @param int $skip 129 | * @param mixed string $conditions 130 | * @param string $orderBy 131 | * @return array 132 | */ 133 | public function findConfigurations($limit = 0, $skip = 0, $conditions = '', $orderBy = '') 134 | { 135 | if (is_numeric($limit) === false) { 136 | throw new ApiException('Limit value must be numeric.'); 137 | } 138 | 139 | if (is_numeric($skip) === false) { 140 | throw new ApiException('Skip value must be numeric.'); 141 | } 142 | 143 | if (is_string($conditions) === false) { 144 | throw new ApiException('Conditions must be a string.'); 145 | } 146 | 147 | if (is_string($orderBy) === false) { 148 | throw new ApiException('Order by must be a string.'); 149 | } 150 | 151 | $params = array( 152 | 'skip' => $skip, 153 | 'conditions' => $conditions, 154 | 'orderBy' => $orderBy 155 | ); 156 | 157 | // only set limit if there is a limit, limit 0 will return no results 158 | if ($limit > 0) { 159 | $params['limit'] = $limit; 160 | } 161 | 162 | return $this->client->makeRequest('FindConfigurations', $params); 163 | } 164 | 165 | /** 166 | * Gets a count of available configurations. Optionally filters by the supplied conditions. 167 | * 168 | * @throws ApiException 169 | * @param boolean $isOpen 170 | * @param string $conditions 171 | * @return array 172 | */ 173 | public function findConfigurationsCount($isOpen = false, $conditions = '') 174 | { 175 | if (is_bool($isOpen) === false) { 176 | throw new ApiException('Is Open param must be boolean.'); 177 | } 178 | 179 | if (is_string($conditions) === false) { 180 | throw new ApiException('Conditions must be a string.'); 181 | } 182 | 183 | $params = array( 184 | 'conditions' => $conditions, 185 | 'isOpen' => $isOpen 186 | ); 187 | 188 | return $this->client->makeRequest('FindConfigurationsCount', $params); 189 | } 190 | 191 | /** 192 | * Gets a configuration by database record id. 193 | * If no configuration exists with the given id, an empty array is returned 194 | * 195 | * @throws ApiException 196 | * @param int $id 197 | * @return array 198 | */ 199 | public function getConfiguration($id) 200 | { 201 | if (is_numeric($id) === false) { 202 | throw new ApiException('Configuration ID must be numeric.'); 203 | } 204 | 205 | $params = array( 206 | 'id' => $id 207 | ); 208 | 209 | return $this->client->makeRequest('GetConfiguration', $params); 210 | } 211 | 212 | /** 213 | * Gets a configuration type by database record id. 214 | * If no configuration exists with the given id, an empty array is returned 215 | * 216 | * @throws ApiException 217 | * @param int $id 218 | * @return array 219 | */ 220 | public function getConfigurationType($id) 221 | { 222 | if (is_numeric($id) === false) { 223 | throw new ApiException('ConfigurationType ID must be numeric.'); 224 | } 225 | 226 | $params = array( 227 | 'id' => $id 228 | ); 229 | 230 | return $this->client->makeRequest('GetConfigurationType', $params); 231 | } 232 | 233 | /** 234 | * Delete an existing configuration 235 | * 236 | * @throws ApiException 237 | * @param int $id 238 | * @return array 239 | */ 240 | public function deleteConfiguration($id) 241 | { 242 | if (is_numeric($id) === false) { 243 | throw new ApiException('Configuration ID must be numeric.'); 244 | } 245 | 246 | $params = array( 247 | 'id' => $id 248 | ); 249 | 250 | return $this->client->makeRequest('DeleteConfiguration', $params); 251 | } 252 | 253 | /** 254 | * Deletes an existing configuration type 255 | * 256 | * @throws ApiException 257 | * @param int $id 258 | * @return array 259 | */ 260 | public function deleteConfigurationType($id) 261 | { 262 | if (is_numeric($id) === false) { 263 | throw new ApiException('ConfigurationType ID must be numeric.'); 264 | } 265 | 266 | $params = array( 267 | 'id' => $id 268 | ); 269 | 270 | return $this->client->makeRequest('DeleteConfigurationType', $params); 271 | } 272 | 273 | /** 274 | * Deletes a question from an existing configuration type 275 | * 276 | * @throws ApiException 277 | * @param int $id 278 | * @return array 279 | */ 280 | public function deleteConfigurationTypeQuestion($id) 281 | { 282 | if (is_numeric($id) === false) { 283 | throw new ApiException('ConfigurationTypeQuestion ID must be numeric.'); 284 | } 285 | 286 | $params = array( 287 | 'id' => $id 288 | ); 289 | 290 | return $this->client->makeRequest('DeleteConfigurationTypeQuestion', $params); 291 | } 292 | 293 | /** 294 | * Deletes a possible response from an existing configuration type question 295 | * 296 | * @throws ApiException 297 | * @param int $id 298 | * @return array 299 | */ 300 | public function deletePossibleResponse($id) 301 | { 302 | if (is_numeric($id) === false) { 303 | throw new ApiException('PossibleResponse ID must be numeric.'); 304 | } 305 | 306 | $params = array( 307 | 'id' => $id 308 | ); 309 | 310 | return $this->client->makeRequest('DeletePossibleResponse', $params); 311 | } 312 | } 313 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/ConnectWiseApi.php: -------------------------------------------------------------------------------- 1 | wireDependencies($api.'API', $config)); 35 | } 36 | 37 | /** 38 | * Load the config file, set up a SoapClient instance and prepare for a request 39 | * 40 | * @throws \InvalidArgumentException 41 | * @param string $apiName 42 | * @param string|array $config 43 | * @return \LabtechSoftware\ConnectwisePsaSdk\SoapApiRequester 44 | */ 45 | private function wireDependencies($apiName, $config) 46 | { 47 | if (is_string($apiName) === false || strlen($apiName) < 1) { 48 | throw new InvalidArgumentException( 49 | 'Expecting string value with required amount of characters.' 50 | ); 51 | } 52 | 53 | // Load the config file using the set path 54 | $cl = new ConfigLoader(); 55 | $cl->loadConfig($config); 56 | 57 | // New SoapClient instance 58 | $soap = new Overrides\SoapClient( 59 | $cl->getSoapAddress($apiName), 60 | $cl->getSoapOptions() 61 | ); 62 | 63 | return new SoapApiRequester($soap, $cl); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Contact.php: -------------------------------------------------------------------------------- 1 | client = $client; 15 | } 16 | 17 | /** 18 | * Adds a contact to a specified group 19 | * 20 | * @todo Need a valid group id to finish testing this 21 | * 22 | * @throws ApiException 23 | * @param int $contactId 24 | * @param int $groupId 25 | * @param string $note 26 | * @return array 27 | */ 28 | public function addContactToGroup($contactId, $groupId, $note = '') 29 | { 30 | if (is_numeric($contactId) === false) { 31 | throw new ApiException('Contact ID must be numeric.'); 32 | } 33 | 34 | if (is_numeric($groupId) === false) { 35 | throw new ApiException('Group ID must be numeric.'); 36 | } 37 | 38 | if (is_string($note) === false) { 39 | throw new ApiException('Note must be a string.'); 40 | } 41 | 42 | $params = array( 43 | 'contactID' => $contactId, 44 | 'groupID' => $groupId, 45 | 'transactionNote' => $note 46 | ); 47 | 48 | return $this->client->makeRequest('AddContactToGroup', $params); 49 | } 50 | 51 | /** 52 | * Adds or updates a contact 53 | * Set RecId & Id to 0 to add new contact. If non-zero, the existing contact with that Id is updated. 54 | * 55 | * @throws ApiException 56 | * @param array $contactData 57 | * @return array 58 | */ 59 | public function addOrUpdateContact(array $contactData) 60 | { 61 | $params = array( 62 | 'contact' => $contactData 63 | ); 64 | 65 | return $this->client->makeRequest('AddOrUpdateContact', $params); 66 | } 67 | 68 | /** 69 | * Adds or updates a contact's communication item 70 | * If the communicationItem id (inside of $commItemData) is 0, the communication item is added. 71 | * If non-zero, the existing communicationItem with that Id is updated. 72 | * 73 | * @throws ApiException 74 | * @param int $contactId 75 | * @param array $commItemData 76 | * @return array 77 | */ 78 | public function addOrUpdateContactCommunicationItem($contactId, array $commItemData) 79 | { 80 | if (is_numeric($contactId) === false) { 81 | throw new ApiException('Contact ID must be numeric.'); 82 | } 83 | 84 | $params = array( 85 | 'contactId' => $contactId, 86 | 'ContactMethod' => $commItemData 87 | ); 88 | 89 | return $this->client->makeRequest('AddOrUpdateContactCommunicationItem', $params); 90 | } 91 | 92 | /** 93 | * Adds or updates a contact note. 94 | * If the note Id is 0, and the contactId is set; the note is added. 95 | * If non-zero, the existing note with that Id is updated. 96 | * 97 | * @throws ApiException 98 | * @param int $contactId 99 | * @param array $note 100 | * @return array 101 | */ 102 | public function addOrUpdateContactNote($contactId, array $note) 103 | { 104 | if (is_numeric($contactId) === false) { 105 | throw new ApiException('Contact ID must be numeric.'); 106 | } 107 | 108 | $params = array( 109 | 'contactId' => $contactId, 110 | 'note' => $note 111 | ); 112 | 113 | return $this->client->makeRequest('AddOrUpdateContactNote', $params); 114 | } 115 | 116 | 117 | /** 118 | * @todo Disabled until CW fixes authentication issues -- DO NOT USE THIS METHOD! 119 | * @throws ApiException 120 | * 121 | * f/ Marc: 122 | * This is a very dangerous method right now. You should not use this unless you know what it does. 123 | * I recommend if your trying to authenticate via portal password you use the FindContacts method 124 | * @param array $params 125 | */ 126 | public static function authenticate(array $params) 127 | { 128 | throw new ApiException('Authenticate method unavailable.'); 129 | 130 | /* 131 | $params2['email'] = $params['email']; 132 | $params2['loginpw'] = $params['loginpw']; 133 | $params2['portalName'] = $params['portalName']; 134 | 135 | try 136 | { 137 | $results = $this->call('Authenticate', $params2); 138 | if(is_soap_fault($results)) { throw $results; } 139 | return $results->AuthenticateResult; 140 | } 141 | catch(SoapFault $fault) { return $fault; } 142 | */ 143 | } 144 | 145 | 146 | 147 | /** 148 | * Finds contact information by a set of conditions 149 | * 150 | * @throws ApiException 151 | * @param int $limit 152 | * @param int $skip 153 | * @param string $orderBy 154 | * @param string $conditions 155 | * @return array 156 | */ 157 | public function findContacts($limit = 0, $skip = 0, $orderBy = '', $conditions = '') 158 | { 159 | if (is_numeric($limit) === false) { 160 | throw new ApiException('Limit value must be numeric.'); 161 | } 162 | 163 | if (is_numeric($skip) === false) { 164 | throw new ApiException('Skip value must be numeric.'); 165 | } 166 | 167 | if (is_string($orderBy) === false) { 168 | throw new ApiException('Order by must be a string.'); 169 | } 170 | 171 | if (is_string($conditions) === false) { 172 | throw new ApiException('Conditions must be a string.'); 173 | } 174 | 175 | $params = array( 176 | 'skip' => $skip, 177 | 'conditions' => $conditions, 178 | 'orderBy' => $orderBy 179 | ); 180 | 181 | // only set limit if there is a limit, limit 0 will return no results 182 | if ($limit > 0) { 183 | $params['limit'] = $limit; 184 | } 185 | 186 | return $this->client->makeRequest('FindContacts', $params); 187 | } 188 | 189 | /** 190 | * Finds a count of available contacts by a set of conditions 191 | * 192 | * @throws ApiException 193 | * @param string $conditions 194 | * @return array 195 | */ 196 | public function findContactsCount($conditions = '') 197 | { 198 | if (is_string($conditions) === false) { 199 | throw new ApiException('Conditions must be a string.'); 200 | } 201 | 202 | $params = array( 203 | 'conditions' => $conditions 204 | ); 205 | 206 | return $this->client->makeRequest('FindContactsCount', $params); 207 | } 208 | 209 | /** 210 | * Gets all communication types and descriptions 211 | * 212 | * @throws ApiException 213 | * @return array 214 | */ 215 | public function getAllCommunicationTypesAndDescriptions() 216 | { 217 | return $this->client->makeRequest('GetAllCommunicationTypesAndDescription', array()); 218 | } 219 | 220 | /** 221 | * Gets all communication items for contact by database record id 222 | * If no contact exists with the given id, an empty array is returned 223 | * 224 | * @throws ApiException 225 | * @param int $contactId 226 | * @return array 227 | */ 228 | public function getAllContactCommunicationItems($contactId) 229 | { 230 | if (is_numeric($contactId) === false) { 231 | throw new ApiException('Contact ID must be numeric.'); 232 | } 233 | 234 | $params = array( 235 | 'contactId' => $contactId 236 | ); 237 | 238 | return $this->client->makeRequest('GetAllContactCommunicationItems', $params); 239 | } 240 | 241 | /** 242 | * Gets all notes for contact by database record id. 243 | * If no contact exists with the given id, an exception is thrown in CW 244 | * 245 | * @throws ApiException 246 | * @param int $contactRecId 247 | * @return array 248 | */ 249 | public function getAllContactNotes($contactRecId) 250 | { 251 | if (is_numeric($contactRecId) === false) { 252 | throw new ApiException('Contact ID must be numeric.'); 253 | } 254 | 255 | $params = array( 256 | 'contactId' => $contactRecId 257 | ); 258 | 259 | return $this->client->makeRequest('GetAllContactNotes', $params); 260 | } 261 | 262 | 263 | /** 264 | * Gets a contact by database id 265 | * If no contact exists with the given id, an exception is thrown in cw 266 | * 267 | * @throws ApiException 268 | * @param int $id 269 | * @return array 270 | */ 271 | public function getContact($id) 272 | { 273 | if (is_numeric($id) === false) { 274 | throw new ApiException('Contact ID must be numeric.'); 275 | } 276 | 277 | $params = array( 278 | 'id' => $id 279 | ); 280 | 281 | return $this->client->makeRequest('GetContact', $params); 282 | } 283 | 284 | /** 285 | * Gets a communication item for contact by database record contactId 286 | * If no contact exists with the given id, an exception is thrown in CW 287 | * 288 | * @throws ApiException 289 | * @param int $contactId 290 | * @param string $type 291 | * @param string $description 292 | * @return array 293 | */ 294 | public function getContactCommunicationItem($contactId, $type, $description = '') 295 | { 296 | if (is_numeric($contactId) === false) { 297 | throw new ApiException('Contact ID must be numeric.'); 298 | } 299 | 300 | if (is_string($type) === false) { 301 | throw new ApiException('Type must be a string.'); 302 | } 303 | 304 | if (is_string($description) === false) { 305 | throw new ApiException('Description must be a string.'); 306 | } 307 | 308 | $params = array( 309 | 'contactId' => $contactId, 310 | 'communicationType' => $type, 311 | 'communicationDescription' => $description 312 | ); 313 | 314 | return $this->client->makeRequest('GetContactCommunicationItem', $params); 315 | } 316 | 317 | /** 318 | * Gets a note for contact by database record id 319 | * If no contact or contact note exists with the given ids, an exception is thrown in CW 320 | * 321 | * @throws ApiException 322 | * @param int $contactId 323 | * @param int $noteId 324 | * @return array 325 | */ 326 | public function getContactNote($contactId, $noteId) 327 | { 328 | if (is_numeric($contactId) === false) { 329 | throw new ApiException('Contact id must be numeric.'); 330 | } 331 | 332 | if (is_numeric($noteId) === false) { 333 | throw new ApiException('Note ID must be numeric.'); 334 | } 335 | 336 | $params = array( 337 | 'contactId' => $contactId, 338 | 'noteId' => $noteId 339 | ); 340 | 341 | return $this->client->makeRequest('GetContactNote', $params); 342 | } 343 | 344 | /** 345 | * Return the configuration settings for the specified portal 346 | * An exception is thrown in CW if the portal is not found / doesn't exist 347 | * 348 | * @throws ApiException 349 | * @param string $portalName 350 | * @return array 351 | */ 352 | public function getPortalConfigSettings($portalName = '') 353 | { 354 | if (is_string($portalName) === false) { 355 | throw new ApiException('Portal name must be a string.'); 356 | } 357 | 358 | $params = array( 359 | 'portalName' => $portalName 360 | ); 361 | 362 | return $this->client->makeRequest('GetPortalConfigSettings', $params); 363 | } 364 | 365 | /** 366 | * Get the login page customizations for the specified portal 367 | * Returns an empty array if portal is not found / doesn't exist 368 | * 369 | * @throws ApiException 370 | * @param string $portalName 371 | * @return array 372 | */ 373 | public function getPortalLoginCustomizations($portalName = '') 374 | { 375 | if (is_string($portalName) === false) { 376 | throw new ApiException('Portal name must be a string.'); 377 | } 378 | 379 | $params = array( 380 | 'portalName' => $portalName 381 | ); 382 | 383 | return $this->client->makeRequest('GetPortalLoginCustomizations', $params); 384 | } 385 | 386 | /** 387 | * Return the security settings for the contact logged into the portal 388 | * This will always return an array of portal security settings regardless of what you send it 389 | * 390 | * @throws ApiException 391 | * @param int $portalContId 392 | * @param string $portalCompName 393 | * @return array 394 | */ 395 | public function getPortalSecurity($portalContId, $portalCompName = '') 396 | { 397 | if (is_numeric($portalContId) === false) { 398 | throw new ApiException('Portal ContId must be numeric.'); 399 | } 400 | 401 | if (is_string($portalCompName) === false) { 402 | throw new ApiException('Portal name must be a string.'); 403 | } 404 | 405 | $params = array( 406 | 'portalContId' => $portalContId, 407 | 'portalCompName' => $portalCompName 408 | ); 409 | 410 | return $this->client->makeRequest('GetPortalSecurity', $params); 411 | } 412 | 413 | 414 | /** 415 | * Removes a contact from the specified group 416 | * 417 | * @todo Need a valid group id to finish testing this 418 | * 419 | * @throws ApiException 420 | * @param int $contactId 421 | * @param int $groupId 422 | * @param string $note 423 | * @return array 424 | */ 425 | public function removeContactFromGroup($contactId, $groupId, $note = '') 426 | { 427 | if (is_numeric($contactId) === false) { 428 | throw new ApiException('Contact ID must be numeric.'); 429 | } 430 | 431 | if (is_numeric($groupId) === false) { 432 | throw new ApiException('Group ID must be numeric.'); 433 | } 434 | 435 | if (is_string($note) === false) { 436 | throw new ApiException('Note must be a string.'); 437 | } 438 | 439 | $params = array( 440 | 'contactID' => $contactId, 441 | 'groupID' => $groupId, 442 | 'transactionNote' => $note 443 | ); 444 | 445 | return $this->client->makeRequest('RemoveContactFromGroup', $params); 446 | } 447 | 448 | /** 449 | * Runs the "Forgot Password" process on the server 450 | * 451 | * @throws ApiException 452 | * @param string $emailAddress 453 | * @return array 454 | */ 455 | public function requestPassword($emailAddress = '') 456 | { 457 | if (is_string($emailAddress) === false) { 458 | throw new ApiException('Email address must be a string.'); 459 | } 460 | 461 | $params = array( 462 | 'emailAddress' => $emailAddress 463 | ); 464 | 465 | return $this->client->makeRequest('RequestPassword', $params); 466 | } 467 | 468 | /** 469 | * Sets the default communication type for contactId, communcation type, and communication description 470 | * 471 | * @throws ApiException 472 | * @param int $contactId 473 | * @param string $communicationType 474 | * @param string $communicationDescription 475 | * @return array 476 | */ 477 | public function setDefaultContactCommunicationItem($contactId, $communicationType, $communicationDescription) 478 | { 479 | if (is_numeric($contactId) === false) { 480 | throw new ApiException('Contact ID must be numeric.'); 481 | } 482 | 483 | if (is_string($communicationType) === false) { 484 | throw new ApiException('Communication type must be a string.'); 485 | } 486 | 487 | if (is_string($communicationDescription) === false) { 488 | throw new ApiException('Communication description must be a string.'); 489 | } 490 | 491 | $params = array( 492 | 'contactId' => $contactId, 493 | 'communicationType' => $communicationType, 494 | 'communicationDescription' => $communicationDescription 495 | ); 496 | 497 | return $this->client->makeRequest('SetDefaultContactCommunicationItem', $params); 498 | } 499 | 500 | /** 501 | * Deletes a contact by database record id 502 | * 503 | * @throws ApiException 504 | * @param int $id 505 | * @return array 506 | */ 507 | public function deleteContact($id) 508 | { 509 | if (is_numeric($id) === false) { 510 | throw new ApiException('Contact ID must be numeric.'); 511 | } 512 | 513 | $params = array( 514 | 'id' => $id 515 | ); 516 | 517 | return $this->client->makeRequest('DeleteContact', $params); 518 | } 519 | 520 | /** 521 | * Deletes a communication by database record for contactId, communcationType, and communicationDescription 522 | * 523 | * @throws ApiException 524 | * @param int $contactId 525 | * @param string $type 526 | * @param string $description 527 | * @return array 528 | */ 529 | public function deleteContactCommunicationItem($contactId, $type, $description = '') 530 | { 531 | if (is_numeric($contactId) === false) { 532 | throw new ApiException('Contact ID must be numeric.'); 533 | } 534 | 535 | if (is_string($type) === false) { 536 | throw new ApiException('Type must be a string.'); 537 | } 538 | 539 | if (is_string($description) === false) { 540 | throw new ApiException('Description must be a string.'); 541 | } 542 | 543 | $params = array( 544 | 'contactId' => $contactId, 545 | 'communicationType' => $type, 546 | 'communicationDescription' => $description 547 | ); 548 | 549 | return $this->client->makeRequest('DeleteContactCommunicationItem', $params); 550 | } 551 | 552 | /** 553 | * Deletes a note by database record id. Returns an empty array on success 554 | * 555 | * @throws ApiException 556 | * @param int $noteId 557 | * @param int $contactId 558 | * @return array 559 | */ 560 | public function deleteNote($noteId, $contactId) 561 | { 562 | if (is_numeric($contactId) === false) { 563 | throw new ApiException('Contact ID must be numeric.'); 564 | } 565 | 566 | if (is_numeric($noteId) === false) { 567 | throw new ApiException('Note ID must be numeric.'); 568 | } 569 | 570 | $params = array( 571 | 'id' => $noteId, 572 | 'contactId' => $contactId 573 | ); 574 | 575 | return $this->client->makeRequest('DeleteNote', $params); 576 | } 577 | } 578 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Document.php: -------------------------------------------------------------------------------- 1 | client = $client; 21 | } 22 | 23 | /** 24 | * Add documents to a CW object, such as a ticket or contact 25 | * 26 | * @param string|int $objectId numeric value, recID of object to add document to 27 | * @param string $documentTableReference type of object document is being added to 28 | * @param array $documentInfo array of objects that represent a document 29 | * @return array Array of one or more document objects 30 | */ 31 | public function addDocuments($objectId, $documentTableReference, array $documentInfo) 32 | { 33 | // throw exception if $objectId is not numeric 34 | if (!is_numeric($objectId)) { 35 | throw new InvalidArgumentException( 36 | 'objectId must be a numeric value.' 37 | ); 38 | } 39 | 40 | // throw exception if $documentTableReference 41 | // is not a string 42 | if (!is_string($documentTableReference)) { 43 | throw new InvalidArgumentException( 44 | 'documentTableReference must be a string value.' 45 | ); 46 | } 47 | 48 | $params = [ 49 | 'objectId' => $objectId, 50 | 'documentTableReference' => $documentTableReference, 51 | 'documentInfo' => $documentInfo 52 | ]; 53 | 54 | // Fire off the request to the Document API and return the result array 55 | return $this->client->makeRequest('AddDocuments', $params); 56 | } 57 | 58 | /** 59 | * Retrieve a document from ConnectWise 60 | * 61 | * @throws \LabtechSoftware\ConnectwisePsaSdk\ApiException 62 | * @throws \InvalidArgumentException 63 | * @param string|int $documentId numeric, the id of the document to get 64 | * @return array Representation of a document 65 | */ 66 | public function getDocument($documentId) 67 | { 68 | // Throw exception if the argument is a non numeric value 69 | if (is_numeric($documentId) === false) { 70 | throw new InvalidArgumentException('Expecting numeric value.'); 71 | } 72 | 73 | // Throw exception if the Document ID is 0 or a negative number 74 | if ($documentId <= 0) { 75 | throw new ApiException('Expecting value greater than 0.'); 76 | } 77 | 78 | // Fire off the request to the Document API and return the result array 79 | return $this->client->makeRequest( 80 | 'GetDocument', 81 | array('documentId' => $documentId) 82 | ); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/IntegrationIO.php: -------------------------------------------------------------------------------- 1 | client = $client; 10 | } 11 | 12 | /** 13 | * Gets a list of ticket statuses available for the portal, per ticket 14 | * 15 | * @param $serviceTicketRecId 16 | * @return mixed 17 | * @throws ApiException 18 | */ 19 | public function getPortalTicketStatuses($serviceTicketRecId) 20 | { 21 | if (!is_numeric($serviceTicketRecId)) { 22 | throw new ApiException('argument 1 must be numeric'); 23 | } 24 | 25 | $creds = $this->client->getConfigLoader()->getSoapCredentials(); 26 | $companyName = $creds['CompanyId']; 27 | $login = $creds['IntegratorLoginId']; 28 | $pass = $creds['IntegratorPassword']; 29 | 30 | $params = [ 31 | 'actionString' => ' 32 | 33 | '. $companyName . ' 34 | '. $login . ' 35 | '. $pass .' 36 | '. $serviceTicketRecId . ' 37 | true 38 | ' 39 | ]; 40 | 41 | $result = $this->client->makeRequest('ProcessClientAction', $params); 42 | $result->ProcessClientActionResult = simplexml_load_string($result->ProcessClientActionResult); 43 | return $result; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Laravel/ConnectwiseFactory.php: -------------------------------------------------------------------------------- 1 | app->bind('LabtechSoftware\ConnectwisePsaSdk\ConnectwiseApiFactory', function () { 11 | return new LabtechSoftware\ConnectwisePsaSdk\ConnnectwiseApiFactory; 12 | });*/ 13 | 14 | $this->app['connectwise-psa-sdk'] = $this->app->share(function ($app) { 15 | return new ConnectwiseApiFacotry( 16 | $app['config']['connectwise-psa-sdk::api'] 17 | ); 18 | }); 19 | } 20 | 21 | public function boot() 22 | { 23 | $this->package('labtech-software/connectwise-psa-sdk', 'connectwise-psa-sdk'); 24 | } 25 | 26 | public function provides() 27 | { 28 | return array('connectwise-psa-sdk'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Member.php: -------------------------------------------------------------------------------- 1 | client = $client; 10 | } 11 | 12 | 13 | public function isValidMemberIdAndPassword($memberId, $password) 14 | { 15 | if (!is_string($memberId)) { 16 | throw new ApiException('Member Id must be a string'); 17 | } 18 | 19 | if (!is_string($password)) { 20 | throw new ApiException('Password must be a string'); 21 | } 22 | 23 | $params = [ 24 | 'memberId' => $memberId, 25 | 'password' => $password 26 | ]; 27 | 28 | return $this->client->makeRequest('isValidMemberIdAndPassword', $params); 29 | } 30 | 31 | public function findMembers($conditions = '', $limit = 0, $orderBy = '', $skip = '') 32 | { 33 | $params = [ 34 | 'conditions' => $conditions, 35 | 'orderBy' => $orderBy, 36 | 'skip' => $skip, 37 | ]; 38 | 39 | // only set limit if there is a limit, limit 0 will return no results 40 | if ($limit > 0) { 41 | $params['limit'] = $limit; 42 | } 43 | 44 | return $this->client->makeRequest('FindMembers', $params); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Overrides/SoapClient.php: -------------------------------------------------------------------------------- 1 | wsdl = $wsdl; 15 | parent::__construct($wsdl, $options); 16 | } 17 | 18 | public function __doRequest($request, $location, $action, $version, $one_way = 0) 19 | { 20 | if (strpos($this->wsdl, 'https://') === 0) { 21 | $location = str_replace('http://', 'https://', $location); 22 | } 23 | return parent::__doRequest($request, $location, $action, $version, $one_way); 24 | } 25 | } -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Reporting.php: -------------------------------------------------------------------------------- 1 | client = $client; 15 | } 16 | 17 | /** 18 | * Gets the list of fields for a particular report 19 | * 20 | * @throws ApiException 21 | * @param string $reportName 22 | * @return array 23 | */ 24 | public function getReportFields($reportName = '') 25 | { 26 | if (is_string($reportName) === false) { 27 | throw new ApiException('Report name must be a string.'); 28 | } 29 | 30 | $params = array( 31 | 'reportName' => $reportName 32 | ); 33 | 34 | return $this->client->makeRequest('GetReportFields', $params); 35 | } 36 | 37 | /** 38 | * Gets the list of available reports 39 | * 40 | * @throws ApiException 41 | * @param boolean $includeFields 42 | * @return array 43 | */ 44 | public function getReports($includeFields = true) 45 | { 46 | // Check for boolean param 47 | if (is_bool($includeFields) === false) { 48 | throw new ApiException('Include fields parameter must be boolean.'); 49 | } 50 | 51 | $params = array( 52 | 'includeFields' => $includeFields 53 | ); 54 | 55 | return $this->client->makeRequest('GetReports', $params); 56 | } 57 | 58 | /** 59 | * Runs a particular report with a given set of conditions. Returns the # of records that would be returned. 60 | * 61 | * @throws ApiException 62 | * @param string $reportName 63 | * @param string $conditions 64 | * @return array 65 | */ 66 | public function runReportCount($reportName, $conditions = '') 67 | { 68 | if (is_string($reportName) === false) { 69 | throw new ApiException('Report name must be a string.'); 70 | } 71 | 72 | if (is_string($conditions) === false) { 73 | throw new ApiException('Conditions must be a string.'); 74 | } 75 | 76 | $params = array( 77 | 'reportName' => $reportName, 78 | 'conditions' => $conditions 79 | ); 80 | 81 | return $this->client->makeRequest('RunReportCount', $params); 82 | } 83 | 84 | /** 85 | * Runs a particular report with a given set of conditions 86 | * 87 | * @throws ApiException 88 | * @param string $reportName 89 | * @param int $limit 90 | * @param int $skip 91 | * @param string $conditions 92 | * @param string $orderBy 93 | * @return array 94 | */ 95 | public function runReportQuery($reportName, $limit = 100, $skip = 0, $conditions = '', $orderBy = '') 96 | { 97 | if (is_string($reportName) === false) { 98 | throw new ApiException('Report name must be a string.'); 99 | } 100 | 101 | if (is_numeric($limit) === false) { 102 | throw new ApiException('Limit value must be numeric.'); 103 | } 104 | 105 | if (is_numeric($skip) === false) { 106 | throw new ApiException('Skip value must be numeric.'); 107 | } 108 | 109 | if (is_string($conditions) === false) { 110 | throw new ApiException('Conditions value must be a string.'); 111 | } 112 | 113 | if (is_string($orderBy) === false) { 114 | throw new ApiException('Order by value must be a string.'); 115 | } 116 | 117 | $params = array( 118 | 'reportName' => $reportName, 119 | 'conditions' => $conditions, 120 | 'orderBy' => $orderBy, 121 | 'skip' => $skip 122 | ); 123 | 124 | // only set limit if there is a limit, limit 0 will return no results 125 | if ($limit > 0) { 126 | $params['limit'] = $limit; 127 | } 128 | 129 | $result = $this->getData( 130 | $this->client->makeRequest('RunReportQuery', $params), 131 | 'RunReportQueryResult' 132 | ); 133 | 134 | return $this->prepareReport($result); 135 | } 136 | 137 | /** 138 | * Runs a particular report with a given set of conditions 139 | * 140 | * @throws ApiException 141 | * @param string $reportName 142 | * @param int $limit 143 | * @param int $skip 144 | * @param string $conditions 145 | * @param string $orderBy 146 | * @param array $fieldFilters 147 | * @return array 148 | */ 149 | public function runReportQueryWithFilters($reportName, $limit = 100, $skip = 0, $conditions = '', $orderBy = '', $fieldFilters = array()) 150 | { 151 | if (is_string($reportName) === false) { 152 | throw new ApiException('Report name must be a string.'); 153 | } 154 | 155 | if (is_numeric($limit) === false) { 156 | throw new ApiException('Limit value must be numeric.'); 157 | } 158 | 159 | if (is_numeric($skip) === false) { 160 | throw new ApiException('Skip value must be numeric.'); 161 | } 162 | 163 | if (is_string($conditions) === false) { 164 | throw new ApiException('Conditions value must be a string.'); 165 | } 166 | 167 | if (is_string($orderBy) === false) { 168 | throw new ApiException('Order by value must be a string.'); 169 | } 170 | 171 | if (is_array($fieldFilters) === false) { 172 | throw new ApiException('FieldFilters value must be an array.'); 173 | } 174 | 175 | $params = array( 176 | 'reportName' => $reportName, 177 | 'conditions' => $conditions, 178 | 'orderBy' => $orderBy, 179 | 'skip' => $skip, 180 | 'fieldFilters' => $fieldFilters 181 | ); 182 | 183 | // only set limit if there is a limit, limit 0 will return no results 184 | if ($limit > 0) { 185 | $params['limit'] = $limit; 186 | } 187 | 188 | // make the request and get data from the returned object 189 | $result = $this->getData( 190 | $this->client->makeRequest('RunReportQueryWithFilters', $params), 191 | 'RunReportQueryWithFiltersResult' 192 | ); 193 | 194 | // send pulled data to prepare report, for a more sane data structure 195 | return $this->prepareReport($result); 196 | } 197 | 198 | /* 199 | * Helper method, manipulates data structure given from ConnectWise, into a structure that is easier to work with 200 | */ 201 | private function prepareReport(array $report) 202 | { 203 | $items = array(); 204 | foreach ($report as $item) { 205 | $tmpItems = new \stdClass(); 206 | foreach ($item->Value as $v) { 207 | $tmpItems->{$v->Name} = $v->_; 208 | } 209 | $items[] = $tmpItems; 210 | } 211 | 212 | return $items; 213 | } 214 | 215 | /** 216 | * Helper method, pulls the data structure giving from ConnectWise 217 | * 218 | * @param object $report The report as giving back from ConnectWise 219 | * @param string $reportName The name of the method used on Reporting API 220 | * @return array|bool 221 | */ 222 | private function getData($report, $reportName) 223 | { 224 | if (isset($report->{$reportName}->ResultRow)) { 225 | $report = $report->{$reportName}->ResultRow; 226 | } elseif (isset($report->{$reportName})) { 227 | $report = []; 228 | } else { 229 | $report = false; 230 | } 231 | 232 | return $report; 233 | } 234 | } 235 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Rest/Client.php: -------------------------------------------------------------------------------- 1 | getBody()->getContents(), true); 21 | } 22 | } -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Rest/ContactApi.php: -------------------------------------------------------------------------------- 1 | client = $client; 11 | } 12 | 13 | public function authenticate(array $credentials) 14 | { 15 | $method = 'POST'; 16 | $uri = $this->api . '/validatePortalCredentials'; 17 | $options = ['json' => $credentials]; 18 | 19 | return $this->client->makeRequest($method, $uri, $options); 20 | } 21 | 22 | public function update($id, array $operations) 23 | { 24 | $method = 'PATCH'; 25 | $uri = $this->api . '/' . $id; 26 | $options = ['json' => $operations]; 27 | 28 | return $this->client->makeRequest($method, $uri, $options); 29 | } 30 | } -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/Rest/MarketingContactApi.php: -------------------------------------------------------------------------------- 1 | client = $client; 11 | } 12 | 13 | public function add($groupId, $contactId, $message = '') 14 | { 15 | $method = 'POST'; 16 | $uri = "{$this->api}/{$groupId}/contacts"; 17 | $options = [ 18 | 'json' => [ 19 | 'id' => $contactId, 20 | 'groupId' => $groupId, 21 | 'note' => $message, 22 | 'unsubscribeFlag' => false 23 | ] 24 | ]; 25 | 26 | return $this->client->makeRequest($method, $uri, $options); 27 | } 28 | 29 | public function get($groupId, $contactId, $throwExceptions) 30 | { 31 | $method = 'GET'; 32 | $uri = "{$this->api}/{$groupId}/contacts/{$contactId}"; 33 | $options = ['http_errors' => $throwExceptions]; 34 | 35 | return $this->client->makeRequest($method, $uri, $options, !$throwExceptions); 36 | } 37 | 38 | public function update($groupId, $contactId, array $operations) 39 | { 40 | $method = 'PATCH'; 41 | $uri = "{$this->api}/{$groupId}/contacts/{$contactId}"; 42 | $options = ['json' => $operations]; 43 | 44 | return $this->client->makeRequest($method, $uri, $options); 45 | } 46 | } -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/ServiceTicket.php: -------------------------------------------------------------------------------- 1 | client = $client; 17 | } 18 | 19 | /** 20 | * Adds or updates a service ticket for a company identified by the text-based company id. 21 | * If the service ticket number is 0, the service ticket is added. 22 | * If non-zero, the existing service ticket with that ticket number is updated. 23 | * 24 | * @throws ApiException 25 | * @param string $companyId 26 | * @param array $serviceTicket 27 | * @return array 28 | **/ 29 | public function addOrUpdateServiceTicketViaCompanyId($companyId, array $serviceTicket) 30 | { 31 | if (is_string($companyId) === false) { 32 | throw new ApiException('Company ID must be a string.'); 33 | } 34 | 35 | $params = array( 36 | 'companyId' => $companyId, 37 | 'serviceTicket' => $serviceTicket 38 | ); 39 | 40 | return $this->client->makeRequest('AddOrUpdateServiceTicketViaCompanyId', $params); 41 | } 42 | 43 | /** 44 | * Adds or updates a service ticket for a company identified by managed id. 45 | * If the service ticket number is 0, the service ticket is added. 46 | * If non-zero, the existing service ticket with that ticket number is updated. 47 | * @todo This is untested: need a valid managed id to test this method 48 | * 49 | * @throws ApiException 50 | * @param string $managedId 51 | * @param array $serviceTicket 52 | * @return array 53 | **/ 54 | public function addOrUpdateServiceTicketViaManagedId($managedId, array $serviceTicket) 55 | { 56 | if (is_string($managedId) === false) { 57 | throw new ApiException('Managed ID must be a string.'); 58 | } 59 | 60 | $params = array( 61 | 'manageId' => $managedId, 62 | 'serviceTicket' => $serviceTicket 63 | ); 64 | 65 | return $this->client->makeRequest('AddOrUpdateServiceTicketViaManagedId', $params); 66 | } 67 | 68 | /** 69 | * Add or update a product on a ticket 70 | * 71 | * @param array $ticketProduct 72 | * @return array 73 | **/ 74 | public function addOrUpdateTicketProduct(array $ticketProduct) 75 | { 76 | $params = array( 77 | 'ticketProduct' => $ticketProduct 78 | ); 79 | 80 | return $this->client->makeRequest('AddOrUpdateTicketProduct', $params); 81 | } 82 | 83 | /** 84 | * Finds service ticket information by a set of conditions 85 | * 86 | * @throws ApiException 87 | * @param int $limit 88 | * @param int $skip 89 | * @param string $conditions 90 | * @param string $orderBy 91 | * @return array 92 | */ 93 | public function findServiceTickets($limit = 100, $skip = 0, $conditions = '', $orderBy = '') 94 | { 95 | if (is_numeric($limit) === false) { 96 | throw new ApiException('Limit value must be numeric.'); 97 | } 98 | 99 | if (is_numeric($skip) === false) { 100 | throw new ApiException('Skip value must be numeric.'); 101 | } 102 | 103 | if (is_string($conditions) === false) { 104 | throw new ApiException('Conditions value must be a string.'); 105 | } 106 | 107 | if (is_string($orderBy) === false) { 108 | throw new ApiException('Order by value must be a string.'); 109 | } 110 | 111 | $params = array( 112 | 'skip' => $skip, 113 | 'conditions' => $conditions, 114 | 'orderBy' => $orderBy 115 | ); 116 | 117 | // only set limit if there is a limit, limit 0 will return no results 118 | if ($limit > 0) { 119 | $params['limit'] = $limit; 120 | } 121 | 122 | return $this->client->makeRequest('FindServiceTickets', $params); 123 | } 124 | 125 | /** 126 | * Gets the list of statuses available to the specified ticket 127 | * 128 | * @throws ApiException 129 | * @param int $ticketId 130 | * @return array 131 | **/ 132 | public function getServiceStatuses($ticketId) 133 | { 134 | if (is_numeric($ticketId) === false) { 135 | throw new ApiException('Ticket ID must be numeric.'); 136 | } 137 | 138 | $params = array( 139 | 'ticketNumber' => $ticketId 140 | ); 141 | 142 | return $this->client->makeRequest('GetServiceStatuses', $params); 143 | } 144 | 145 | /** 146 | * Gets a service ticket by the ticket number (id) 147 | * If no service ticket exists with the given ticket number, an empty array is returned 148 | * 149 | * @throws ApiException 150 | * @param int $ticketId 151 | * @return array 152 | **/ 153 | public function getServiceTicket($ticketId) 154 | { 155 | if (is_numeric($ticketId) === false) { 156 | throw new ApiException('Ticket ID must be numeric.'); 157 | } 158 | 159 | $params = array( 160 | 'ticketNumber' => $ticketId 161 | ); 162 | 163 | return $this->client->makeRequest('GetServiceTicket', $params); 164 | } 165 | 166 | /** 167 | * Gets the count of service tickets that meet the specified conditions 168 | * 169 | * @throws ApiException 170 | * @param string $conditions 171 | * @return array 172 | **/ 173 | public function getTicketCount($conditions = '') 174 | { 175 | if (is_string($conditions) === false) { 176 | throw new ApiException('Conditions value must be a string.'); 177 | } 178 | 179 | $params = array( 180 | 'conditions' => $conditions, 181 | ); 182 | 183 | return $this->client->makeRequest('GetTicketCount', $params); 184 | } 185 | 186 | /** 187 | * Get a list of products for the specified ticket 188 | * 189 | * @throws ApiException 190 | * @param int $ticketNumber 191 | * @return array 192 | **/ 193 | public function getTicketProductList($ticketNumber) 194 | { 195 | if (is_numeric($ticketNumber) === false) { 196 | throw new ApiException('Ticket number must be numeric.'); 197 | } 198 | 199 | $params = array( 200 | 'ticketNumber' => $ticketNumber 201 | ); 202 | 203 | return $this->client->makeRequest('GetTicketProductList', $params); 204 | } 205 | 206 | /** 207 | * Performs a Knowledgebase search using the specified parameters 208 | * 209 | * @throws ApiException 210 | * @param string $terms 211 | * @param string $type 212 | * @param string $start 213 | * @param int $companyRecId 214 | * @param int $limit 215 | * @param int $skip 216 | * @return array 217 | **/ 218 | public function searchKnowledgebase($terms, $type, $start, $companyRecId = 0, $limit = 100, $skip = 0) 219 | { 220 | if (is_string($terms) === false) { 221 | throw new ApiException('Terms value must be a string.'); 222 | } 223 | 224 | if (is_string($type) === false) { 225 | throw new ApiException('Type value must be a string.'); 226 | } 227 | 228 | if ($type != 'Any' && $type != 'All' && $type != 'Exact') { 229 | throw new ApiException('KB type invalid. Must be "Any", "All" or "Exact".'); 230 | } 231 | 232 | if (is_string($start) === false) { 233 | throw new ApiException('Start value must be a string.'); 234 | } 235 | 236 | if (is_numeric($companyRecId) === false) { 237 | throw new ApiException('CompanyRecId value must be numeric'); 238 | } 239 | 240 | if (is_numeric($limit) === false) { 241 | throw new ApiException('Limit value must be numeric.'); 242 | } 243 | 244 | if (is_numeric($skip) === false) { 245 | throw new ApiException('Skip value must be numeric.'); 246 | } 247 | 248 | $params = array( 249 | 'searchTerms' => $terms, 250 | 'searchType' => $type, 251 | 'searchStart' => $start, 252 | 'companyRecID' => $companyRecId, 253 | 'skip' => $skip 254 | ); 255 | 256 | // only set limit if there is a limit, limit 0 will return no results 257 | if ($limit > 0) { 258 | $params['limit'] = $limit; 259 | } 260 | 261 | return $this->client->makeRequest('SearchKnowledgebase', $params); 262 | } 263 | 264 | /** 265 | * Counts the Knowledgebase records that will be returned by performing the associated search 266 | * 267 | * @throws ApiException 268 | * @param string $terms 269 | * @param string $type 270 | * @param string $start 271 | * @param int $companyRecId 272 | * @return array 273 | **/ 274 | public function searchKnowledgebaseCount($terms, $type, $start, $companyRecId = 0) 275 | { 276 | if (is_string($terms) === false) { 277 | throw new ApiException('Terms value must be a string.'); 278 | } 279 | 280 | if (is_string($type) === false) { 281 | throw new ApiException('Type value must be a string.'); 282 | } 283 | 284 | if ($type != 'Any' && $type != 'All' && $type != 'Exact') { 285 | throw new ApiException('KB type invalid. Must be "Any", "All" or "Exact".'); 286 | } 287 | 288 | if (is_string($start) === false) { 289 | throw new ApiException('Start value must be a string.'); 290 | } 291 | 292 | if (is_numeric($companyRecId) === false) { 293 | throw new ApiException('CompanyRecId value must be numeric'); 294 | } 295 | 296 | 297 | $params = array( 298 | 'searchTerms' => $terms, 299 | 'searchType' => $type, 300 | 'searchStart' => $start, 301 | 'companyRecID' => $companyRecId 302 | ); 303 | 304 | return $this->client->makeRequest('searchKnowledgebaseCount', $params); 305 | } 306 | 307 | /** 308 | * Get the documents attached to the specified ticket 309 | * 310 | * @throws ApiException 311 | * @param int $ticketNumber 312 | * @return array 313 | **/ 314 | public function getTicketDocuments($ticketNumber) 315 | { 316 | if (is_numeric($ticketNumber) === false) { 317 | throw new ApiException('Ticket number must be numeric.'); 318 | } 319 | 320 | $params = array( 321 | 'ticketNumber' => $ticketNumber 322 | ); 323 | 324 | return $this->client->makeRequest('GetTicketDocuments', $params); 325 | } 326 | 327 | /** 328 | * Add a new ticket note or update an existing ticket note by service ticket rec id 329 | * 330 | * @throws ApiException 331 | * @param array $note 332 | * @param int $serviceRecId 333 | * @return array 334 | **/ 335 | public function updateTicketNote(array $note, $serviceRecId) 336 | { 337 | if (is_numeric($serviceRecId) === false) { 338 | throw new ApiException('Service Rec ID must be numeric.'); 339 | } 340 | 341 | $params = array( 342 | 'note' => $note, 343 | 'srServiceRecid' => $serviceRecId 344 | ); 345 | 346 | return $this->client->makeRequest('UpdateTicketNote', $params); 347 | } 348 | 349 | /** 350 | * Deletes a service ticket by the ticket number 351 | * 352 | * @throws ApiException 353 | * @param int $ticketId 354 | * @return array 355 | **/ 356 | public function deleteServiceTicket($ticketId) 357 | { 358 | if (is_numeric($ticketId) === false) { 359 | throw new ApiException('Ticket ID must be numeric.'); 360 | } 361 | 362 | $params = array( 363 | 'ticketNumber' => $ticketId 364 | ); 365 | 366 | return $this->client->makeRequest('DeleteServiceTicket', $params); 367 | } 368 | 369 | /** 370 | * Removes the document from the ticket 371 | * 372 | * @throws ApiException 373 | * @param int $docId 374 | * @param int $ticketId 375 | * @return array 376 | **/ 377 | public function deleteTicketDocument($docId, $ticketId) 378 | { 379 | if (is_numeric($docId) === false) { 380 | throw new ApiException('Document ID must be numeric.'); 381 | } 382 | 383 | if (is_numeric($ticketId) === false) { 384 | throw new ApiException('Ticket ID must be numeric.'); 385 | } 386 | 387 | $params = array( 388 | 'id' => $docId, 389 | 'ticketNumber' => $ticketId 390 | ); 391 | 392 | return $this->client->makeRequest('DeleteTicketDocument', $params); 393 | } 394 | 395 | /** 396 | * Delete product from a ticket 397 | * 398 | * @throws ApiException 399 | * @param int $productId 400 | * @param int $ticketId 401 | * @return array 402 | **/ 403 | public function deleteTicketProduct($productId, $ticketId) 404 | { 405 | if (is_numeric($productId) === false) { 406 | throw new ApiException('Product ID must be numeric.'); 407 | } 408 | 409 | if (is_numeric($ticketId) === false) { 410 | throw new ApiException('Ticket ID must be numeric.'); 411 | } 412 | 413 | $params = array( 414 | 'id' => $productId, 415 | 'ticketNumber' => $ticketId 416 | ); 417 | 418 | return $this->client->makeRequest('DeleteTicketProduct', $params); 419 | } 420 | } 421 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/SoapApiRequester.php: -------------------------------------------------------------------------------- 1 | soap = $soap; 18 | $this->configLoader= $configLoader; 19 | } 20 | 21 | public function makeRequest($method, $params = array()) 22 | { 23 | // squirt credentials into params 24 | $params['credentials'] = $this->configLoader->getSoapCredentials(); 25 | 26 | try { 27 | return $this->soap->{$method}($params); 28 | } catch (SoapFault $fault) { 29 | throw new ApiException($fault->getMessage()); 30 | } 31 | } 32 | 33 | public function getConfigLoader() 34 | { 35 | return $this->configLoader; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/LabtechSoftware/ConnectwisePsaSdk/config/config.php: -------------------------------------------------------------------------------- 1 | [ 5 | 'soap_version' => SOAP_1_1, 6 | 'exceptions' => true, 7 | 'trace' => 1, 8 | 'cache_wsdl' => WSDL_CACHE_NONE, 9 | 'features' => SOAP_SINGLE_ELEMENT_ARRAYS 10 | ], 11 | 'url' => [ 12 | 'cw_api_main' => 'https://%s/v4_6_release/apis/1.5/%s.asmx?wsdl' 13 | ], 14 | 'credentials' => [ 15 | 'domain' => '', 16 | 'CompanyId' => '', 17 | 'IntegratorLoginId' => '', 18 | 'IntegratorPassword' => '' 19 | ] 20 | ); 21 | -------------------------------------------------------------------------------- /tests/ConnectWise/integration/CompanyIntegrationTest.php: -------------------------------------------------------------------------------- 1 | configuration = parent::setUp(); 12 | $this->factory = new ConnectwiseApiFactory(); 13 | $this->fixture = $this->factory->make( 14 | 'Company', 15 | $this->configuration 16 | ); 17 | } 18 | 19 | /** 20 | * @return array 21 | */ 22 | public function testAddCompany() 23 | { 24 | $data = [ 25 | 'DefaultAddress' => [ 26 | 'Id' => 0, 27 | 'DefaultFlag' => true, 28 | 'InactiveFlag' => false, 29 | 'CompanyRecid' => 0, 30 | 'SiteName' => 'US Headquarters' 31 | ], 32 | 'CompanyName' => 'Integration Test Co.', 33 | 'CompanyID' => 'Integrate' . time(), 34 | 'PhoneNumber' => '8135555555', 35 | 'FaxNumber' => '8135551111', 36 | 'WebSite' => 'http://pandora.com', 37 | 'Id' => 0 38 | ]; 39 | 40 | $results = $this->fixture->addOrUpdateCompany($data); 41 | $this->assertInternalType('object', $results); 42 | $results = $results->AddOrUpdateCompanyResult; 43 | $this->assertCompanyStructure($data, $results); 44 | 45 | return [ 46 | 'ID' => $results->Id, 47 | 'CompanyID' => $data['CompanyID'] 48 | ]; 49 | } 50 | 51 | /** 52 | * @depends testAddCompany 53 | * @param $res 54 | * @return mixed 55 | */ 56 | public function testUpdateCompany($res) 57 | { 58 | $data = [ 59 | 'DefaultAddress' => [ 60 | 'Id' => 0, 61 | 'DefaultFlag' => true, 62 | 'InactiveFlag' => false, 63 | 'CompanyRecid' => 0, 64 | 'SiteName' => 'US Headquarters' 65 | ], 66 | 'CompanyName' => 'Integration Test Co.', 67 | 'CompanyID' => $res['CompanyID'], 68 | 'PhoneNumber' => rand(1000000000, 9999999999), 69 | 'FaxNumber' => rand(1000000000, 9999999999), 70 | 'WebSite' => 'http://integrationtest.co', 71 | 'Id' => $res['ID'] 72 | ]; 73 | 74 | $results = $this->fixture->addOrUpdateCompany($data); 75 | $this->assertInternalType('object', $results); 76 | $results = $results->AddOrUpdateCompanyResult; 77 | $this->assertCompanyStructure($data, $results); 78 | 79 | $res['Data'] = $data; 80 | return $res; 81 | } 82 | 83 | /** 84 | * @depends testUpdateCompany 85 | * @param $res 86 | */ 87 | public function testGetCompany($res) 88 | { 89 | $results = $this->fixture->getCompany($res['ID']); 90 | $this->assertInternalType('object', $results); 91 | $results = $results->GetCompanyResult; 92 | $this->assertCompanyStructure($res['Data'], $results); 93 | } 94 | 95 | /** 96 | * @depends testAddCompany 97 | * @param $res 98 | */ 99 | public function testDeleteCompany($res) 100 | { 101 | $results = $this->fixture->deleteCompany($res['ID']); 102 | $this->assertInternalType('object', $results); 103 | $this->assertTrue(empty((array)$results)); 104 | } 105 | 106 | /** 107 | * @dataProvider limitDataProvider 108 | * @param $limit 109 | */ 110 | public function testFindCompanies($limit) 111 | { 112 | $results = $this->fixture->findCompanies($limit, 0, '', ''); 113 | $this->assertInternalType('object', $results); 114 | $this->assertInternalType('object', $results->FindCompaniesResult); 115 | $results = $results->FindCompaniesResult->CompanyFindResult; 116 | if ($limit === 1) { 117 | $this->assertFindCompanyStructure($results); 118 | } else { 119 | $this->assertInternalType('array', $results); 120 | foreach ($results as $result) { 121 | $this->assertFindCompanyStructure($result); 122 | } 123 | } 124 | } 125 | 126 | /** 127 | * @param $data 128 | * @param $results 129 | */ 130 | private function assertCompanyStructure($data, $results) 131 | { 132 | $this->assertInternalType('object', $results); 133 | $this->assertInternalType('object', $results->Addresses); 134 | $this->assertInternalType('object', $results->Addresses->CompanyAddress); 135 | $this->assertInternalType('object', $results->Addresses->CompanyAddress->StreetLines); 136 | $this->assertInternalType('array', $results->Addresses->CompanyAddress->StreetLines->string); 137 | $this->assertNull($results->Addresses->CompanyAddress->StreetLines->string[0]); 138 | $this->assertNull($results->Addresses->CompanyAddress->StreetLines->string[1]); 139 | $this->assertInternalType('string', $results->Addresses->CompanyAddress->Country); 140 | $this->assertInternalType('integer', $results->Addresses->CompanyAddress->Id); 141 | $this->assertSame($data['DefaultAddress']['DefaultFlag'], $results->Addresses->CompanyAddress->DefaultFlag); 142 | $this->assertInternalType('integer', $results->Addresses->CompanyAddress->CompanyRecid); 143 | $this->assertSame($data['DefaultAddress']['SiteName'], $results->Addresses->CompanyAddress->SiteName); 144 | $this->assertSame($data['DefaultAddress']['InactiveFlag'], $results->Addresses->CompanyAddress->InactiveFlag); 145 | $this->assertSame($data['CompanyName'], $results->CompanyName); 146 | $this->assertSame($data['CompanyID'], $results->CompanyID); 147 | $this->assertSame((string)$data['PhoneNumber'], $results->PhoneNumber); 148 | $this->assertSame((string)$data['FaxNumber'], $results->FaxNumber); 149 | $this->assertSame($data['WebSite'], $results->WebSite); 150 | $this->assertInternalType('integer', $results->Id); 151 | $this->assertInternalType('string', $results->Type); 152 | $this->assertInternalType('string', $results->Status); 153 | $this->assertInternalType('string', $results->AccountNbr); 154 | $this->assertInternalType('integer', $results->DefaultContactId); 155 | $this->assertInternalType('integer', $results->DefaultBillingContactId); 156 | $this->assertNotFalse(strtotime($results->LastUpdate)); 157 | } 158 | 159 | private function assertFindCompanyStructure($result) 160 | { 161 | $this->assertInternalType('object', $result); 162 | $this->assertInternalType('integer', $result->CompanyRecID); 163 | $this->assertInternalType('string', $result->CompanyName); 164 | $this->assertInternalType('string', $result->CompanyID); 165 | $this->assertInternalType('string', $result->PhoneNumber); 166 | $this->assertInternalType('string', $result->AddressLine1); 167 | $this->assertInternalType('string', $result->AddressLine2); 168 | $this->assertInternalType('string', $result->City); 169 | $this->assertInternalType('string', $result->State); 170 | $this->assertInternalType('string', $result->Zip); 171 | $this->assertInternalType('string', $result->Country); 172 | $this->assertInternalType('string', $result->Type); 173 | $this->assertInternalType('string', $result->Status); 174 | $this->assertInternalType('string', $result->Territory); 175 | $this->assertInternalType('string', $result->Website); 176 | if (isset($result->Market)) { 177 | $this->assertInternalType('string', $result->Market); 178 | } 179 | } 180 | 181 | public function limitDataProvider() 182 | { 183 | return [ 184 | [1], 185 | [2] 186 | ]; 187 | } 188 | } 189 | -------------------------------------------------------------------------------- /tests/ConnectWise/integration/ConfigurationIntegrationTest.php: -------------------------------------------------------------------------------- 1 | configuration = parent::setUp(); 12 | $this->factory = new ConnectwiseApiFactory(); 13 | $this->fixture = $this->factory->make( 14 | 'Configuration', 15 | $this->configuration 16 | ); 17 | } 18 | 19 | public function testAddConfigurationType() 20 | { 21 | $data = [ 22 | 'Id' => 0, 23 | 'InactiveFlag' => false, 24 | 'SystemFlag' => false, 25 | 'Name' => 'IntegrationTestType' . time(), 26 | 'ConfigurationTypeQuestions' => [ 27 | 'ConfigurationTypeQuestion' => [ 28 | 'Id' => 0, 29 | 'Question' => 'Question', 30 | 'SequenceNumber' => '1.00', 31 | 'FieldType' => 'Text', 32 | // or 'Number' 33 | 'EntryType' => 'List', 34 | // or 'EntryField' (with no PossibleResponse!) 35 | 'ConfigurationTypeId' => 0, 36 | 'RequiredFlag' => false, 37 | 'InactiveFlag' => false, 38 | 'PossibleResponses' => [ 39 | 'PossibleResponse' => [ 40 | [ 41 | 'Id' => 0, 42 | 'Value' => 'PossibleResponse1', 43 | 'DefaultFlag' => false, 44 | 'ConfigurationTypeQuestionId' => 0 45 | ], 46 | [ 47 | 'Id' => 0, 48 | 'Value' => 'PossibleResponse2', 49 | 'DefaultFlag' => true, 50 | 'ConfigurationTypeQuestionId' => 0 51 | ] 52 | ] 53 | ] 54 | ] 55 | ] 56 | ]; 57 | 58 | $results = $this->fixture->addOrUpdateConfigurationType($data); 59 | $this->assertInternalType('object', $results); 60 | $results = $results->AddOrUpdateConfigurationTypeResult; 61 | $this->assertConfigurationTypeStructure($data, $results); 62 | 63 | return [ 64 | 'CT_ID' => $results->Id, 65 | 'CQ_ID' => $results->ConfigurationTypeQuestions->ConfigurationTypeQuestion->Id, 66 | 'PR_ID' => $results->ConfigurationTypeQuestions->ConfigurationTypeQuestion->PossibleResponses->PossibleResponse[0]->Id, 67 | 'PR_ID2' => $results->ConfigurationTypeQuestions->ConfigurationTypeQuestion->PossibleResponses->PossibleResponse[1]->Id 68 | ]; 69 | } 70 | 71 | /** 72 | * @depends testAddConfigurationType 73 | * @param $res 74 | */ 75 | public function testUpdateConfigurationType($res) 76 | { 77 | $data = [ 78 | 'Id' => $res['CT_ID'], 79 | 'InactiveFlag' => false, 80 | 'SystemFlag' => false, 81 | 'Name' => 'IntegrationTestType' . time(), 82 | 'ConfigurationTypeQuestions' => [ 83 | 'ConfigurationTypeQuestion' => [ 84 | 'Id' => $res['CQ_ID'], 85 | 'Question' => 'Question', 86 | 'SequenceNumber' => '1.00', 87 | 'FieldType' => 'Text', 88 | // or 'Number' 89 | 'EntryType' => 'List', 90 | // or 'EntryField' (with no PossibleResponse!) 91 | 'ConfigurationTypeId' => $res['CT_ID'], 92 | 'RequiredFlag' => false, 93 | 'InactiveFlag' => false, 94 | 'PossibleResponses' => [ 95 | 'PossibleResponse' => [ 96 | [ 97 | 'Id' => $res['PR_ID'], 98 | 'Value' => 'PossibleResponse1', 99 | 'DefaultFlag' => false, 100 | 'ConfigurationTypeQuestionId' => $res['CQ_ID'] 101 | ], 102 | [ 103 | 'Id' => $res['PR_ID2'], 104 | 'Value' => 'PossibleResponse2', 105 | 'DefaultFlag' => true, 106 | 'ConfigurationTypeQuestionId' => $res['CQ_ID'] 107 | ] 108 | ] 109 | ] 110 | ] 111 | ] 112 | ]; 113 | 114 | $results = $this->fixture->addOrUpdateConfigurationType($data); 115 | $this->assertInternalType('object', $results); 116 | $results = $results->AddOrUpdateConfigurationTypeResult; 117 | $this->assertConfigurationTypeStructure($data, $results); 118 | 119 | $res['Data'] = $data; 120 | return $res; 121 | } 122 | 123 | /** 124 | * @depends testUpdateConfigurationType 125 | * @param $res 126 | */ 127 | public function testGetConfigurationType($res) 128 | { 129 | $data = $res['Data']; 130 | $results = $this->fixture->getConfigurationType($res['CT_ID']); 131 | $this->assertInternalType('object', $results); 132 | $results = $results->GetConfigurationTypeResult; 133 | $this->assertConfigurationTypeStructure($data, $results); 134 | } 135 | 136 | /** 137 | * @depends testAddConfigurationType 138 | * @param $res 139 | */ 140 | public function testAddConfiguration($res) 141 | { 142 | $data = [ 143 | 'Id' => 0, 144 | 'ConfigurationTypeId' => $res['CT_ID'], 145 | 'ConfigurationName' => 'Integration Configuration', 146 | 'CompanyId' => 1 147 | ]; 148 | 149 | $results = $this->fixture->addOrUpdateConfiguration($data); 150 | $this->assertInternalType('object', $results); 151 | $results = $results->AddOrUpdateConfigurationResult; 152 | $this->assertConfigurationStructure($data, $results); 153 | 154 | $res['ConfigID'] = $results->Id; 155 | return $res; 156 | } 157 | 158 | /** 159 | * @depends testAddConfiguration 160 | * @param $res 161 | */ 162 | public function testUpdateConfiguration($res) 163 | { 164 | $data = [ 165 | 'Id' => $res['ConfigID'], 166 | 'ConfigurationTypeId' => $res['CT_ID'], 167 | 'ConfigurationName' => 'Integration Config', 168 | 'CompanyId' => 1 169 | ]; 170 | 171 | $results = $this->fixture->addOrUpdateConfiguration($data); 172 | $this->assertInternalType('object', $results); 173 | $results = $results->AddOrUpdateConfigurationResult; 174 | $this->assertConfigurationStructure($data, $results); 175 | 176 | $res['Data'] = $data; 177 | return $res; 178 | } 179 | 180 | /** 181 | * @depends testUpdateConfiguration 182 | * @param $res 183 | */ 184 | public function testGetConfiguration($res) 185 | { 186 | $results = $this->fixture->getConfiguration($res['ConfigID']); 187 | $this->assertInternalType('object', $results); 188 | $results = $results->GetConfigurationResult; 189 | $this->assertConfigurationStructure($res['Data'], $results); 190 | } 191 | 192 | /** 193 | * @dataProvider singleVsMultipleCheckDataProvider 194 | * @param $count 195 | */ 196 | public function testFindConfigurations($count) 197 | { 198 | $results = $this->fixture->findConfigurations($count, 0, '', ''); 199 | 200 | $this->assertInternalType('object', $results); 201 | $this->assertInternalType('object', $results->FindConfigurationsResult); 202 | if ($count === 1) { 203 | $this->assertConfigurationFindStructure($results->FindConfigurationsResult->ConfigurationFindResult); 204 | } else { 205 | $this->assertInternalType('array', $results->FindConfigurationsResult->ConfigurationFindResult); 206 | foreach ($results->FindConfigurationsResult->ConfigurationFindResult as $item) { 207 | $this->assertConfigurationFindStructure($item); 208 | } 209 | } 210 | } 211 | 212 | public function testFindConfigurationsCount() 213 | { 214 | $results = $this->fixture->findConfigurationsCount(true, ''); 215 | $this->assertInternalType('object', $results); 216 | $this->assertInternalType('integer', $results->FindConfigurationsCountResult); 217 | } 218 | 219 | /** 220 | * @dataProvider singleVsMultipleCheckDataProvider 221 | */ 222 | public function testFindConfigurationTypes($count) 223 | { 224 | $results = $this->fixture->findConfigurationTypes($count, 0, '', ''); 225 | $this->assertInternalType('object', $results); 226 | $this->assertInternalType('object', $results->FindConfigurationTypesResult); 227 | if ($count === 1) { 228 | $this->assertInternalType('object', $results->FindConfigurationTypesResult->ConfigurationTypeFindResult); 229 | $items = [$results->FindConfigurationTypesResult->ConfigurationTypeFindResult]; 230 | } else { 231 | $this->assertInternalType('array', $results->FindConfigurationTypesResult->ConfigurationTypeFindResult); 232 | $items = $results->FindConfigurationTypesResult->ConfigurationTypeFindResult; 233 | } 234 | 235 | foreach ($items as $item) { 236 | $this->assertInternalType('object', $item); 237 | $this->assertInternalType('integer', $item->Id); 238 | $this->assertInternalType('string', $item->Name); 239 | $this->assertInternalType('boolean', $item->InactiveFlag); 240 | $this->assertInternalType('boolean', $item->SystemFlag); 241 | } 242 | } 243 | 244 | /** 245 | * @depends testAddConfigurationType 246 | * @param $res 247 | */ 248 | public function testDeletePossibleResponse($res) 249 | { 250 | $results = $this->fixture->deletePossibleResponse($res['PR_ID']); 251 | $this->assertInternalType('object', $results); 252 | $this->assertTrue(empty((array)$results)); 253 | } 254 | 255 | /** 256 | * @depends testAddConfigurationType 257 | * @param $res 258 | */ 259 | public function testDeleteConfigurationTypeQuestion($res) 260 | { 261 | $results = $this->fixture->deleteConfigurationTypeQuestion($res['CQ_ID']); 262 | $this->assertInternalType('object', $results); 263 | $this->assertTrue(empty((array)$results)); 264 | } 265 | 266 | /** 267 | * @depends testAddConfiguration 268 | * @param $res 269 | */ 270 | public function testDeleteConfiguration($res) 271 | { 272 | $results = $this->fixture->deleteConfiguration($res['ConfigID']); 273 | $this->assertInternalType('object', $results); 274 | $this->assertTrue(empty((array)$results)); 275 | } 276 | 277 | /** 278 | * @depends testAddConfigurationType 279 | * @param $res 280 | */ 281 | public function testDeleteConfigurationType($res) 282 | { 283 | $results = $this->fixture->deleteConfigurationType($res['CT_ID']); 284 | $this->assertInternalType('object', $results); 285 | $this->assertTrue(empty((array)$results)); 286 | } 287 | 288 | /** 289 | * @param $data 290 | * @param $result 291 | */ 292 | private function assertConfigurationStructure($data, $results) 293 | { 294 | $this->assertInternalType('object', $results); 295 | $this->assertInternalType('integer', $results->Id); 296 | $this->assertInternalType('integer', $results->ConfigurationTypeId); 297 | $this->assertInternalType('integer', $results->StatusId); 298 | $this->assertInternalType('string', $results->Status); 299 | $this->assertSame($data['ConfigurationName'], $results->ConfigurationName); 300 | $this->assertSame($data['CompanyId'], $results->CompanyId); 301 | $this->assertInternalType('integer', $results->ContactId); 302 | $this->assertInternalType('integer', $results->OwnerLevelId); 303 | $this->assertInternalType('integer', $results->BillingUnitId); 304 | $this->assertInternalType('string', $results->Manufacturer); 305 | $this->assertInternalType('integer', $results->ManufacturerId); 306 | $this->assertInternalType('string', $results->SerialNumber); 307 | $this->assertInternalType('string', $results->ModelNumber); 308 | $this->assertInternalType('string', $results->TagNumber); 309 | $this->assertNotFalse(strtotime($results->PurchaseDate)); 310 | $this->assertNotFalse(strtotime($results->InstallationDate)); 311 | $this->assertInternalType('string', $results->InstalledBy); 312 | $this->assertNotFalse(strtotime($results->WarrantyExpiration)); 313 | $this->assertNotFalse(strtotime($results->LastUpdate)); 314 | $this->assertInternalType('string', $results->UpdatedBy); 315 | $this->assertNull($results->AddressId); 316 | $this->assertInternalType('string', $results->VendorNotes); 317 | $this->assertInternalType('string', $results->Notes); 318 | $this->assertInternalType('string', $results->MacAddress); 319 | $this->assertInternalType('string', $results->LastLoginName); 320 | $this->assertInternalType('boolean', $results->BillFlag); 321 | $this->assertInternalType('integer', $results->BackupSuccesses); 322 | $this->assertInternalType('integer', $results->BackupIncomplete); 323 | $this->assertInternalType('integer', $results->BackupFailed); 324 | $this->assertInternalType('integer', $results->BackupRestores); 325 | $this->assertNotFalse(strtotime($results->LastBackupDate)); 326 | $this->assertInternalType('string', $results->BackupServerName); 327 | $this->assertInternalType('string', $results->BackupBillableSpaceGb); 328 | $this->assertInternalType('string', $results->BackupProtectedDeviceList); 329 | $this->assertInternalType('integer', $results->BackupYear); 330 | $this->assertInternalType('integer', $results->BackupMonth); 331 | $this->assertInternalType('string', $results->IPAddress); 332 | $this->assertInternalType('string', $results->DefaultGateway); 333 | $this->assertInternalType('string', $results->OSType); 334 | $this->assertInternalType('string', $results->OSInfo); 335 | $this->assertInternalType('string', $results->CPUSpeed); 336 | $this->assertInternalType('string', $results->RAM); 337 | $this->assertInternalType('string', $results->LocalHardDrives); 338 | $this->assertInternalType('boolean', $results->IsActive); 339 | $this->assertNull($results->ParentConfigurationID); 340 | $this->assertInternalType('object', $results->ConfigurationQuestions); 341 | $this->assertInternalType('object', $results->VendorCompany); 342 | $this->assertInternalType('integer', $results->VendorCompany->Id); 343 | $this->assertInternalType('string', $results->VendorCompany->Name); 344 | $this->assertInternalType('object', $results->ManufacturerCompany); 345 | $this->assertInternalType('integer', $results->ManufacturerCompany->Id); 346 | $this->assertInternalType('string', $results->ManufacturerCompany->Name); 347 | } 348 | 349 | /** 350 | * @param $data 351 | * @param $result 352 | */ 353 | private function assertConfigurationTypeStructure($data, $results) 354 | { 355 | $dataQuestions = $data['ConfigurationTypeQuestions']; 356 | $dataResponses = $dataQuestions['ConfigurationTypeQuestion']['PossibleResponses']; 357 | 358 | $questions = $results->ConfigurationTypeQuestions; 359 | $responses = $questions->ConfigurationTypeQuestion->PossibleResponses; 360 | 361 | // Type Assertions 362 | $this->assertInternalType('object', $results); 363 | $this->assertInternalType('integer', $results->Id); 364 | $this->assertInternalType('string', $results->UpdatedBy); 365 | 366 | $this->assertInternalType('object', $questions); 367 | $this->assertInternalType('object', $questions->ConfigurationTypeQuestion); 368 | $this->assertInternalType('integer', $questions->ConfigurationTypeQuestion->Id); 369 | $this->assertInternalType('integer', $questions->ConfigurationTypeQuestion->ConfigurationTypeId); 370 | $this->assertInternalType('integer', $questions->ConfigurationTypeQuestion->NumberOfDecimals); 371 | 372 | $this->assertInternalType('object', $responses); 373 | $this->assertInternalType('array', $responses->PossibleResponse); 374 | $this->assertInternalType('object', $responses->PossibleResponse[0]); 375 | $this->assertInternalType('object', $responses->PossibleResponse[1]); 376 | $this->assertInternalType('integer', $responses->PossibleResponse[0]->Id); 377 | $this->assertInternalType('integer', $responses->PossibleResponse[1]->Id); 378 | $this->assertInternalType('integer', $responses->PossibleResponse[0]->ConfigurationTypeQuestionId); 379 | $this->assertInternalType('integer', $responses->PossibleResponse[1]->ConfigurationTypeQuestionId); 380 | 381 | // Value Assertions 382 | $this->assertSame($data['Name'], $results->Name); 383 | $this->assertSame($data['InactiveFlag'], $results->InactiveFlag); 384 | $this->assertSame($data['SystemFlag'], $results->SystemFlag); 385 | 386 | $this->assertSame( 387 | $dataQuestions['ConfigurationTypeQuestion']['FieldType'], 388 | $questions->ConfigurationTypeQuestion->FieldType 389 | ); 390 | $this->assertSame( 391 | $dataQuestions['ConfigurationTypeQuestion']['EntryType'], 392 | $questions->ConfigurationTypeQuestion->EntryType 393 | ); 394 | $this->assertSame( 395 | $dataQuestions['ConfigurationTypeQuestion']['SequenceNumber'], 396 | $questions->ConfigurationTypeQuestion->SequenceNumber 397 | ); 398 | $this->assertSame( 399 | $dataQuestions['ConfigurationTypeQuestion']['Question'], 400 | $questions->ConfigurationTypeQuestion->Question 401 | ); 402 | $this->assertSame( 403 | $dataQuestions['ConfigurationTypeQuestion']['RequiredFlag'], 404 | $questions->ConfigurationTypeQuestion->RequiredFlag 405 | ); 406 | $this->assertSame( 407 | $dataQuestions['ConfigurationTypeQuestion']['InactiveFlag'], 408 | $questions->ConfigurationTypeQuestion->InactiveFlag 409 | ); 410 | 411 | $this->assertSame($dataResponses['PossibleResponse'][0]['Value'], $responses->PossibleResponse[0]->Value); 412 | $this->assertSame($dataResponses['PossibleResponse'][1]['Value'], $responses->PossibleResponse[1]->Value); 413 | $this->assertSame( 414 | $dataResponses['PossibleResponse'][0]['DefaultFlag'], 415 | $responses->PossibleResponse[0]->DefaultFlag 416 | ); 417 | $this->assertSame( 418 | $dataResponses['PossibleResponse'][1]['DefaultFlag'], 419 | $responses->PossibleResponse[1]->DefaultFlag 420 | ); 421 | } 422 | 423 | private function assertConfigurationFindStructure($item) 424 | { 425 | $this->assertInternalType('integer', $item->Id); 426 | $this->assertInternalType('integer', $item->ConfigurationTypeId); 427 | $this->assertInternalType('string', $item->ConfigurationType); 428 | $this->assertInternalType('integer', $item->StatusId); 429 | $this->assertInternalType('string', $item->Status); 430 | $this->assertInternalType('string', $item->CompanyId); 431 | $this->assertInternalType('string', $item->ConfigurationName); 432 | $this->assertInternalType('string', $item->ContactName); 433 | $this->assertInternalType('string', $item->SerialNumber); 434 | $this->assertInternalType('string', $item->ModelNumber); 435 | $this->assertInternalType('string', $item->TagNumber); 436 | if ($item->WarrantyExpiration !== null) { 437 | $this->assertNotFalse(strtotime($item->WarrantyExpiration)); 438 | } 439 | } 440 | 441 | /** 442 | * @return array 443 | */ 444 | public static function singleVsMultipleCheckDataProvider() 445 | { 446 | return [ 447 | [1], 448 | [2], 449 | [5] 450 | ]; 451 | } 452 | } 453 | -------------------------------------------------------------------------------- /tests/ConnectWise/integration/DocumentIntegrationTest.php: -------------------------------------------------------------------------------- 1 | configuration = parent::setUp(); 12 | $this->configuration['url']['cw_api_main'] = 'https://%s/v4_6_release/apis/2.0/%s.asmx?wsdl'; 13 | $this->factory = new ConnectwiseApiFactory(); 14 | $this->fixture = $this->factory->make('Document', $this->configuration); 15 | } 16 | 17 | public function testAddDocument() 18 | { 19 | $objectId = 1176; 20 | $documentTableReference = 'Ticket'; 21 | $data = [ 22 | 'Id' => 0, 23 | 'Title' => 'integration_test_file', 24 | 'FileName' => 'integration_test_file.txt', 25 | 'LastUpdated' => '2014-12-11', 26 | 'IsLink' => false, 27 | 'IsImage' => false, 28 | 'IsPublic' => true, 29 | 'Content' => 'VGhpcyBpcyBhIGZpbGUgZm9yIGludGVncmF0aW9uIHRlc3Rpbmcu' 30 | ]; 31 | 32 | $results = $this->fixture->addDocuments($objectId, $documentTableReference, [$data]); 33 | $this->assertInternalType('object', $results->AddDocumentsResult); 34 | $this->assertDocumentStructure($data, $results->AddDocumentsResult->DocumentInfo); 35 | 36 | return ['ID' =>$results->AddDocumentsResult->DocumentInfo->Id, 'Data' => $data]; 37 | } 38 | 39 | public function testAddDocumentAsLink() 40 | { 41 | $objectId = 1176; 42 | $documentTableReference = 'Ticket'; 43 | $data = [ 44 | 'Id' => 0, 45 | 'Title' => 'http://pastebin.com/raw.php?i=vu43mBRF', 46 | 'FileName' => 'http://pastebin.com/raw.php?i=vu43mBRF', 47 | 'LastUpdated' => '2014-12-11', 48 | 'IsLink' => true, 49 | 'IsImage' => false, 50 | 'IsPublic' => true 51 | ]; 52 | 53 | $results = $this->fixture->addDocuments($objectId, $documentTableReference, [$data]); 54 | $this->assertInternalType('object', $results->AddDocumentsResult); 55 | $this->assertDocumentStructure($data, $results->AddDocumentsResult->DocumentInfo, false); 56 | } 57 | 58 | /** 59 | * @depends testAddDocument 60 | * @param $res 61 | */ 62 | public function testGetDocument($res) 63 | { 64 | $results = $this->fixture->getDocument($res['ID']); 65 | 66 | $this->assertDocumentStructure($res['Data'], $results->GetDocumentResult); 67 | } 68 | 69 | private function assertDocumentStructure($data, $result, $withContent = true) 70 | { 71 | $this->assertInternalType('object', $result); 72 | $this->assertInternalType('integer', $result->Id); 73 | if (isset($result->Title)) { 74 | $this->assertSame($data['Title'], $result->Title); 75 | } 76 | $this->assertSame($data['FileName'], $result->FileName); 77 | $this->assertNotFalse(strtotime($result->LastUpdated)); 78 | $this->assertSame($data['IsLink'], $result->IsLink); 79 | $this->assertSame($data['IsImage'], $result->IsImage); 80 | $this->assertSame($data['IsPublic'], $result->IsPublic); 81 | if ($withContent === true) { 82 | $this->assertSame($data['Content'], $result->Content); 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /tests/ConnectWise/integration/PsaTestCase.php: -------------------------------------------------------------------------------- 1 | configuration = parent::setUp(); 12 | $this->factory = new ConnectwiseApiFactory(); 13 | $this->fixture = $this->factory->make('Reporting', $this->configuration); 14 | } 15 | 16 | public function testGetReports() 17 | { 18 | $results = $this->fixture->getReports(false); 19 | $this->assertInternalType('object', $results); 20 | $this->assertInternalType('object', $results->GetReportsResult); 21 | $this->assertInternalType('array', $results->GetReportsResult->Report); 22 | foreach ($results->GetReportsResult->Report as $report) { 23 | $this->assertInternalType('string', $report->Name); 24 | $this->assertInternalType('integer', $report->Id); 25 | $this->assertInternalType('boolean', $report->IsCustom); 26 | $this->assertInternalType('boolean', $report->VisibleFlag); 27 | $this->assertInternalType('boolean', $report->OpenNewWindowFlag); 28 | } 29 | } 30 | 31 | public function testGetReportFields() 32 | { 33 | $results = $this->fixture->getReportFields('Service'); 34 | $this->assertInternalType('object', $results); 35 | $this->assertInternalType('object', $results->GetReportFieldsResult); 36 | $this->assertInternalType('array', $results->GetReportFieldsResult->FieldInfo); 37 | foreach ($results->GetReportFieldsResult->FieldInfo as $field) { 38 | $this->assertInternalType('string', $field->Name); 39 | $this->assertInternalType('string', $field->Type); 40 | $this->assertInternalType('boolean', $field->IsNullable); 41 | } 42 | } 43 | 44 | public function testRunReportCount() 45 | { 46 | $results = $this->fixture->runReportCount('Service'); 47 | $this->assertInternalType('object', $results); 48 | $this->assertInternalType('integer', $results->RunReportCountResult); 49 | } 50 | 51 | public function testRunReportQuery() 52 | { 53 | $results = $this->fixture->runReportQuery('Service', 3, 0, '', ''); 54 | $this->assertInternalType('array', $results); 55 | foreach ($results as $report) { 56 | $this->assertInternalType('object', $report); 57 | $this->assertInternalType('string', $report->TicketNbr); 58 | $this->assertInternalType('string', $report->owner_level_recid); 59 | $this->assertInternalType('string', $report->Location); 60 | $this->assertInternalType('string', $report->billing_unit_recid); 61 | $this->assertInternalType('string', $report->BusGroup); 62 | $this->assertInternalType('string', $report->SR_Board_RecID); 63 | $this->assertInternalType('string', $report->Board_Name); 64 | $this->assertInternalType('string', $report->Site_Name); 65 | $this->assertInternalType('string', $report->sr_status_recid); 66 | $this->assertInternalType('string', $report->Urgency); 67 | $this->assertInternalType('string', $report->service_location); 68 | $this->assertInternalType('string', $report->Status_SortOrder); 69 | $this->assertInternalType('string', $report->status_description); 70 | $this->assertInternalType('string', $report->Source); 71 | $this->assertInternalType('string', $report->Closed_Flag); 72 | $this->assertInternalType('string', $report->ClosedDesc); 73 | $this->assertInternalType('string', $report->date_closed); 74 | $this->assertInternalType('string', $report->closed_by); 75 | $this->assertInternalType('string', $report->Type_RecID); 76 | $this->assertInternalType('string', $report->ServiceType); 77 | $this->assertInternalType('string', $report->SubType_RecID); 78 | $this->assertInternalType('string', $report->ServiceSubType); 79 | $this->assertInternalType('string', $report->SubTypeItem_RecID); 80 | $this->assertInternalType('string', $report->ServiceSubTypeItem); 81 | $this->assertInternalType('string', $report->company_name); 82 | $this->assertInternalType('string', $report->company_recid); 83 | $this->assertInternalType('string', $report->contact_name); 84 | $this->assertInternalType('string', $report->contact_recid); 85 | $this->assertInternalType('string', $report->Address_Line1); 86 | $this->assertInternalType('string', $report->Address_Line2); 87 | $this->assertInternalType('string', $report->City); 88 | $this->assertInternalType('string', $report->State); 89 | $this->assertInternalType('string', $report->PostalCode); 90 | $this->assertInternalType('string', $report->Country); 91 | $this->assertInternalType('string', $report->Summary); 92 | $this->assertInternalType('string', $report->Detail_Description); 93 | $this->assertInternalType('string', $report->Internal_Analysis); 94 | $this->assertInternalType('string', $report->Resolution); 95 | $this->assertInternalType('string', $report->AGR_Header_RecID); 96 | $this->assertInternalType('string', $report->agreement_name); 97 | $this->assertInternalType('string', $report->team_name); 98 | $this->assertInternalType('string', $report->Territory); 99 | $this->assertInternalType('string', $report->territory_recid); 100 | $this->assertInternalType('string', $report->Territory_Manager); 101 | $this->assertInternalType('string', $report->date_entered); 102 | $this->assertInternalType('string', $report->entered_by); 103 | $this->assertInternalType('string', $report->Approved); 104 | $this->assertInternalType('string', $report->Last_Update); 105 | $this->assertInternalType('string', $report->Time_Zone); 106 | $this->assertInternalType('string', $report->Updated_By); 107 | $this->assertInternalType('string', $report->Date_Required); 108 | $this->assertInternalType('string', $report->Hours_Actual); 109 | $this->assertInternalType('string', $report->Hours_Budget); 110 | $this->assertInternalType('string', $report->Hours_Scheduled); 111 | $this->assertInternalType('string', $report->Hours_Billable); 112 | $this->assertInternalType('string', $report->Hours_NonBillable); 113 | $this->assertInternalType('string', $report->Hours_Invoiced); 114 | $this->assertInternalType('string', $report->Hours_Agreement); 115 | $this->assertInternalType('string', $report->Parent); 116 | $this->assertInternalType('string', $report->resource_list); 117 | $this->assertInternalType('string', $report->Assigned_By_RecID); 118 | $this->assertInternalType('string', $report->Age); 119 | $this->assertInternalType('string', $report->Date_Resolved_UTC); 120 | $this->assertInternalType('string', $report->Date_Resplan_UTC); 121 | $this->assertInternalType('string', $report->Date_Responded_UTC); 122 | $this->assertInternalType('string', $report->Date_Status_Changed_UTC); 123 | $this->assertInternalType('string', $report->Escalation_Start_Date_UTC); 124 | $this->assertInternalType('string', $report->Minutes_Before_Waiting); 125 | $this->assertInternalType('string', $report->Minutes_Waiting); 126 | $this->assertInternalType('string', $report->Overall_Start_Date_UTC); 127 | $this->assertInternalType('string', $report->Previous_SR_Status_RecID); 128 | $this->assertInternalType('string', $report->Resolved_By); 129 | $this->assertInternalType('string', $report->Resolved_Minutes); 130 | $this->assertInternalType('string', $report->Resplan_Minutes); 131 | $this->assertInternalType('string', $report->Resplan_Skipped_Minutes); 132 | $this->assertInternalType('string', $report->Responded_By); 133 | $this->assertInternalType('string', $report->Responded_Minutes); 134 | $this->assertInternalType('string', $report->Responded_Skipped_Minutes); 135 | $this->assertInternalType('string', $report->Waiting_Flag); 136 | $this->assertInternalType('string', $report->Severity); 137 | $this->assertInternalType('string', $report->SR_Severity_RecID); 138 | $this->assertInternalType('string', $report->Impact); 139 | $this->assertInternalType('string', $report->SR_Impact_RecID); 140 | $this->assertInternalType('string', $report->Opportunity_RecID); 141 | $this->assertInternalType('string', $report->SR_Service_RecID); 142 | $this->assertInternalType('string', $report->Date_Entered_UTC); 143 | $this->assertInternalType('string', $report->Date_Closed_UTC); 144 | } 145 | } 146 | 147 | public function testRunReportQueryWithFilters() 148 | { 149 | $results = $this->fixture->runReportQueryWithFilters('Service', 3, 0, '', '', ['Last_Update']); 150 | $this->assertInternalType('object', $results); 151 | $this->assertInternalType('object', $results->RunReportQueryWithFiltersResult); 152 | $this->assertInternalType('array', $results->RunReportQueryWithFiltersResult->ResultRow); 153 | foreach ($results->RunReportQueryWithFiltersResult->ResultRow as $report) { 154 | $this->assertInternalType('object', $report); 155 | $this->assertInternalType('object', $report->Value); 156 | $this->assertNotFalse(strtotime($report->Value->_)); 157 | $this->assertInternalType('string', $report->Value->Name); 158 | $this->assertInternalType('string', $report->Value->Type); 159 | $this->assertInternalType('boolean', $report->Value->IsNullable); 160 | $this->assertInternalType('integer', $report->Number); 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ApiExceptionTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('ConnectWise API Error: An exception message.', $apiException->getMessage()); 12 | } 13 | 14 | public function testConstructorWithMessagePrefixedWithSoapError() 15 | { 16 | $apiException = new ApiException('SOAP-ERROR: Could not reach CW API', 0, null); 17 | 18 | $this->assertEquals('ConnectWise API Error: Could not reach CW API', $apiException->getMessage()); 19 | } 20 | 21 | 22 | public function testConstructorWithOnlySoapErrorInMessage() 23 | { 24 | $apiException = new ApiException('SOAP-ERROR:', 0, null); 25 | 26 | $this->assertEquals('ConnectWise API Error: SOAP-ERROR:', $apiException->getMessage()); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/CompanyTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('LabtechSoftware\ConnectwisePsaSdk\ConnectWiseApi') 13 | ->disableOriginalConstructor() 14 | ->getMock(); 15 | 16 | $this->fixture = new Company($client); 17 | } 18 | 19 | 20 | /** 21 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::addOrUpdateCompany 22 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 23 | */ 24 | public function testPassEmptyArrayToAddOrUpdateCompany() 25 | { 26 | $this->fixture->addOrUpdateCompany(array()); 27 | } 28 | 29 | /** 30 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::getCompany 31 | * @expectedException LabTechSoftware\ConnectwisePsaSdk\ApiException 32 | */ 33 | public function testPassStringToGetCompany() 34 | { 35 | $this->fixture->getCompany('hello'); 36 | } 37 | 38 | 39 | /** 40 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::getCompany 41 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 42 | */ 43 | public function testPassZeroToGetCompany() 44 | { 45 | $this->fixture->getCompany(0); 46 | } 47 | 48 | /** 49 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::deleteCompany 50 | * @expectedException LabtechSoftware\ConnectWisePsaSdk\ApiException 51 | */ 52 | public function testPassStringToDeleteCompany() 53 | { 54 | $this->fixture->deleteCompany('a string'); 55 | } 56 | 57 | 58 | /** 59 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::findCompanies 60 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 61 | */ 62 | public function testFindCompaniesThrowsExceptionWhenLimitIsNotNumeric() 63 | { 64 | $this->fixture->findCompanies('', 0, '', ''); 65 | } 66 | 67 | /** 68 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::findCompanies 69 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 70 | */ 71 | public function testFindCompaniesThrowsExceptionWhenSkipIsNotNumeric() 72 | { 73 | $this->fixture->findCompanies(0, '', '', ''); 74 | } 75 | 76 | /** 77 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::findCompanies 78 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 79 | */ 80 | public function testFindCompaniesThrowsExceptionWhenOrderByIsNotString() 81 | { 82 | $this->fixture->findCompanies(0, 0, 0, ''); 83 | } 84 | 85 | /** 86 | * @covers LabtechSoftware\ConnectwisePsaSdk\Company::findCompanies 87 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 88 | */ 89 | public function testFindCompaniesThrowsExceptionWhenConditionsIsNotString() 90 | { 91 | $this->fixture->findCompanies(0, 0, '', 0); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ConfigLoaderTest.php: -------------------------------------------------------------------------------- 1 | fixture = new ConfigLoader; 20 | } 21 | 22 | /** 23 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::loadConfig 24 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 25 | * @expectedExceptionMessage Expecting string or array value. 26 | */ 27 | public function testLoadConfigThrowsExceptionWhenConfigIsNeitherStringNorArray() 28 | { 29 | $this->fixture->loadConfig(null); 30 | } 31 | 32 | /** 33 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::isValidPath 34 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 35 | * @expectedExceptionMessage Config file not found. 36 | */ 37 | public function testLoadConfigThrowsExceptionWhenConfigFileDoesNotExist() 38 | { 39 | $this->fixture->loadConfig('path/to/non/existant/file.php'); 40 | } 41 | 42 | /** 43 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::load 44 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 45 | * @expectedExceptionMessage config file is not formatted correctly 46 | */ 47 | public function testLoadThrowsExceptionWhenConfigFileIsNotFormattedCorrectly() 48 | { 49 | vfsStream::setup('root'); 50 | $file = vfsStream::url('root/config.php'); 51 | file_put_contents($file, 'Boo on invalid config file formats like this one.'); 52 | 53 | $this->fixture->loadConfig($file); 54 | } 55 | 56 | /** 57 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 58 | * @dataProvider validConfigItems 59 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 60 | * @expectedExceptionMessage Configuration array must be indexed with soap and its type must be array 61 | */ 62 | public function testValidateConfigItemsThrowsExceptionWhenSoapIsMissing($configValues) 63 | { 64 | unset($configValues['soap']); 65 | $this->fixture->loadConfig($configValues); 66 | } 67 | 68 | /** 69 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 70 | * @dataProvider validConfigItems 71 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 72 | * @expectedExceptionMessage Configuration array must be indexed with soap and its type must be array 73 | */ 74 | public function testValidateConfigItemsThrowsExceptionWhenSoapIsNotAnArray($configValues) 75 | { 76 | $configValues['soap'] = null; 77 | $this->fixture->loadConfig($configValues); 78 | } 79 | 80 | /** 81 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 82 | * @dataProvider validConfigItems 83 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 84 | * @expectedExceptionMessage soap array must be indexed with soap_version and its type must be integer 85 | */ 86 | public function testValidateConfigItemsThrowsExceptionWhenSoapVersionIsMissing($configValues) 87 | { 88 | unset($configValues['soap']['soap_version']); 89 | $this->fixture->loadConfig($configValues); 90 | } 91 | 92 | /** 93 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 94 | * @dataProvider validConfigItems 95 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 96 | * @expectedExceptionMessage soap array must be indexed with soap_version and its type must be integer 97 | */ 98 | public function testValidateConfigItemsThrowsExceptionWhenSoapVersionIsNotAnInteger($configValues) 99 | { 100 | $configValues['soap']['soap_version'] = null; 101 | $this->fixture->loadConfig($configValues); 102 | } 103 | 104 | /** 105 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 106 | * @dataProvider validConfigItems 107 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 108 | * @expectedExceptionMessage soap array must be indexed with exceptions and its type must be boolean 109 | */ 110 | public function testValidateConfigItemsThrowsExceptionWhenExceptionsIsMissing($configValues) 111 | { 112 | unset($configValues['soap']['exceptions']); 113 | $this->fixture->loadConfig($configValues); 114 | } 115 | 116 | /** 117 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 118 | * @dataProvider validConfigItems 119 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 120 | * @expectedExceptionMessage soap array must be indexed with exceptions and its type must be boolean 121 | */ 122 | public function testValidateConfigItemsThrowsExceptionWhenExceptionsIsNotBoolean($configValues) 123 | { 124 | $configValues['soap']['exceptions'] = null; 125 | $this->fixture->loadConfig($configValues); 126 | } 127 | 128 | /** 129 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 130 | * @dataProvider validConfigItems 131 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 132 | * @expectedExceptionMessage soap array must be indexed with trace and its type must be integer 133 | */ 134 | public function testValidateConfigItemsThrowsExceptionWhenTraceIsMissing($configValues) 135 | { 136 | unset($configValues['soap']['trace']); 137 | $this->fixture->loadConfig($configValues); 138 | } 139 | 140 | /** 141 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 142 | * @dataProvider validConfigItems 143 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 144 | * @expectedExceptionMessage soap array must be indexed with trace and its type must be integer 145 | */ 146 | public function testValidateConfigItemsThrowsExceptionWhenTraceIsNotAnInteger($configValues) 147 | { 148 | $configValues['soap']['trace'] = null; 149 | $this->fixture->loadConfig($configValues); 150 | } 151 | 152 | /** 153 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 154 | * @dataProvider validConfigItems 155 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 156 | * @expectedExceptionMessage soap array must be indexed with cache_wsdl and its type must be integer 157 | */ 158 | public function testValidateConfigItemsThrowsExceptionWhenCacheWsdlIsMissing($configValues) 159 | { 160 | unset($configValues['soap']['cache_wsdl']); 161 | $this->fixture->loadConfig($configValues); 162 | } 163 | 164 | /** 165 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 166 | * @dataProvider validConfigItems 167 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 168 | * @expectedExceptionMessage soap array must be indexed with cache_wsdl and its type must be integer 169 | */ 170 | public function testValidateConfigItemsThrowsExceptionWhenCacheWsdlIsNotAnInteger($configValues) 171 | { 172 | $configValues['soap']['cache_wsdl'] = null; 173 | $this->fixture->loadConfig($configValues); 174 | } 175 | 176 | /** 177 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 178 | * @dataProvider validConfigItems 179 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 180 | * @expectedExceptionMessage Configuration array must be indexed with url and its type must be array 181 | */ 182 | public function testValidateConfigItemsThrowsExceptionWhenUrlIsMissing($configValues) 183 | { 184 | unset($configValues['url']); 185 | $this->fixture->loadConfig($configValues); 186 | } 187 | 188 | /** 189 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 190 | * @dataProvider validConfigItems 191 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 192 | * @expectedExceptionMessage Configuration array must be indexed with url and its type must be array 193 | */ 194 | public function testValidateConfigItemsThrowsExceptionWhenUrlIsNotAnArray($configValues) 195 | { 196 | $configValues['url'] = null; 197 | $this->fixture->loadConfig($configValues); 198 | } 199 | 200 | /** 201 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 202 | * @dataProvider validConfigItems 203 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 204 | * @expectedExceptionMessage url array must be indexed with cw_api_main and its type must be string 205 | */ 206 | public function testValidateConfigItemsThrowsExceptionWhenCwApiMainIsMissing($configValues) 207 | { 208 | unset($configValues['url']['cw_api_main']); 209 | $this->fixture->loadConfig($configValues); 210 | } 211 | 212 | /** 213 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 214 | * @dataProvider validConfigItems 215 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 216 | * @expectedExceptionMessage url array must be indexed with cw_api_main and its type must be string 217 | */ 218 | public function testValidateConfigItemsThrowsExceptionWhenCwApiMainIsNotAString($configValues) 219 | { 220 | $configValues['url']['cw_api_main'] = null; 221 | $this->fixture->loadConfig($configValues); 222 | } 223 | 224 | /** 225 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 226 | * @dataProvider validConfigItems 227 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 228 | * @expectedExceptionMessage url array must be indexed with cw_api_main and its type must be string 229 | */ 230 | public function testValidateConfigItemsThrowsExceptionWhenCwApiMainIsAnEmptyString($configValues) 231 | { 232 | $configValues['url']['cw_api_main'] = ''; 233 | $this->fixture->loadConfig($configValues); 234 | } 235 | 236 | /** 237 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 238 | * @dataProvider validConfigItems 239 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 240 | * @expectedExceptionMessage Configuration array must be indexed with credentials and its type must be array 241 | */ 242 | public function testValidateConfigItemsThrowsExceptionWhenCredentialsIsMissing($configValues) 243 | { 244 | unset($configValues['credentials']); 245 | $this->fixture->loadConfig($configValues); 246 | } 247 | 248 | /** 249 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 250 | * @dataProvider validConfigItems 251 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 252 | * @expectedExceptionMessage Configuration array must be indexed with credentials and its type must be array 253 | */ 254 | public function testValidateConfigItemsThrowsExceptionWhenCredentialsIsNotAnArray($configValues) 255 | { 256 | $configValues['credentials'] = null; 257 | $this->fixture->loadConfig($configValues); 258 | } 259 | 260 | /** 261 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 262 | * @dataProvider validConfigItems 263 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 264 | * @expectedExceptionMessage credentials array must be indexed with domain and its type must be string 265 | */ 266 | public function testValidateConfigItemsThrowsExceptionWhenDomainIsMissing($configValues) 267 | { 268 | unset($configValues['credentials']['domain']); 269 | $this->fixture->loadConfig($configValues); 270 | } 271 | 272 | /** 273 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 274 | * @dataProvider validConfigItems 275 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 276 | * @expectedExceptionMessage credentials array must be indexed with domain and its type must be string 277 | */ 278 | public function testValidateConfigItemsThrowsExceptionWhenDomainIsNotAString($configValues) 279 | { 280 | $configValues['credentials']['domain'] = null; 281 | $this->fixture->loadConfig($configValues); 282 | } 283 | 284 | /** 285 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 286 | * @dataProvider validConfigItems 287 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 288 | * @expectedExceptionMessage credentials array must be indexed with domain and its type must be string 289 | */ 290 | public function testValidateConfigItemsThrowsExceptionWhenDomainIsAnEmptyString($configValues) 291 | { 292 | $configValues['credentials']['domain'] = ''; 293 | $this->fixture->loadConfig($configValues); 294 | } 295 | 296 | /** 297 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 298 | * @dataProvider validConfigItems 299 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 300 | * @expectedExceptionMessage credentials array must be indexed with CompanyId and its type must be string 301 | */ 302 | public function testValidateConfigItemsThrowsExceptionWhenCompanyIdIsMissing($configValues) 303 | { 304 | unset($configValues['credentials']['CompanyId']); 305 | $this->fixture->loadConfig($configValues); 306 | } 307 | 308 | /** 309 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 310 | * @dataProvider validConfigItems 311 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 312 | * @expectedExceptionMessage credentials array must be indexed with CompanyId and its type must be string 313 | */ 314 | public function testValidateConfigItemsThrowsExceptionWhenCompanyIdIsNotAString($configValues) 315 | { 316 | $configValues['credentials']['CompanyId'] = null; 317 | $this->fixture->loadConfig($configValues); 318 | } 319 | 320 | /** 321 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 322 | * @dataProvider validConfigItems 323 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 324 | * @expectedExceptionMessage credentials array must be indexed with CompanyId and its type must be string 325 | */ 326 | public function testValidateConfigItemsThrowsExceptionWhenCompanyIdIsAnEmptyString($configValues) 327 | { 328 | $configValues['credentials']['CompanyId'] = null; 329 | $this->fixture->loadConfig($configValues); 330 | } 331 | 332 | /** 333 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 334 | * @dataProvider validConfigItems 335 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 336 | * @expectedExceptionMessage credentials array must be indexed with IntegratorLoginId and its type must be string 337 | */ 338 | public function testValidateConfigItemsThrowsExceptionWhenIntegratorLoginIdIsMissing($configValues) 339 | { 340 | unset($configValues['credentials']['IntegratorLoginId']); 341 | $this->fixture->loadConfig($configValues); 342 | } 343 | 344 | /** 345 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 346 | * @dataProvider validConfigItems 347 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 348 | * @expectedExceptionMessage credentials array must be indexed with IntegratorLoginId and its type must be string 349 | */ 350 | public function testValidateConfigItemsThrowsExceptionWhenIntegratorLoginIdIsNotAString($configValues) 351 | { 352 | $configValues['credentials']['IntegratorLoginId'] = null; 353 | $this->fixture->loadConfig($configValues); 354 | } 355 | 356 | /** 357 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 358 | * @dataProvider validConfigItems 359 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 360 | * @expectedExceptionMessage credentials array must be indexed with IntegratorLoginId and its type must be string 361 | */ 362 | public function testValidateConfigItemsThrowsExceptionWhenIntegratorLoginIdIsAnEmptyString($configValues) 363 | { 364 | $configValues['credentials']['IntegratorLoginId'] = ''; 365 | $this->fixture->loadConfig($configValues); 366 | } 367 | 368 | /** 369 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 370 | * @dataProvider validConfigItems 371 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 372 | * @expectedExceptionMessage credentials array must be indexed with IntegratorPassword and its type must be string 373 | */ 374 | public function testValidateConfigItemsThrowsExceptionWhenIntegratorPasswordIsMissing($configValues) 375 | { 376 | unset($configValues['credentials']['IntegratorPassword']); 377 | $this->fixture->loadConfig($configValues); 378 | } 379 | 380 | /** 381 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 382 | * @dataProvider validConfigItems 383 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 384 | * @expectedExceptionMessage credentials array must be indexed with IntegratorPassword and its type must be string 385 | */ 386 | public function testValidateConfigItemsThrowsExceptionWhenIntegratorPasswordIsNotAString($configValues) 387 | { 388 | $configValues['credentials']['IntegratorPassword'] = null; 389 | $this->fixture->loadConfig($configValues); 390 | } 391 | 392 | /** 393 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConfigLoader::validateConfigItems 394 | * @dataProvider validConfigItems 395 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 396 | * @expectedExceptionMessage credentials array must be indexed with IntegratorPassword and its type must be string 397 | */ 398 | public function testValidateConfigItemsThrowsExceptionWhenIntegratorPasswordIsAnEmptyString($configValues) 399 | { 400 | $configValues['credentials']['IntegratorPassword'] = ''; 401 | $this->fixture->loadConfig($configValues); 402 | } 403 | /** 404 | * @return array 405 | */ 406 | public function validConfigItems() 407 | { 408 | return [ 409 | [ 410 | [ 411 | 'soap' => [ 412 | 'soap_version' => 1, 413 | 'exceptions' => true, 414 | 'trace' => 1, 415 | 'cache_wsdl' => 1, 416 | ], 417 | 'url' => [ 418 | 'cw_api_main' => 'cw_api_main' 419 | ], 420 | 'credentials' => [ 421 | 'domain' => 'domain', 422 | 'CompanyId' => 'CompanyId', 423 | 'IntegratorLoginId' => 'IntegratorLoginId', 424 | 'IntegratorPassword' => 'IntegratorPassword' 425 | ] 426 | ] 427 | ] 428 | ]; 429 | } 430 | } -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ConfigurationTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('LabtechSoftware\ConnectwisePsaSdk\ConnectWiseApi') 27 | ->disableOriginalConstructor() 28 | ->getMock(); 29 | 30 | $this->fixture = new Configuration($client); 31 | } 32 | 33 | /** 34 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurationTypes 35 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 36 | */ 37 | public function testFindConfigurationTypesThrowsExceptionWhenLimitIsNotNumeric() 38 | { 39 | $this->fixture->findConfigurationTypes('', 3, '', ''); 40 | } 41 | 42 | /** 43 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurationTypes 44 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 45 | */ 46 | public function testFindConfigurationTypesThrowsExceptionWhenSkipIsNotNumeric() 47 | { 48 | $this->fixture->findConfigurationTypes(3, '', '', ''); 49 | } 50 | 51 | /** 52 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurationTypes 53 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 54 | */ 55 | public function testFindConfigurationTypesThrowsExceptionWhenConditionsIsNotAString() 56 | { 57 | $this->fixture->findConfigurationTypes(3, 3, 3, ''); 58 | } 59 | 60 | /** 61 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurationTypes 62 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 63 | */ 64 | public function testFindConfigurationTypesThrowsExceptionWhenOrderByIsNotAString() 65 | { 66 | $this->fixture->findConfigurationTypes(3, 3, '', 3); 67 | } 68 | 69 | /** 70 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurations 71 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 72 | */ 73 | public function testFindConfigurationsThrowsExceptionWhenLimitIsNotNumeric() 74 | { 75 | $this->fixture->findConfigurations('', 3, '', ''); 76 | } 77 | 78 | /** 79 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurations 80 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 81 | */ 82 | public function testFindConfigurationsThrowsExceptionWhenSkipIsNotNumeric() 83 | { 84 | $this->fixture->findConfigurations(3, '', '', ''); 85 | } 86 | 87 | /** 88 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurations 89 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 90 | */ 91 | public function testFindConfigurationsThrowsExceptionWhenConditionsIsNotAString() 92 | { 93 | $this->fixture->findConfigurations(3, 3, 3, ''); 94 | } 95 | 96 | /** 97 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurations 98 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 99 | */ 100 | public function testFindConfigurationsThrowsExceptionWhenOrderByIsNotAString() 101 | { 102 | $this->fixture->findConfigurations(3, 3, '', 3); 103 | } 104 | 105 | 106 | /** 107 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurationsCount 108 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 109 | */ 110 | public function testFindConfigurationsCountThrowsExceptionWhenIsOpenIsNotBoolean() 111 | { 112 | $this->fixture->findConfigurationsCount(3); 113 | } 114 | 115 | /** 116 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::findConfigurationsCount 117 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 118 | */ 119 | public function testFindConfigurationsCountThrowsExceptionWhenConditionsIsNotAString() 120 | { 121 | $this->fixture->findConfigurationsCount(3); 122 | } 123 | 124 | /** 125 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::getConfiguration 126 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 127 | */ 128 | public function testGetConfigurationThrowsExceptionWhenIdIsNotNumeric() 129 | { 130 | $this->fixture->getConfiguration(''); 131 | } 132 | 133 | /** 134 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::getConfigurationType 135 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 136 | */ 137 | public function testGetConfigurationTypeThrowsExceptionWhenIdIsNotNumeric() 138 | { 139 | $this->fixture->getConfigurationType(''); 140 | } 141 | 142 | /** 143 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::deleteConfiguration 144 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 145 | */ 146 | public function testDeleteConfigurationThrowsExceptionWhenIdIsNotNumeric() 147 | { 148 | $this->fixture->deleteConfiguration(''); 149 | } 150 | 151 | /** 152 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::deleteConfigurationType 153 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 154 | */ 155 | public function testDeleteConfigurationTypeThrowsExceptionWhenIdIsNotNumeric() 156 | { 157 | $this->fixture->deleteConfigurationType(''); 158 | } 159 | 160 | /** 161 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::deleteConfigurationTypeQuestion 162 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 163 | */ 164 | public function testDeleteConfigurationTypeQuestionThrowsExceptionWhenIdIsNotNumeric() 165 | { 166 | $this->fixture->deleteConfigurationTypeQuestion(''); 167 | } 168 | 169 | /** 170 | * @covers LabtechSoftware\ConnectwisePsaSdk\Configuration::deletePossibleResponse 171 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 172 | */ 173 | public function testDeletePossibleResponseThrowsExceptionWhenIdIsNotNumeric() 174 | { 175 | $this->fixture->deletePossibleResponse(''); 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ConnectwiseApiFactoryTest.php: -------------------------------------------------------------------------------- 1 | fixture = new ConnectwiseApiFactory(); 16 | } 17 | 18 | /** 19 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConnectwiseApiFactory::make 20 | * @expectedException InvalidArgumentException 21 | * @expectedExceptionMessage Expecting string value. 22 | */ 23 | public function testMakeThrowsInvalidArgumentExceptionWhenApiIsNotAString() 24 | { 25 | $this->fixture->make(null); 26 | } 27 | 28 | /** 29 | * @covers LabtechSoftware\ConnectwisePsaSdk\ConnectwiseApiFactory::make 30 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 31 | * @expectedExceptionMessage Class does not exist 32 | */ 33 | public function testMakeThrowsApiExceptionWhenClassDoesNotExist() 34 | { 35 | $this->fixture->make('NonExistentClass'); 36 | } 37 | } 38 | 39 | 40 | ///** 41 | // * Tests for \ConnectwisePsaSdk\Contact 42 | // * @todo Add tests for addContactToGroup, getAvatarImage, removeContactFromGroup 43 | // * 44 | // * @covers LabtechSoftware\ConnectwisePsaSdk\Contact 45 | // */ 46 | //class ConnectWiseApiFactoryTest extends \PHPUnit_Framework_TestCase 47 | //{ 48 | // 49 | // protected $fixture; 50 | // 51 | // protected function setUp() 52 | // { 53 | // $this->fixture = new ConnectwiseApiFactory(); 54 | // } 55 | // 56 | // public function testMakeContact() 57 | // { 58 | // $this->assertInstanceOf('LabtechSoftware\ConnectwisePsaSdk\Contact', $this->fixture->makeContact()); 59 | // } 60 | // 61 | // public function testMakeCompany() 62 | // { 63 | // $this->assertInstanceOf('LabtechSoftware\ConnectwisePsaSdk\Company', $this->fixture->makeCompany()); 64 | // } 65 | // 66 | // public function testMakeConfiguration() 67 | // { 68 | // $this->assertInstanceOf('LabtechSoftware\ConnectwisePsaSdk\Configuration', $this->fixture->makeConfiguration()); 69 | // } 70 | // 71 | // public function testMakeReporting() 72 | // { 73 | // $this->assertInstanceOf('LabtechSoftware\ConnectwisePsaSdk\Reporting', $this->fixture->makeReporting()); 74 | // } 75 | // 76 | // public function testMakeServiceTicket() 77 | // { 78 | // $this->assertInstanceOf('LabtechSoftware\ConnectwisePsaSdk\ServiceTicket', $this->fixture->makeServiceTicket()); 79 | // } 80 | //} 81 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ContactTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('LabtechSoftware\ConnectwisePsaSdk\ConnectWiseApi') 26 | ->disableOriginalConstructor() 27 | ->getMock(); 28 | 29 | $this->fixture = new Contact($client); 30 | } 31 | 32 | 33 | /** 34 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::addContactToGroup 35 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 36 | */ 37 | public function testAddContactToGroupThrowsExceptionWhenContactIdIsNotNumeric() 38 | { 39 | $this->fixture->addContactToGroup('not numeric', 3, ''); 40 | } 41 | 42 | /** 43 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::addContactToGroup 44 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 45 | */ 46 | public function testAddContactToGroupThrowsExceptionWhenGroupIdIsNotNumeric() 47 | { 48 | $this->fixture->addContactToGroup(3, 'not numeric', ''); 49 | } 50 | 51 | /** 52 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::addContactToGroup 53 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 54 | */ 55 | public function testAddContactToGroupThrowsExceptionWhenNoteIsNotString() 56 | { 57 | $this->fixture->addContactToGroup(3, 3, 3); 58 | } 59 | 60 | /** 61 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::addOrUpdateContactCommunicationItem 62 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 63 | */ 64 | public function testAddOrUpdateContactCommunicationItemsThrowsExceptionWhenContactIdIsNotNumeric() 65 | { 66 | $this->fixture->addOrUpdateContactCommunicationItem('not numeric', array()); 67 | } 68 | 69 | /** 70 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::addOrUpdateContactNote 71 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 72 | */ 73 | public function testAddOrUpdateContactNoteThrowsExceptionWhenContactIdIsNotNumeric() 74 | { 75 | $this->fixture->addOrUpdateContactNote('not numeric', array()); 76 | } 77 | 78 | /** 79 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::authenticate 80 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 81 | */ 82 | public function testAuthenticateThrowsException() 83 | { 84 | $this->fixture->authenticate(array()); 85 | } 86 | 87 | /** 88 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::findContacts 89 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 90 | */ 91 | public function testFindContactsThrowsExceptionWhenLimitIsNotNumeric() 92 | { 93 | $this->fixture->findContacts('', 3, '', ''); 94 | } 95 | 96 | /** 97 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::findContacts 98 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 99 | */ 100 | public function testFindContactsThrowsExceptionWhenSkipIsNotNumeric() 101 | { 102 | $this->fixture->findContacts(3, '', '', ''); 103 | } 104 | 105 | /** 106 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::findContacts 107 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 108 | */ 109 | public function testFindContactsThrowsExceptionWhenOrderByIsNotAString() 110 | { 111 | $this->fixture->findContacts(3, 3, 3, ''); 112 | } 113 | 114 | /** 115 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::findContacts 116 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 117 | */ 118 | public function testFindContactsThrowsExceptionWhenConditionsIsNotAString() 119 | { 120 | $this->fixture->findContacts(3, 3, '', 3); 121 | } 122 | 123 | /** 124 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::findContactsCount 125 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 126 | */ 127 | public function testFindContactsCountThrowsExceptionWhenConditionsIsNotAString() 128 | { 129 | $this->fixture->findContactsCount(5); 130 | } 131 | 132 | /** 133 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getAllContactCommunicationItems 134 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 135 | */ 136 | public function testGetAllContactCommunicationItemsThrowsExceptionWhenContactIdIsNotNumeric() 137 | { 138 | $this->fixture->getAllContactCommunicationItems(''); 139 | } 140 | 141 | /** 142 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getAllContactNotes 143 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 144 | */ 145 | public function testGetAllContactNotesThrowsExceptionWhenContactRecIdIsNotNumeric() 146 | { 147 | $this->fixture->getAllContactNotes(''); 148 | } 149 | 150 | 151 | /** 152 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getContact 153 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 154 | */ 155 | public function testGetContactThrowsExceptionWhenIdIsNotNumeric() 156 | { 157 | $this->fixture->getContact(''); 158 | } 159 | 160 | /** 161 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getContactCommunicationItem 162 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 163 | */ 164 | public function testGetContactCommunicationItemThrowsExceptionWhenContactIdIsNotNumeric() 165 | { 166 | $this->fixture->getContactCommunicationItem('', '', ''); 167 | } 168 | 169 | /** 170 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getContactCommunicationItem 171 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 172 | */ 173 | public function testGetContactCommunicationItemThrowsExceptionWhenTypeIsNotAString() 174 | { 175 | $this->fixture->getContactCommunicationItem(3, 3, ''); 176 | } 177 | 178 | /** 179 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getContactCommunicationItem 180 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 181 | */ 182 | public function testGetContactCommunicationItemThrowsExceptoinWhenDescriptionIsNotAString() 183 | { 184 | $this->fixture->getContactCommunicationItem(3, '', 3); 185 | } 186 | 187 | /** 188 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getContactNote 189 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 190 | */ 191 | public function testGetContactNoteThrowsExceptionWhenContactIdIsNotNumeric() 192 | { 193 | $this->fixture->getContactNote('', 3); 194 | } 195 | 196 | /** 197 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getContactNote 198 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 199 | */ 200 | public function testGetContactNoteThrowsExceptionWhenNoteIdIsNotNumeric() 201 | { 202 | $this->fixture->getContactNote(3, ''); 203 | } 204 | 205 | /** 206 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getPortalConfigSettings 207 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 208 | */ 209 | public function testGetPortalConfigSettingsThrowsExceptionWhenPortalNameIsNotAString() 210 | { 211 | $this->fixture->getPortalConfigSettings(3); 212 | } 213 | 214 | /** 215 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getPortalLoginCustomizations 216 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 217 | */ 218 | public function testGetPortalLoginCustomizationsThrowsExceptionWhenPortalNameIsNotAString() 219 | { 220 | $this->fixture->getPortalLoginCustomizations(3); 221 | } 222 | 223 | /** 224 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getPortalSecurity 225 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 226 | */ 227 | public function testGetPortalSecurityThrowsExceptionWhenPortalContIdIsNotNumeric() 228 | { 229 | $this->fixture->getPortalSecurity('', ''); 230 | } 231 | 232 | /** 233 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::getPortalSecurity 234 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 235 | */ 236 | public function testGetPortalSecurityThrowsExceptionWhenPortalCompNameIsNotAString() 237 | { 238 | $this->fixture->getPortalSecurity(3, 3); 239 | } 240 | 241 | 242 | /** 243 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::removeContactFromGroup 244 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 245 | */ 246 | public function testRemoveContactFromGroupThrowsExceptionWhenContactIdIsNotNumeric() 247 | { 248 | $this->fixture->removeContactFromGroup('', 3, ''); 249 | } 250 | 251 | /** 252 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::removeContactFromGroup 253 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 254 | */ 255 | public function testRemoveContactFromGroupThrowsExceptionWhenGroupIdIsNotNumeric() 256 | { 257 | $this->fixture->removeContactFromGroup(3, '', ''); 258 | } 259 | 260 | /** 261 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::removeContactFromGroup 262 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 263 | */ 264 | public function testRemoveContactFromGroupThrowsExceptionWhenNoteIsNotAString() 265 | { 266 | $this->fixture->removeContactFromGroup(3, 3, 3); 267 | } 268 | 269 | /** 270 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::requestPassword 271 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 272 | */ 273 | public function testRequestPasswordThrowsExceptionWhenEmailAddressIsNotAString() 274 | { 275 | $this->fixture->requestPassword(3); 276 | } 277 | 278 | /** 279 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::setDefaultContactCommunicationItem 280 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 281 | */ 282 | public function testSetDefaultContactCommunicationItemThrowsExceptionWhenContactIdIsNotNumeric() 283 | { 284 | $this->fixture->setDefaultContactCommunicationItem('', '', ''); 285 | } 286 | 287 | /** 288 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::setDefaultContactCommunicationItem 289 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 290 | */ 291 | public function testSetDefaultContactCommunicationItemThrowsExceptionWhenCommunicationTypeIsNotAString() 292 | { 293 | $this->fixture->setDefaultContactCommunicationItem(3, 3, ''); 294 | } 295 | 296 | /** 297 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::setDefaultContactCommunicationItem 298 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 299 | */ 300 | public function testSetDefaultContactCommunicationItemThrowsExceptionWhenCommunicationDescriptionIsNotAString() 301 | { 302 | $this->fixture->setDefaultContactCommunicationItem(3, '', 3); 303 | } 304 | 305 | /** 306 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::deleteContact 307 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 308 | */ 309 | public function testDeleteContactThrowsExceptionWhenIdIsNotNumeric() 310 | { 311 | $this->fixture->deleteContact(''); 312 | } 313 | 314 | /** 315 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::deleteContactCommunicationItem 316 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 317 | */ 318 | public function testDeleteContactCommunicationItemThrowsExceptionWhenContactIdIsNotNumeric() 319 | { 320 | $this->fixture->deleteContactCommunicationItem('', '', ''); 321 | } 322 | 323 | /** 324 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::deleteContactCommunicationItem 325 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 326 | */ 327 | public function testDeleteContactCommunicationItemThrowsExceptionWhenTypeIsNotAString() 328 | { 329 | $this->fixture->deleteContactCommunicationItem(3, 3, ''); 330 | } 331 | 332 | /** 333 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::deleteContactCommunicationItem 334 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 335 | */ 336 | public function testDeleteContactCommunicationItemThrowsExceptionWhenDescriptionIsNotAString() 337 | { 338 | $this->fixture->deleteContactCommunicationItem(3, '', 3); 339 | } 340 | 341 | /** 342 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::deleteNote 343 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 344 | */ 345 | public function testDeleteNoteThrowsExceptionWhenNoteIdIsNotNumeric() 346 | { 347 | $this->fixture->deleteNote('', 3); 348 | } 349 | 350 | /** 351 | * @covers LabtechSoftware\ConnectwisePsaSdk\Contact::deleteNote 352 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 353 | */ 354 | public function testDeleteNoteThrowsExceptionWhenContactIdIsNotNumeric() 355 | { 356 | $this->fixture->deleteNote(3, ''); 357 | } 358 | } 359 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/DocumentTest.php: -------------------------------------------------------------------------------- 1 | connectWiseApiMock = $this->getMockBuilder('LabtechSoftware\ConnectwisePsaSdk\ConnectWiseApi') 15 | ->disableOriginalConstructor() 16 | ->getMock(); 17 | 18 | $this->document = new Document($this->connectWiseApiMock); 19 | 20 | } 21 | 22 | protected function tearDown() 23 | { 24 | 25 | // \Mockery::close(); 26 | 27 | } 28 | 29 | /** 30 | * @covers LabtechSoftware\ConnectwisePsaSdk\Document::addDocuments 31 | * @expectedException InvalidArgumentException 32 | * @expectedExceptionMessage objectId must be a numeric value. 33 | */ 34 | public function testAddDocumentsObjectIdNotNumeric() 35 | { 36 | $this->document->addDocuments('string', null, []); 37 | Route::get('', ['as' => '', 'before' => '', 'uses' => '']); 38 | Route::get('test', ['as' => 'test', 'before' => '', 'uses' => '']); 39 | } 40 | 41 | /** 42 | * @covers LabtechSoftware\ConnectwisePsaSdk\Document::addDocuments 43 | * @expectedException InvalidArgumentException 44 | * @expectedExceptionMessage documentTableReference must be a string value. 45 | */ 46 | public function testAddDocumentsDocumentTableReferenceNotString() 47 | { 48 | 49 | $this->document->addDocuments(1, 1, []); 50 | 51 | } 52 | 53 | /** 54 | * @covers LabtechSoftware\ConnectwisePsaSdk\Document::addDocuments 55 | */ 56 | public function testAddDocumentsObjectIdNumericDocumentTableReferenceString() 57 | { 58 | 59 | $objectId = 1; 60 | $documentTableReference = 'string'; 61 | $documentInfo = ['something', 'more']; 62 | 63 | $this->connectWiseApiMock->expects($this->once()) 64 | ->method('makeRequest') 65 | ->with( 66 | 'AddDocuments', 67 | [ 68 | 'objectId' => $objectId, 69 | 'documentTableReference' => $documentTableReference, 70 | 'documentInfo' => $documentInfo 71 | ] 72 | ); 73 | 74 | $this->document->addDocuments( 75 | $objectId, 76 | $documentTableReference, 77 | $documentInfo 78 | ); 79 | 80 | } 81 | 82 | /** 83 | * @covers LabtechSoftware\ConnectwisePsaSdk\Document::getDocument 84 | * @expectedException InvalidArgumentException 85 | * @expectedExceptionMessage Expecting numeric value. 86 | */ 87 | public function testGetDocumentDocumentIdNonNumeric() 88 | { 89 | 90 | $this->document->getDocument('string'); 91 | 92 | } 93 | 94 | /** 95 | * @covers LabtechSoftware\ConnectwisePsaSdk\Document::getDocument 96 | * @expectedException \LabtechSoftware\ConnectwisePsaSdk\ApiException 97 | * @expectedExceptionMessage Expecting value greater than 0. 98 | */ 99 | public function testGetDocumentDocumentIdNotGreaterThanZero() 100 | { 101 | 102 | $this->document->getDocument(0); 103 | 104 | } 105 | 106 | /** 107 | * @covers LabtechSoftware\ConnectwisePsaSdk\Document::getDocument 108 | */ 109 | public function testGetDocumentDocumentIdNumericGreaterThanZero() 110 | { 111 | 112 | $documentId = 1; 113 | 114 | $this->connectWiseApiMock->expects($this->once()) 115 | ->method('makeRequest') 116 | ->with('GetDocument', ['documentId' => $documentId]); 117 | 118 | $this->document->getDocument($documentId); 119 | 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ReportingTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('LabtechSoftware\ConnectwisePsaSdk\ConnectWiseApi') 27 | ->disableOriginalConstructor() 28 | ->getMock(); 29 | 30 | $this->fixture = new Reporting($client); 31 | } 32 | 33 | /** 34 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::getReportFields 35 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 36 | */ 37 | public function testGetReportFieldsThrowsExceptionWhenReportNameIsNotAString() 38 | { 39 | $this->fixture->getReportFields(3); 40 | } 41 | 42 | /** 43 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::getReports 44 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 45 | */ 46 | public function testGetReportsThrowsExceptionWhenIncludeFieldsIsNotBoolean() 47 | { 48 | $this->fixture->getReports(''); 49 | } 50 | 51 | /** 52 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportCount 53 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 54 | */ 55 | public function testRunReportCountThrowsExceptionWhenReportNameIsNotAString() 56 | { 57 | $this->fixture->runReportCount(3, ''); 58 | } 59 | 60 | /** 61 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportCount 62 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 63 | */ 64 | public function testRunReportCountThrowsExceptionWhenConditionsIsNotAString() 65 | { 66 | $this->fixture->runReportCount('', 3); 67 | } 68 | 69 | /** 70 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportQuery 71 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 72 | */ 73 | public function testRunReportQueryThrowsExceptionWhenReportNameIsNotAString() 74 | { 75 | $this->fixture->runReportQuery(3, 3, 3, '', ''); 76 | } 77 | 78 | /** 79 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportQuery 80 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 81 | */ 82 | public function testRunReportQueryThrowsExceptionWhenLimitIsNotNumeric() 83 | { 84 | $this->fixture->runReportQuery('', '', 3, '', ''); 85 | } 86 | 87 | /** 88 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportQuery 89 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 90 | */ 91 | public function testRunReportQueryThrowsExceptionWhenSkipIsNotNumeric() 92 | { 93 | $this->fixture->runReportQuery('', 3, '', '', ''); 94 | } 95 | 96 | /** 97 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportQuery 98 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 99 | */ 100 | public function testRunReportQueryThrowsExceptionWhenConditionsIsNotAString() 101 | { 102 | $this->fixture->runReportQuery('', 3, 3, 3, ''); 103 | } 104 | 105 | /** 106 | * @covers LabtechSoftware\ConnectwisePsaSdk\Reporting::runReportQuery 107 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 108 | */ 109 | public function testRunReportQueryThrowsExceptionWhenOrderByIsNotAString() 110 | { 111 | $this->fixture->runReportQuery('', 3, 3, '', 3); 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/ServiceTicketTest.php: -------------------------------------------------------------------------------- 1 | getMockBuilder('LabtechSoftware\ConnectwisePsaSdk\ConnectWiseApi') 27 | ->disableOriginalConstructor() 28 | ->getMock(); 29 | 30 | $this->fixture = new ServiceTicket($client); 31 | } 32 | 33 | /** 34 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::addOrUpdateServiceTicketViaCompanyId 35 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 36 | */ 37 | public function testAddOrUpdateServiceTicketViaCompanyIdThrowsExceptionWhenCompanyIdIsNotAString() 38 | { 39 | $this->fixture->addOrUpdateServiceTicketViaCompanyId(3, array()); 40 | } 41 | 42 | /** 43 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::addOrUpdateServiceTicketViaManagedId 44 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 45 | */ 46 | public function testAddOrUpdateServiceTicketViaManagedIdThrowsExceptionWhenManagedIdIsNotAString() 47 | { 48 | $this->fixture->addOrUpdateServiceTicketViaManagedId(3, array()); 49 | } 50 | 51 | /** 52 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::findServiceTickets 53 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 54 | */ 55 | public function testFindServiceTicketsThrowsExceptionWhenLimitIsNotNumeric() 56 | { 57 | $this->fixture->findServiceTickets('', 3, '', ''); 58 | } 59 | 60 | /** 61 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::findServiceTickets 62 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 63 | */ 64 | public function testFindServiceTicketsThrowsExceptionWhenSkipIsNotNumeric() 65 | { 66 | $this->fixture->findServiceTickets(3, '', '', ''); 67 | } 68 | 69 | /** 70 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::findServiceTickets 71 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 72 | */ 73 | public function testFindServiceTicketsThrowsExceptionWhenConditionsIsNotAString() 74 | { 75 | $this->fixture->findServiceTickets(3, 3, 3, ''); 76 | } 77 | 78 | /** 79 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::findServiceTickets 80 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 81 | */ 82 | public function testFindServiceTicketsThrowsExceptionWhenOrderByIsNotAString() 83 | { 84 | $this->fixture->findServiceTickets(3, 3, '', 3); 85 | } 86 | 87 | /** 88 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::getServiceStatuses 89 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 90 | */ 91 | public function testGetServiceStatusesThrowsExceptionWhenTicketIdIsNotNumeric() 92 | { 93 | $this->fixture->getServiceStatuses(''); 94 | } 95 | 96 | /** 97 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::getServiceTicket 98 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 99 | */ 100 | public function testGetServiceTicketThrowsExceptionWhenTicketIdIsNotNumeric() 101 | { 102 | $this->fixture->getServiceTicket(''); 103 | } 104 | 105 | /** 106 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::getTicketCount 107 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 108 | */ 109 | public function testGetTicketCountThrowsExceptionWhenConditionsIsNotAString() 110 | { 111 | $this->fixture->getTicketCount(null); 112 | } 113 | 114 | /** 115 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::getTicketProductList 116 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 117 | */ 118 | public function testGetTicketProductListThrowsExceptionWhenTicketNumberIsNotNumeric() 119 | { 120 | $this->fixture->getTicketProductList(''); 121 | } 122 | 123 | /** 124 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 125 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 126 | */ 127 | public function testSearchKnowledgebaseThrowsExceptionWhenTermsIsNotAString() 128 | { 129 | $this->fixture->searchKnowledgebase(3, 'Any', '', 3, 3, 3); 130 | } 131 | 132 | /** 133 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 134 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 135 | */ 136 | public function testSearchKnowledgebaseThrowsExceptionWhenTypeIsNotAString() 137 | { 138 | $this->fixture->searchKnowledgebase('', 3, '', 3, 3, 3); 139 | } 140 | 141 | /** 142 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 143 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 144 | */ 145 | public function testSearchKnowledgebaseThrowsExceptionWhenTypeIsNotAValidValue() 146 | { 147 | $this->fixture->searchKnowledgebase('', 'Not Valid String', '', 3, 3, 3); 148 | } 149 | 150 | /** 151 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 152 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 153 | */ 154 | public function testSearchKnowledgebaseThrowsExceptionWhenStartIsNotAString() 155 | { 156 | $this->fixture->searchKnowledgebase('', 'Any', 3, 3, 3, 3); 157 | } 158 | 159 | /** 160 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 161 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 162 | */ 163 | public function testSearchKnowledgebaseThrowsExceptionWhenCompanyRecIdIsNotNumeric() 164 | { 165 | $this->fixture->searchKnowledgebase('', 'Any', '', '', 3, 3); 166 | } 167 | 168 | /** 169 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 170 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 171 | */ 172 | public function testSearchKnowledgebaseThrowsExceptionWhenLimitIsNotNumeric() 173 | { 174 | $this->fixture->searchKnowledgebase('', 'Any', '', 3, '', 3); 175 | } 176 | 177 | /** 178 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebase 179 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 180 | */ 181 | public function testSearchKnowledgebaseThrowsExceptionWhenSkipIsNotNumeric() 182 | { 183 | $this->fixture->searchKnowledgebase('', 'Any', '', 3, 3, ''); 184 | } 185 | 186 | /** 187 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebaseCount 188 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 189 | */ 190 | public function testSearchKnowledgebaseCountThrowsExceptionWhenTermsIsNotAString() 191 | { 192 | $this->fixture->searchKnowledgebaseCount(3, 'Any', '', 3); 193 | } 194 | 195 | /** 196 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebaseCount 197 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 198 | */ 199 | public function testSearchKnowledgebaseCountThrowsExceptionWhenTypeIsNotAString() 200 | { 201 | $this->fixture->searchKnowledgebaseCount('', 3, '', 3); 202 | } 203 | 204 | /** 205 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebaseCount 206 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 207 | */ 208 | public function testSearchKnowledgebaseCountThrowsExceptionWhenTypeIsNotAValidValue() 209 | { 210 | $this->fixture->searchKnowledgebaseCount('', 'Not A Valid Value', '', 3); 211 | } 212 | 213 | /** 214 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebaseCount 215 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 216 | */ 217 | public function testSearchKnowledgebaseCountThrowsExceptionWhenStartIsNotAString() 218 | { 219 | $this->fixture->searchKnowledgebaseCount('', 'Any', 3, 3); 220 | } 221 | 222 | /** 223 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::searchKnowledgebaseCount 224 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 225 | */ 226 | public function testSearchKnowledgebaseCountThrowsExceptionWhenCompanyRecIdIsNotNumeric() 227 | { 228 | $this->fixture->searchKnowledgebaseCount('', 'Any', '', ''); 229 | } 230 | 231 | /** 232 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::getTicketDocuments 233 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 234 | */ 235 | public function testGetTicketDocumentsThrowsExceptionWhenTicketNumberIsNotNumeric() 236 | { 237 | $this->fixture->getTicketDocuments(''); 238 | } 239 | 240 | /** 241 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::updateTicketNote 242 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 243 | */ 244 | public function testUpdateTicketNoteThrowsExceptionWhenServiceRecIdIsNotNumeric() 245 | { 246 | $this->fixture->updateTicketNote(array(), ''); 247 | } 248 | 249 | /** 250 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::deleteServiceTicket 251 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 252 | */ 253 | public function testDeleteServiceTicketThrowsExceptionWhenTicketIdIsNotNumeric() 254 | { 255 | $this->fixture->deleteServiceTicket(''); 256 | } 257 | 258 | /** 259 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::deleteTicketDocument 260 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 261 | */ 262 | public function testDeleteTicketDocumentThrowsExceptionWhenDocIdIsNotNumeric() 263 | { 264 | $this->fixture->deleteTicketDocument('', 3); 265 | } 266 | 267 | /** 268 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::deleteTicketDocument 269 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 270 | */ 271 | public function testDeleteTicketDocumentThrowsExceptionWhenTicketIdIsNotNumeric() 272 | { 273 | $this->fixture->deleteTicketDocument(3, ''); 274 | } 275 | 276 | /** 277 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::deleteTicketProduct 278 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 279 | */ 280 | public function testDeleteTicketProductThrowsExceptionWhenProductIdIsNotNumeric() 281 | { 282 | $this->fixture->deleteTicketProduct('', 3); 283 | } 284 | 285 | /** 286 | * @covers LabtechSoftware\ConnectwisePsaSdk\ServiceTicket::deleteTicketProduct 287 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 288 | */ 289 | public function testDeleteTicketProductThrowsExceptionWhenTicketIdIsNotNumeric() 290 | { 291 | $this->fixture->deleteTicketProduct(3, ''); 292 | } 293 | } 294 | -------------------------------------------------------------------------------- /tests/ConnectWise/unit/SoapApiRequesterTest.php: -------------------------------------------------------------------------------- 1 | soapMock = $this->getMockBuilder('SoapClient') 15 | ->disableOriginalConstructor() 16 | ->getMock(); 17 | 18 | // build the config loader mock 19 | $configLoaderMock = $this->getMock('LabtechSoftware\ConnectwisePsaSdk\ConfigLoader'); 20 | 21 | // configure the config loader mock 22 | $configLoaderMock->expects($this->once()) 23 | ->method('getSoapCredentials') 24 | ->will($this->returnValue('mock credentials')); 25 | 26 | 27 | // create the SUT, passing in mocks 28 | $this->fixture = new SoapApiRequester($this->soapMock, $configLoaderMock); 29 | } 30 | 31 | 32 | /** 33 | * @expectedException LabtechSoftware\ConnectwisePsaSdk\ApiException 34 | */ 35 | public function testMakeRequestThrowsExceptionWhenSoapFaultOccurs() 36 | { 37 | // configure the soap mock for this test, to throw a soap fault, which will in turn throw an API Exception 38 | $this->soapMock->expects($this->once()) 39 | ->method('__call') 40 | ->with($this->equalTo('amethod')) 41 | ->will($this->throwException(new SoapFault('a soap fault', ''))); 42 | 43 | $this->fixture->makeRequest('amethod'); 44 | } 45 | 46 | 47 | public function testMakeRequestReturnsEmptyArrayWhenNoSoapFault() 48 | { 49 | // configure the soap mock for this test, to return an empty array (opposed to an API Exception when error) 50 | $this->soapMock->expects($this->once()) 51 | ->method('__call') 52 | ->with($this->equalTo('amethod')) 53 | ->will($this->returnValue(array())); 54 | 55 | $this->assertInternalType('array', $this->fixture->makeRequest('amethod')); 56 | } 57 | } 58 | --------------------------------------------------------------------------------