From d03a4d44e058fc7b308f5a317df78ae7e199f9a9 Mon Sep 17 00:00:00 2001 From: Vitaliy Zhuk Date: Wed, 11 Nov 2015 13:38:38 +0200 Subject: [PATCH] Fix feedbcack service bugs --- src/Feedback/Feedback.php | 11 +++++++++-- tests/Feedback/FeedbackTest.php | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Feedback/Feedback.php b/src/Feedback/Feedback.php index 6ef77e2..805da89 100644 --- a/src/Feedback/Feedback.php +++ b/src/Feedback/Feedback.php @@ -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; @@ -35,7 +36,7 @@ class Feedback implements FeedbackInterface /** * Construct * - * @param Connection $connection + * @param ConnectionInterface|string $connection */ public function __construct($connection = null) { @@ -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); } } } @@ -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; diff --git a/tests/Feedback/FeedbackTest.php b/tests/Feedback/FeedbackTest.php index 90147bc..588a3f5 100644 --- a/tests/Feedback/FeedbackTest.php +++ b/tests/Feedback/FeedbackTest.php @@ -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 @@ -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');