From 4317e5bb1f1061974bf6d4fa0e374930269adee9 Mon Sep 17 00:00:00 2001
From: Alex Arnaud <alex.arnaud@biblibre.com>
Date: Thu, 9 Jul 2015 16:32:42 +0200
Subject: [PATCH] dev #24821 - Fix an error when users have no doc waiting to
 be pulled

---
 library/Class/WebService/SIGB/Emprunteur.php  |  1 +
 .../Class/WebService/SIGB/KohaTest.php        | 29 +++++++++++++------
 2 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/library/Class/WebService/SIGB/Emprunteur.php b/library/Class/WebService/SIGB/Emprunteur.php
index 127ffd36d73..7eefe78eacc 100644
--- a/library/Class/WebService/SIGB/Emprunteur.php
+++ b/library/Class/WebService/SIGB/Emprunteur.php
@@ -344,6 +344,7 @@ class Class_WebService_SIGB_Emprunteur {
 
 	public function getHoldsWaitingToBePulled() {
 		if (null === $this->_waiting_holds) {
+			$this->_waiting_holds = [];
 			foreach ($this->getReservations() as $hold) {
 				if ($hold->isWaitingToBePulled())
 					$this->_waiting_holds[] = $hold;
diff --git a/tests/library/Class/WebService/SIGB/KohaTest.php b/tests/library/Class/WebService/SIGB/KohaTest.php
index 6191f6347fe..4510c0c4b8c 100644
--- a/tests/library/Class/WebService/SIGB/KohaTest.php
+++ b/tests/library/Class/WebService/SIGB/KohaTest.php
@@ -352,53 +352,64 @@ class KohaGetEmprunteurLaureAfondTest extends KohaTestCase {
 			->getEmprunteur(Class_Users::newInstance()
 											->setLogin('lafond')
 											->setPassword('afi')
-											->setIdabon('012345')
-		);
+											->setIdabon('012345'));
+
+		$this->pierre = $this->service
+			->getEmprunteur(Class_Users::newInstance()
+											->setLogin('pierre')
+											->setPassword('toto')
+											->setIdabon('9865'));
 	}
 
 
 	/** @test */
-	function getIdShouldReturn572() {
+	public function getIdShouldReturn572() {
 		$this->assertEquals(572, $this->laurent->getId());
 	}
 
 
 	/** @test */
-	function getHoldsWaitingToBePulledShouldReturn2Holds() {
+	public function getHoldsWaitingToBePulledForPierreShouldReturn0Holds() {
+		$this->assertCount(0, $this->pierre->getHoldsWaitingToBePulled());
+	}
+
+
+	/** @test */
+	public function getHoldsWaitingToBePulledForLaurentShouldReturn2Holds() {
 		$this->assertCount(2, $this->laurent->getHoldsWaitingToBePulled());
 	}
 
 
 	/** @test */
-	function firstHoldWaitingToBePulledTitleShouldBeHarryPotterEtLaCoupeDeFeu() {
+	public function firstHoldWaitingToBePulledTitleShouldBeHarryPotterEtLaCoupeDeFeu() {
 		$waiting_holds = $this->laurent->getHoldsWaitingToBePulled();
 		$this->assertEquals('Harry Potter et le prisonnier d\'Azkaban', $waiting_holds[0]->getTitre());
 	}
 
 
 	/** @test */
-	function firstHoldWaitingToBePulledPickUpLocationShouldBeMontmedy() {
+	public function firstHoldWaitingToBePulledPickUpLocationShouldBeMontmedy() {
 		$waiting_holds = $this->laurent->getHoldsWaitingToBePulled();
 		$this->assertEquals('Médiathèque publique', $waiting_holds[0]->getPickupLocationLabel());
 	}
 
 
 	/** @test */
-	function secondHoldWaitingToBePulledTitleShouldBeHarryPotterEtLePrisonnierDAzkaban() {
+	public function secondHoldWaitingToBePulledTitleShouldBeHarryPotterEtLePrisonnierDAzkaban() {
 		$waiting_holds = $this->laurent->getHoldsWaitingToBePulled();
 		$this->assertEquals('Harry Potter et l\'ordre du Phénix', $waiting_holds[1]->getTitre());
 	}
 
 
 	/** @test */
-	function secondHoldWaitingToBePulledPickUpLocationShouldBeMediathequePublique() {
+	public function secondHoldWaitingToBePulledPickUpLocationShouldBeMediathequePublique() {
 		$waiting_holds = $this->laurent->getHoldsWaitingToBePulled();
 		$this->assertEquals('Montmedy', $waiting_holds[1]->getPickupLocationLabel());
 	}
 
 
 	/** @test */
-	function nbReservationsShouldReturnThree() {
+	public function nbReservationsShouldReturnThree() {
 		$this->assertEquals(4, $this->laurent->getNbReservations());
 	}
 
-- 
GitLab