Skip to content

Commit 6c8f71b

Browse files
committed
Don't throw exception on empty set
1 parent db4aea8 commit 6c8f71b

File tree

5 files changed

+19
-7
lines changed

5 files changed

+19
-7
lines changed

src/Collection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,8 @@ public function parse($source, $isXml, $ns = '', $isPrefix = true)
5656
public function __get($key = '')
5757
{
5858
if ($key == 'records') {
59-
// re-instantiaces..
6059
if (is_null($this->parser)) {
61-
return array();
60+
$this->_records = new Records();
6261
}
6362
if (is_null($this->_records)) {
6463
$this->_records = new Records($this->parser);

src/Importers/XmlImporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getCollection()
6363
{
6464
$records = $this->getRecords();
6565
if (!count($records)) {
66-
throw new \ErrorException("Uh oh, didn't find any records");
66+
return $this->collection;
6767
}
6868

6969
list($prefix, $ns) = $this->getMarcNamespace($records[0]->getNamespaces(true));

src/Records.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Records implements \Iterator //, \Countable
88
protected $records;
99
protected $useCache = false;
1010

11-
public function __construct($parser)
11+
public function __construct($parser = null)
1212
{
1313
$this->parser = $parser;
1414
$this->_current = null;
@@ -27,7 +27,7 @@ public function toArray()
2727
}
2828

2929
/*********************************************************
30-
* Iterator + Countable
30+
* Iterator
3131
*********************************************************/
3232

3333
protected $position = 0;
@@ -49,7 +49,7 @@ public function next()
4949
if ($this->useCache) {
5050
$rec = isset($this->records[$this->position]) ? $this->records[$this->position] : false;
5151
} else {
52-
$rec = $this->parser->next();
52+
$rec = $this->parser ? $this->parser->next() : null;
5353
if ($rec) {
5454
$rec = new Record($rec);
5555
$this->records[] = $rec;

tests/SruResponseTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use Scriptotek\Marc\Importers\XmlImporter;
44

5-
class XmlImporterTest extends \PHPUnit_Framework_TestCase
5+
class SruResponseImporterTest extends \PHPUnit_Framework_TestCase
66
{
77
public function testLocSample()
88
{

tests/XmlImporterTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
use Scriptotek\Marc\Importers\XmlImporter;
4+
5+
class XmlImporterTest extends \PHPUnit_Framework_TestCase
6+
{
7+
public function testEmptySet()
8+
{
9+
$response = new XmlImporter('<records></records>');
10+
11+
$this->assertCount(0, $response->getCollection()->records);
12+
}
13+
}

0 commit comments

Comments
 (0)