Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improving Agent and Person Code Coverage. #82

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,11 @@ public function asVersion($version) {
if (! empty($versioned_acct)) {
$result['account'] = $versioned_acct;
}
}
elseif (isset($this->mbox_sha1sum)) {
} else if (isset($this->mbox_sha1sum)) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason phpcc won't consider these lines covered when written like this:

elseif (condition) {
}
elseif (condition) {
}

This might just be me but I don't think so.

$result['mbox_sha1sum'] = $this->mbox_sha1sum;
}
elseif (isset($this->mbox)) {
} else if (isset($this->mbox)) {
$result['mbox'] = $this->mbox;
}
elseif (isset($this->openid)) {
} else if (isset($this->openid)) {
$result['openid'] = $this->openid;
}

Expand Down Expand Up @@ -149,6 +146,8 @@ public function getMbox_sha1sum() {
if (isset($this->mbox)) {
return sha1($this->mbox);
}

return false;
}
public function setOpenid($value) { $this->openid = $value; return $this; }
public function getOpenid() { return $this->openid; }
Expand Down
29 changes: 29 additions & 0 deletions tests/AgentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public function testAsVersionMbox() {
$this->assertEquals($versioned, $args, "serialized version matches corrected");
}

// TODO: need to loop versions
public function testAsVersionOpenid() {
$args = [
'openid' => COMMON_OPENID
];

$obj = Agent::fromJSON(json_encode($args, JSON_UNESCAPED_SLASHES));
$versioned = $obj->asVersion('1.0.0');

$args['objectType'] = 'Agent';

$this->assertEquals($versioned, $args, "serialized version matches corrected");
}

public function testAsVersionMboxSha1() {
$args = [
'mbox_sha1sum' => COMMON_MBOX_SHA1
Expand Down Expand Up @@ -201,6 +215,9 @@ public function testGetMbox_sha1sum() {

$obj = new Agent(['mbox' => COMMON_MBOX]);
$this->assertSame($obj->getMbox_sha1sum(), COMMON_MBOX_SHA1, 'sha1 from mbox');

$obj = new Agent();
$this->assertSame($obj->getMbox_sha1sum(), false, 'no mbox at all');
}

public function testCompareWithSignature() {
Expand Down Expand Up @@ -299,6 +316,18 @@ public function testCompareWithSignature() {
'sigArgs' => ['account' => $acct2 ],
'reason' => 'Comparison of account failed: Comparison of name failed: value is not the same'
],
[
'description' => 'missing object account',
'objArgs' => [],
'sigArgs' => ['account' => $acct2 ],
'reason' => 'Comparison of account failed: value not in this'
],
[
'description' => 'missing signature account',
'objArgs' => ['account' => $acct1 ],
'sigArgs' => [],
'reason' => 'Comparison of account failed: value not in signature'
],

//
// special cases where we can try to equate an mbox and an mbox SHA1 sum
Expand Down
6 changes: 6 additions & 0 deletions tests/PersonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public function testAsVersion() {
$obj = new Person(
[
'mbox' => array(COMMON_MBOX),
'name' => COMMON_NAME,
'openid' => COMMON_OPENID,
'mbox_sha1sum' => COMMON_MBOX_SHA1,
'account' => array(
array(
'name' => COMMON_ACCT_NAME,
Expand All @@ -73,6 +76,9 @@ public function testAsVersion() {
[
'objectType' => 'Person',
'mbox' => array(COMMON_MBOX),
'name' => COMMON_NAME,
'openid' => COMMON_OPENID,
'mbox_sha1sum' => COMMON_MBOX_SHA1,
'account' => array(
array(
'name' => COMMON_ACCT_NAME,
Expand Down