Skip to content

Commit 62e0084

Browse files
committed
Cleanup & tests
1 parent ceebec6 commit 62e0084

File tree

9 files changed

+40
-23
lines changed

9 files changed

+40
-23
lines changed

phpunit.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
<testsuites>
33
<testsuite name="TestSuite">
44
<directory>tests/</directory>
5-
</testsuite>
6-
</testsuites>
7-
</phpunit>
5+
</testsuite>
6+
</testsuites>
7+
<filter>
8+
<whitelist processUncoveredFilesFromWhitelist="true">
9+
<directory suffix=".php">src/</directory>
10+
</whitelist>
11+
</filter>
12+
</phpunit>

src/Exceptions/XmlException.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
class XmlException extends \RuntimeException
66
{
7-
public function __construct($errors)
8-
{
9-
$details = array_map(function($error) {
10-
return $error->message;
11-
}, $errors);
12-
parent::__construct('Failed loading XML: \n' . implode('\n', $details));
13-
}
14-
}
7+
public function __construct($errors)
8+
{
9+
$details = array_map(function ($error) {
10+
return $error->message;
11+
}, $errors);
12+
parent::__construct('Failed loading XML: \n' . implode('\n', $details));
13+
}
14+
}

src/Fields/Field.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,5 @@ public function __get($key)
2222
if (method_exists($this, $method)) {
2323
return call_user_func(array($this, $method));
2424
}
25-
// TODO: Throw something!
2625
}
2726
}

src/Fields/Isbn.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ public function __toString()
88
{
99
$a = $this->field->getSubfield('a');
1010
if (!$a) {
11-
return;
11+
return '';
1212
}
1313

14-
// TODO: Other subfields?
1514
return $a->getData();
1615
}
1716
}

src/Fields/Subject.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,14 @@ public function getVocabulary()
3434
/**
3535
* Return the Authority record control number
3636
*/
37-
public function getControlNumber($value='')
37+
public function getControlNumber()
3838
{
39-
return $this->field->getSubfield('0');
39+
$value = $this->field->getSubfield('0');
40+
return $value ?: null;
4041
}
4142

42-
function getParts() {
43+
public function getParts()
44+
{
4345
$parts = array();
4446
foreach ($this->field->getSubfields() as $c) {
4547
if (in_array($c->getCode(), array('a', 'b', 'x', 'y', 'z'))) {

src/Fields/Title.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ public function __toString()
1515
{
1616
// $a is not repeated
1717
$a = $this->field->getSubfield('a');
18-
if (!$a) {
19-
return;
20-
}
21-
$title = trim($a->getData());
18+
$title = $a ? trim($a->getData()) : '';
2219

2320
// $b is not repeated
2421
$b = $this->field->getSubfield('b');

src/Record.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,10 @@ public function __get($key)
154154
if (method_exists($this, $method)) {
155155
return call_user_func(array($this, $method));
156156
}
157-
// TODO: Throw something!
158157
}
159158

160159
public function __toString()
161160
{
162161
return strval($this->record);
163162
}
164-
165163
}

tests/IsbnFieldTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,20 @@ public function testIsbn()
2020
$record = Record::fromString($source);
2121
$this->assertEquals(array('8200424421'), $record->isbns);
2222
}
23+
24+
public function test020withoutA()
25+
{
26+
$source = '<?xml version="1.0" encoding="UTF-8" ?>
27+
<record xmlns="http://www.loc.gov/MARC21/slim">
28+
<leader>99999cam a2299999 u 4500</leader>
29+
<controlfield tag="001">98218834x</controlfield>
30+
<datafield tag="020" ind1=" " ind2=" ">
31+
<subfield code="q">h.</subfield>
32+
<subfield code="c">Nkr 98.00</subfield>
33+
</datafield>
34+
</record>';
35+
36+
$record = Record::fromString($source);
37+
$this->assertEquals(array(''), $record->isbns);
38+
}
2339
}

tests/SubjectFieldTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public function testSubjects()
3838
$this->assertEquals('noubomn', $subject->vocabulary);
3939
$this->assertEquals('Elementærpartikler', strval($subject));
4040
$this->assertEquals('650', $subject->getTag('650'));
41+
$this->assertNull($subject->getControlNumber());
4142

4243
$subject = $record->subjects[3];
4344
$this->assertInstanceOf('Scriptotek\Marc\Fields\Subject', $subject);

0 commit comments

Comments
 (0)