From af9ee8f3d6f57c11be4ca06787469194d2237597 Mon Sep 17 00:00:00 2001 From: Will Date: Fri, 27 Jan 2017 00:18:29 +0000 Subject: [PATCH 1/2] Improving Agent and Person Code Coverage. --- src/Agent.php | 11 +++++------ tests/AgentTest.php | 29 +++++++++++++++++++++++++++++ tests/PersonTest.php | 6 ++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/Agent.php b/src/Agent.php index 8bed2bd..dbf6e78 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -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)) { $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; } @@ -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; } diff --git a/tests/AgentTest.php b/tests/AgentTest.php index a027de8..4e3a680 100644 --- a/tests/AgentTest.php +++ b/tests/AgentTest.php @@ -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 @@ -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() { @@ -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 diff --git a/tests/PersonTest.php b/tests/PersonTest.php index bceb7e8..9b458b2 100644 --- a/tests/PersonTest.php +++ b/tests/PersonTest.php @@ -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, @@ -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, From fa97bcace10c42d5c55b8a9a1d97cd1dd294bd9c Mon Sep 17 00:00:00 2001 From: William Skates Date: Mon, 20 Mar 2017 08:22:56 +0000 Subject: [PATCH 2/2] Forcing the 5.* releases for phpunit. This is to avoid the namespacing changes that come in PHPUnit 6. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 7786424..0dae765 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "phpdocumentor/phpdocumentor": "2.*", - "phpunit/phpunit": "@stable" + "phpunit/phpunit": "^5.7" }, "autoload": { "psr-4": {