Skip to content

Commit bceec14

Browse files
committed
Default ContextActivities properties to arrays
* The check to make sure the properties were set was not happening soon enough so that the set methods through the _listSetter were trying to push to arrays that were not defined yet * Improve tests for fromJSON instantiation in ContextActivities
1 parent a445f95 commit bceec14

File tree

2 files changed

+26
-25
lines changed

2 files changed

+26
-25
lines changed

src/ContextActivities.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ class ContextActivities implements VersionableInterface
2121
{
2222
use ArraySetterTrait, FromJSONTrait;
2323

24-
protected $category;
25-
protected $parent;
26-
protected $grouping;
27-
protected $other;
24+
protected $category = array();
25+
protected $parent = array();
26+
protected $grouping = array();
27+
protected $other = array();
2828

2929
private static $directProps = array(
3030
'category',
@@ -39,21 +39,6 @@ public function __construct() {
3939

4040
$this->_fromArray($arg);
4141
}
42-
43-
foreach (
44-
[
45-
'category',
46-
'parent',
47-
'grouping',
48-
'other',
49-
] as $k
50-
) {
51-
$method = 'set' . ucfirst($k);
52-
53-
if (! isset($this->$k)) {
54-
$this->$method(array());
55-
}
56-
}
5742
}
5843

5944
public function asVersion($version) {

tests/ContextActivitiesTest.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,31 @@ public function testInstantiation() {
3131
}
3232
}
3333

34-
/*
35-
// TODO: need to loop possible configs
3634
public function testFromJSONInstantiations() {
37-
$obj = ContextActivities::fromJSON('{"mbox":"' . COMMON_GROUP_MBOX . '", "member":[{"mbox":"' . COMMON_MBOX . '"}]}');
35+
$common_activity = new TinCan\Activity(self::$common_activity_cfg);
36+
37+
$all_json = array();
38+
foreach (self::$listProps as $k) {
39+
$getMethod = 'get' . ucfirst($k);
40+
41+
$prop_json = '"' . $k . '":[' . json_encode($common_activity->asVersion('1.0.0')) . ']';
42+
43+
array_push($all_json, $prop_json);
44+
45+
$obj = ContextActivities::fromJSON('{' . $prop_json . '}');
46+
47+
$this->assertInstanceOf('TinCan\ContextActivities', $obj);
48+
$this->assertEquals([$common_activity], $obj->$getMethod(), "$k list");
49+
}
50+
51+
$obj = ContextActivities::fromJSON('{' . join(",", $all_json) . "}");
52+
3853
$this->assertInstanceOf('TinCan\ContextActivities', $obj);
39-
$this->assertSame(COMMON_GROUP_MBOX, $obj->getMbox(), 'mbox value');
40-
$this->assertEquals([['mbox' => COMMON_MBOX]], $obj->getMember(), 'member list');
54+
$this->assertEquals([$common_activity], $obj->getCategory(), "all props: category list");
55+
$this->assertEquals([$common_activity], $obj->getParent(), "all props: parent list");
56+
$this->assertEquals([$common_activity], $obj->getGrouping(), "all props: grouping list");
57+
$this->assertEquals([$common_activity], $obj->getOther(), "all props: other list");
4158
}
42-
*/
4359

4460
// TODO: need to loop versions
4561
public function testAsVersion() {

0 commit comments

Comments
 (0)