Skip to content

Commit 37cdd68

Browse files
committed
fix callbacks, add tests
1 parent ce575ad commit 37cdd68

File tree

4 files changed

+51
-9
lines changed

4 files changed

+51
-9
lines changed

src/Responses/FailureResponse.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ class FailureResponse extends MailchimpResponse
1818
* @param $body
1919
* @param $http_code
2020
* @param callable|null $failure_callback
21-
* @throws MailchimpException
2221
*/
2322
public function __construct($headers, $body, $http_code, callable $failure_callback = null)
2423
{
2524
parent::__construct($headers, $body, $http_code);
26-
if ($failure_callback && is_callable($failure_callback)) {
25+
26+
if ($failure_callback) {
2727
call_user_func($failure_callback);
28-
} elseif ($failure_callback && !is_callable($failure_callback)) {
29-
throw new MailchimpException("The failure callback is not callable");
3028
}
3129
}
3230
}

src/Responses/SuccessResponse.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ class SuccessResponse extends MailchimpResponse
1818
* @param $body
1919
* @param $http_code
2020
* @param callable|null $success_callback
21-
* @throws MailchimpException
2221
*/
2322
public function __construct($headers, $body, $http_code, callable $success_callback = null)
2423
{
2524
parent::__construct($headers, $body, $http_code);
26-
if (is_callable($success_callback)) {
27-
call_user_func("foo");
28-
} elseif ($success_callback && !is_callable($success_callback)) {
29-
throw new MailchimpException("The success callback is not callable");
25+
26+
if ($success_callback) {
27+
call_user_func($success_callback);
3028
}
3129
}
3230
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
4+
namespace MailchimpTests\Responses;
5+
6+
7+
use MailchimpAPI\Responses\FailureResponse;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class FailureResponseTest extends TestCase
11+
{
12+
public function testFailureCallback()
13+
{
14+
$called = false;
15+
16+
$callback = function () use (&$called) {
17+
$called = true;
18+
};
19+
20+
(new FailureResponse([], '', 200, $callback));
21+
$this->assertTrue($called == true, 'The callback should be called by FailureResponse');
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
4+
namespace MailchimpTests\Responses;
5+
6+
7+
use MailchimpAPI\Responses\SuccessResponse;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class SuccessResponseTest extends TestCase
11+
{
12+
public function testSuccessCallback()
13+
{
14+
$called = false;
15+
16+
$callback = function () use (&$called) {
17+
$called = true;
18+
};
19+
20+
(new SuccessResponse([], '', 200, $callback));
21+
$this->assertTrue($called == true, 'The callback should be called by SuccessResponse');
22+
}
23+
}

0 commit comments

Comments
 (0)