Skip to content

Commit 52ebd17

Browse files
committed
Add test on thrown Exception if the API returns an error
1 parent 5412884 commit 52ebd17

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Knp/PiwikClient/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Client
3232
public function __construct(ConnectionInterface $connection, $token = 'anonymous')
3333
{
3434
$this->connection = $connection;
35-
$this->token = $token;
35+
$this->setToken($token);
3636
}
3737

3838
/**

tests/Knp/PiwikClient/ClientTest.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function testConnection()
2626
}
2727

2828

29-
/* TEST CALL FORMAT JSON
29+
/* TEST CALL
3030
*************************************************************************/
3131
/**
3232
* @dataProvider providerCall
@@ -63,6 +63,23 @@ public function providerCall()
6363
}
6464

6565

66+
/* TEST CALL EXCEPTION
67+
*************************************************************************/
68+
public function testCallException()
69+
{
70+
$connection = $this->getConnectionMock();
71+
$client = new Client($connection, '123');
72+
73+
$connection
74+
->expects($this->once())
75+
->method('send')
76+
->will($this->returnValue(serialize(array('result'=>'error', 'message'=>'test'))));
77+
78+
$this->setExpectedException('Knp\PiwikClient\Exception\Exception');
79+
$client->call('API.getReportMetadata');
80+
}
81+
82+
6683
/* UTILS
6784
*************************************************************************/
6885
protected function getConnectionMock()

0 commit comments

Comments
 (0)