Skip to content

Commit

Permalink
Add tests and spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
nichtich committed Aug 29, 2017
1 parent 8475f2e commit 0f017d4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 21 deletions.
16 changes: 8 additions & 8 deletions src/Concept.php
Expand Up @@ -16,14 +16,14 @@ class Concept extends Item
];

const FIELDS = [
'narrower' => ['Set','Concept'],
'broader' => ['Set','Concept'],
'related' => ['Set','Concept'],
'previous' => ['Set','Concept'],
'next' => ['Set','Concept'],
'ancestors' => ['Set','Concept'],
'inScheme' => ['Set','ConceptScheme'],
'topConceptOf' => ['Set','ConceptScheme'],
'narrower' => ['Set', 'Concept'],
'broader' => ['Set', 'Concept'],
'related' => ['Set', 'Concept'],
'previous' => ['Set', 'Concept'],
'next' => ['Set', 'Concept'],
'ancestors' => ['Set', 'Concept'],
'inScheme' => ['Set', 'ConceptScheme'],
'topConceptOf' => ['Set', 'ConceptScheme'],
];

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Container.php
Expand Up @@ -169,7 +169,7 @@ public function getIterator()

public function jsonLDSerialize(string $context = self::DEFAULT_CONTEXT, bool $types = null)
{
$set = array_map(function ($m) use ($types) {
$set = array_map(function($m) use ($types) {
return is_object($m) ? $m->jsonLDSerialize('', $types) : $m;
}, $this->members);

Expand Down
14 changes: 6 additions & 8 deletions src/DataType.php
Expand Up @@ -48,7 +48,7 @@ protected static function fieldType(string $field, bool $strict = false)
}
}

private function fieldException($field, $message)
private function fieldException(string $field, string $message)
{
return new InvalidArgumentException(
get_called_class() . "->$field must $message"
Expand All @@ -74,7 +74,7 @@ protected function setField(string $field, $value, bool $strict = true)
if (is_array($value)) {
$class = 'JSKOS\\' . $type[1];
$value = new Set(
array_map(function ($m) use ($class) {
array_map(function($m) use ($class) {
if (is_null($m)) {
return null;
}
Expand All @@ -99,8 +99,6 @@ protected function setField(string $field, $value, bool $strict = true)
}
# TODO: check member types
}
} elseif ($type == '*') {
$value = $value;
} elseif ($type == 'LanguageMapOfStrings') {
if (!($value instanceof LanguageMapOfStrings)) {
$value = new LanguageMapOfStrings($value);
Expand All @@ -109,12 +107,12 @@ protected function setField(string $field, $value, bool $strict = true)
if (!($value instanceof LanguageMapOfLists)) {
$value = new LanguageMapOfLists($value);
}
} elseif (!DataType::hasType($value, $type)) {
if ($type == 'ConceptScheme') {
} elseif ($type == 'ConceptScheme') {
if (!($value instanceof ConceptScheme)) {
$value = new ConceptScheme($value);
} else {
throw $this->fieldException($field, "match JSKOS\DataType::is$type");
}
} elseif ($type != '*' && !DataType::hasType($value, $type)) {
throw $this->fieldException($field, "match JSKOS\DataType::is$type");
}

$this->$field = $value;
Expand Down
8 changes: 4 additions & 4 deletions src/Resource.php
Expand Up @@ -26,10 +26,10 @@ abstract class Resource extends DataType
'created' => 'Date',
'issued' => 'Date',
'modified' => 'Date',
'creator' => ['Set','Concept'],
'contributor' => ['Set','Concept'],
'publisher' => ['Set','Concept'],
'partOf' => ['Set','Concept'],
'creator' => ['Set', 'Concept'],
'contributor' => ['Set', 'Concept'],
'publisher' => ['Set', 'Concept'],
'partOf' => ['Set', 'Concept'],
];

/**
Expand Down
3 changes: 3 additions & 0 deletions tests/LanguageMapOfStringsTest.php
Expand Up @@ -19,6 +19,9 @@ public function testConstruct()

$nonstrict = new LanguageMapOfStrings([0=>[], 'en'=>'hi']);
$this->assertEquals($map, $nonstrict);

$map['en'] = null;
$this->assertEquals(new LanguageMapOfStrings(), $map);
}

public function testJson()
Expand Down
1 change: 1 addition & 0 deletions tests/SetTest.php
Expand Up @@ -7,6 +7,7 @@

/**
* @covers JSKOS\Set
* @covers JSKOS\Container
*/
class SetTest extends \PHPUnit\Framework\TestCase
{
Expand Down

0 comments on commit 0f017d4

Please sign in to comment.