Skip to content

Commit d3aa726

Browse files
committed
Add Tests namespace
1 parent 07b86da commit d3aa726

10 files changed

+67
-39
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@
1616
"pear/file_marc": "^1.1"
1717
},
1818
"require-dev": {
19-
"phpunit/phpunit": "^5.7 | ^6.0",
19+
"phpunit/phpunit": "^5.7 | ^6.0 | ^7.0",
2020
"squizlabs/php_codesniffer": "^3.3"
2121
},
2222
"autoload": {
2323
"psr-4": {
24-
"Scriptotek\\Marc\\": "src/"
24+
"Scriptotek\\Marc\\": "src/",
25+
"Tests\\": "tests/"
2526
}
2627
},
2728
"scripts": {

tests/CollectionTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?php
22

3-
namespace Scriptotek\Marc\Record;
3+
namespace Tests;
44

5-
use PHPUnit\Framework\TestCase;
65
use Scriptotek\Marc\Collection;
76

87
class CollectionTest extends TestCase
@@ -17,15 +16,15 @@ public function testEmptyCollection()
1716

1817
public function testBinaryMarc()
1918
{
20-
$records = Collection::fromFile('tests/data/sandburg.mrc')->toArray();
19+
$records = $this->getTestCollection('sandburg.mrc')->toArray();
2120

2221
$this->assertCount(1, $records);
2322
$this->assertEquals('Arithmetic', $records[0]->title);
2423
}
2524

2625
public function testBibsysOaiPmhSample()
2726
{
28-
$collection = Collection::fromFile('tests/data/oaipmh-bibsys.xml');
27+
$collection = $this->getTestCollection('oaipmh-bibsys.xml');
2928

3029
$this->assertCount(89, $collection->toArray());
3130
}
@@ -37,40 +36,41 @@ public function testAlmaBibsApiExample()
3736
{
3837
// Expect failure because of invalid encoding in XML declaration:
3938
// Document labelled UTF-16 but has UTF-8 content
40-
Collection::fromFile('tests/data/alma-bibs-api-invalid.xml');
39+
40+
$this->getTestCollection('alma-bibs-api-invalid.xml');
4141
}
4242

4343
public function testLocSample()
4444
{
45-
$collection = Collection::fromFile('tests/data/sru-loc.xml');
45+
$collection = $this->getTestCollection('sru-loc.xml');
4646

4747
$this->assertCount(10, $collection->toArray());
4848
}
4949

5050
public function testBibsysSample()
5151
{
52-
$collection = Collection::fromFile('tests/data/sru-bibsys.xml');
52+
$collection = $this->getTestCollection('sru-bibsys.xml');
5353

5454
$this->assertCount(117, $collection->toArray());
5555
}
5656

5757
public function testZdbSample()
5858
{
59-
$collection = Collection::fromFile('tests/data/sru-zdb.xml');
59+
$collection = $this->getTestCollection('sru-zdb.xml');
6060

6161
$this->assertCount(8, $collection->toArray());
6262
}
6363

6464
public function testKthSample()
6565
{
66-
$collection = Collection::fromFile('tests/data/sru-kth.xml');
66+
$collection = $this->getTestCollection('sru-kth.xml');
6767

6868
$this->assertCount(10, $collection->toArray());
6969
}
7070

7171
public function testAlmaSample()
7272
{
73-
$collection = Collection::fromFile('tests/data/sru-alma.xml');
73+
$collection = $this->getTestCollection('sru-alma.xml');
7474

7575
$this->assertCount(3, $collection->toArray());
7676
}

tests/ExamplesTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
namespace Tests;
4+
45
use Scriptotek\Marc\AuthorityRecord;
56
use Scriptotek\Marc\BibliographicRecord;
67
use Scriptotek\Marc\Fields\Subject;
@@ -27,7 +28,7 @@ public function testExample($filename)
2728

2829
public function exampleDataProvider()
2930
{
30-
foreach (glob(__DIR__ . '/data/examples/*.xml') as $filename) {
31+
foreach (glob($this->pathTo('examples/*.xml')) as $filename) {
3132
yield [$filename];
3233
}
3334
}

tests/FieldsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
namespace Tests;
4+
45
use Scriptotek\Marc\Record;
56

67
class IsbnFieldTest extends TestCase

tests/PersonFieldTest.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
4-
use Scriptotek\Marc\Collection;
5-
use Scriptotek\Marc\Fields\Person;
3+
namespace Tests;
64

75
class PersonFieldTest extends TestCase
86
{
9-
protected function getNthrecord($filename, $n)
10-
{
11-
$records = Collection::fromFile('tests/data/' . $filename)->toArray();
12-
13-
return $records[$n - 1];
14-
}
15-
167
public function testSimple()
178
{
189
$record = $this->getNthrecord('sru-alma.xml', 1);

tests/QueryResultTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
namespace Tests;
4+
45
use Scriptotek\Marc\Fields\Field;
56
use Scriptotek\Marc\Record;
67
use Scriptotek\Marc\QueryResult;

tests/RecordTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
namespace Tests;
4+
45
use Scriptotek\Marc\AuthorityRecord;
56
use Scriptotek\Marc\BibliographicRecord;
67
use Scriptotek\Marc\Fields\Field;
@@ -67,13 +68,13 @@ public function testExampleWithCustomPrefix()
6768

6869
public function testBinaryMarc()
6970
{
70-
$record = Record::fromFile(__DIR__ . '/data/binary-marc.mrc');
71+
$record = Record::fromFile($this->pathTo('binary-marc.mrc'));
7172
$this->assertInstanceOf(Record::class, $record);
7273
}
7374

7475
public function testThatFieldObjectsAreReturned()
7576
{
76-
$record = Record::fromFile(__DIR__ . '/data/binary-marc.mrc');
77+
$record = Record::fromFile($this->pathTo('binary-marc.mrc'));
7778
$this->assertInstanceOf(Field::class, $record->getField('020'));
7879
$this->assertInstanceOf(Field::class, $record->getFields('020')[0]);
7980
}

tests/SubjectFieldTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
4-
use Scriptotek\Marc\Collection;
3+
namespace Tests;
4+
55
use Scriptotek\Marc\Fields\Subject;
66
use Scriptotek\Marc\Fields\UncontrolledSubject;
77

88
class SubjectFieldTest extends TestCase
99
{
10-
protected function getNthrecord($filename, $n)
11-
{
12-
$records = Collection::fromFile('tests/data/' . $filename)->toArray();
13-
14-
return $records[$n - 1];
15-
}
16-
1710
public function testSubjectString()
1811
{
1912
$record = $this->getNthrecord('sru-alma.xml', 1);

tests/TestCase.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Scriptotek\Marc\Collection;
6+
use Scriptotek\Marc\Record;
7+
8+
class TestCase extends \PHPUnit\Framework\TestCase
9+
{
10+
protected function pathTo($filename)
11+
{
12+
return __DIR__ . '/data/' . $filename;
13+
}
14+
15+
protected function getTestCollection($filename)
16+
{
17+
return Collection::fromFile($this->pathTo($filename));
18+
}
19+
20+
protected function getNthrecord($filename, $n)
21+
{
22+
$records = $this->getTestCollection($filename)->toArray();
23+
24+
return $records[$n - 1];
25+
}
26+
27+
protected function makeMinimalRecord($value)
28+
{
29+
return Record::fromString('<?xml version="1.0" encoding="UTF-8" ?>
30+
<record>
31+
<leader>99999cam a2299999 u 4500</leader>
32+
<controlfield tag="001">98218834x</controlfield>
33+
' . $value . '
34+
</record>');
35+
}
36+
}

tests/TitleFieldTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
use PHPUnit\Framework\TestCase;
3+
namespace Tests;
4+
5+
use File_MARC_Data_Field;
6+
use File_MARC_Subfield;
47
use Scriptotek\Marc\Fields\Title;
58

69
class TitleFieldTest extends TestCase

0 commit comments

Comments
 (0)