Skip to content

Commit

Permalink
Default ContextActivities properties to arrays
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
brianjmiller committed Jul 22, 2014
1 parent a445f95 commit bceec14
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
23 changes: 4 additions & 19 deletions src/ContextActivities.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ class ContextActivities implements VersionableInterface
{
use ArraySetterTrait, FromJSONTrait;

protected $category;
protected $parent;
protected $grouping;
protected $other;
protected $category = array();
protected $parent = array();
protected $grouping = array();
protected $other = array();

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

$this->_fromArray($arg);
}

foreach (
[
'category',
'parent',
'grouping',
'other',
] as $k
) {
$method = 'set' . ucfirst($k);

if (! isset($this->$k)) {
$this->$method(array());
}
}
}

public function asVersion($version) {
Expand Down
28 changes: 22 additions & 6 deletions tests/ContextActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,31 @@ public function testInstantiation() {
}
}

/*
// TODO: need to loop possible configs
public function testFromJSONInstantiations() {
$obj = ContextActivities::fromJSON('{"mbox":"' . COMMON_GROUP_MBOX . '", "member":[{"mbox":"' . COMMON_MBOX . '"}]}');
$common_activity = new TinCan\Activity(self::$common_activity_cfg);

$all_json = array();
foreach (self::$listProps as $k) {
$getMethod = 'get' . ucfirst($k);

$prop_json = '"' . $k . '":[' . json_encode($common_activity->asVersion('1.0.0')) . ']';

array_push($all_json, $prop_json);

$obj = ContextActivities::fromJSON('{' . $prop_json . '}');

$this->assertInstanceOf('TinCan\ContextActivities', $obj);
$this->assertEquals([$common_activity], $obj->$getMethod(), "$k list");
}

$obj = ContextActivities::fromJSON('{' . join(",", $all_json) . "}");

$this->assertInstanceOf('TinCan\ContextActivities', $obj);
$this->assertSame(COMMON_GROUP_MBOX, $obj->getMbox(), 'mbox value');
$this->assertEquals([['mbox' => COMMON_MBOX]], $obj->getMember(), 'member list');
$this->assertEquals([$common_activity], $obj->getCategory(), "all props: category list");
$this->assertEquals([$common_activity], $obj->getParent(), "all props: parent list");
$this->assertEquals([$common_activity], $obj->getGrouping(), "all props: grouping list");
$this->assertEquals([$common_activity], $obj->getOther(), "all props: other list");
}
*/

// TODO: need to loop versions
public function testAsVersion() {
Expand Down

0 comments on commit bceec14

Please sign in to comment.