Skip to content

Commit

Permalink
Fix feedbcack service bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhukV committed Nov 11, 2015
1 parent 9982587 commit d03a4d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions src/Feedback/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Apple\ApnPush\Feedback;

use Apple\ApnPush\Certificate\Certificate;
use Apple\ApnPush\Connection\ConnectionInterface;
use Apple\ApnPush\Exception;
use Psr\Log\LoggerInterface;
Expand All @@ -35,7 +36,7 @@ class Feedback implements FeedbackInterface
/**
* Construct
*
* @param Connection $connection
* @param ConnectionInterface|string $connection
*/
public function __construct($connection = null)
{
Expand All @@ -44,7 +45,8 @@ public function __construct($connection = null)
$this->connection = $connection;
} elseif (is_string($connection)) {
// Connection is a certificate path file
$this->connection = new Connection($connection);
$certificate = new Certificate($connection, null);
$this->connection = new Connection($certificate);
}
}
}
Expand All @@ -58,6 +60,11 @@ public function __construct($connection = null)
*/
public function setConnection(ConnectionInterface $connection)
{
if ($this->connection) {
// Close old connection
$this->connection->close();
}

$this->connection = $connection;

return $this;
Expand Down
4 changes: 2 additions & 2 deletions tests/Feedback/FeedbackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function setUp()
{
$this->connection = $this->getMock(
'Apple\ApnPush\Feedback\Connection',
array('is', 'write', 'isReadyRead', 'create', 'close', 'read'),
array('is', 'write', 'isReadyRead', 'connect', 'close', 'read'),
array(),
'',
false
Expand All @@ -53,7 +53,7 @@ public function testService()
$this->connection->expects($this->any())->method('is')
->will($this->returnValue(false));

$this->connection->expects($this->once())->method('create');
$this->connection->expects($this->once())->method('connect');

$this->connection->expects($this->never())->method('write');

Expand Down

0 comments on commit d03a4d4

Please sign in to comment.