Skip to content

Commit

Permalink
Fixed tests and linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thelfensdrfer committed Nov 26, 2018
1 parent d90137a commit 1ec48ed
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"license": "MIT",
"require": {
"php": ">=7",
"ext-json": "*",
"voku/httpful": "0.4.*"
},
"require-dev": {
Expand Down
16 changes: 11 additions & 5 deletions src/Matomo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace VisualAppeal;

use Httpful\Exception\ConnectionErrorException;
use Httpful\Request;

/**
Expand Down Expand Up @@ -373,7 +374,7 @@ public function reset()
* @param string $method
* @param array $params
* @param array $optional
* @return bool|object
* @return bool|object|array
*/
private function _request($method, $params = [], $optional = [])
{
Expand All @@ -387,7 +388,12 @@ private function _request($method, $params = [], $optional = [])
$req->max_redirects = $this->maxRedirects;
$req->setConnectionTimeout(5);

$buffer = $req->send();
try {
$buffer = $req->send();
} catch (ConnectionErrorException $e) {
$this->_addError(sprintf('Could not send buffer: %s', $e->getMessage()));
return false;
}

if (!empty($buffer)) {
$request = $this->_parseRequest($buffer);
Expand Down Expand Up @@ -1545,7 +1551,7 @@ public function getAvailableExtractionDimensions()
*
* @param string $segment
* @param array $optional
* @return bool|object
* @return array
*/
public function getCustomVariables($segment = '', $optional = [])
{
Expand Down Expand Up @@ -2567,7 +2573,7 @@ public function getUsersById( $segment = '', $optional = []){
'segment' => $segment,
], $optional);
}

/**
* MODULE: MOBILEMESSAGING
* The MobileMessaging API lets you manage and access all the MobileMessaging plugin features
Expand Down Expand Up @@ -4297,7 +4303,7 @@ public function getCountry($segment = '', $optional = [])
*
* @return object
*/
public function getCountryCodeMapping($segment = '', $optional = [])
public function getCountryCodeMapping()
{
return $this->_request('UserCountry.getCountryCodeMapping');
}
Expand Down
10 changes: 5 additions & 5 deletions tests/MatomoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class MatomoTest extends \PHPUnit\Framework\TestCase
{
const TEST_SITE_URL = 'https://demo.matomo.org/';

const TEST_SITE_ID = 7;
const TEST_SITE_ID = 62;

const TEST_TOKEN = 'anonymous';

Expand Down Expand Up @@ -191,26 +191,26 @@ public function testMultipleErrors()
*/
public function testOptionalParameters()
{
$this->_matomo->setDate('2011-01-11');
$this->_matomo->setDate('2018-10-01');
$this->_matomo->setPeriod(Matomo::PERIOD_WEEK);
$result = $this->_matomo->getWebsites('', [
'flat' => 1,
]);

$this->assertInternalType('array', $result);
$this->assertEquals('', implode(',', $this->_matomo->getErrors()));
$this->assertEquals(388, $result[0]->nb_visits);
$this->assertEquals(934, $result[0]->nb_visits);
}

/**
* Test if the response contains custom variables
*/
public function testCustomVariables()
{
$this->_matomo->setDate('2011-11-08');
$this->_matomo->setDate('2018-10-01');
$this->_matomo->setPeriod(Matomo::PERIOD_WEEK);
$result = $this->_matomo->getCustomVariables();

$this->assertEquals(1, count($result));
$this->assertEquals(15, count($result));
}
}

0 comments on commit 1ec48ed

Please sign in to comment.