Skip to content

Commit c845d8f

Browse files
committed
Apply fixes found during coverage improvements
* Significant unit test coverage improvement (credit @WillSkates) * Patches to issues found while applying the above (also credit @WillSkates) * Exception namespace issue in `Map` and `State` * Accept-Language header issue in `RemoteLRS.retrieveActivity` * Incorrect class in failure reason in `SignatureComparisonTrait` * Style fix for 'else if'
1 parent 2bee590 commit c845d8f

21 files changed

+560
-8
lines changed

src/AsVersionTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function asVersion($version) {
4646
if ($value instanceof VersionableInterface) {
4747
$value = $value->asVersion($version);
4848
}
49-
else if (is_array($value) && !empty($value)) {
49+
elseif (is_array($value) && !empty($value)) {
5050
$tmp_value = array();
5151
foreach ($value as $element) {
5252
if ($element instanceof VersionableInterface) {

src/Map.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function __call($func, $args) {
5555
return $this->_unset($args[0]);
5656
break;
5757
default:
58-
throw new BadMethodCallException(__CLASS__ . "::$func() does not exist");
58+
throw new \BadMethodCallException(get_class($this) . "::$func() does not exist");
5959
}
6060
}
6161
}

src/RemoteLRS.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private function _parseMetadata($metadata) {
229229
if ($pair[0] === 'charset') {
230230
$result['headers']['contentTypeCharset'] = $pair[1];
231231
}
232-
else if ($pair[0] === 'boundary') {
232+
elseif ($pair[0] === 'boundary') {
233233
$result['headers']['contentTypeBoundary'] = $pair[1];
234234
}
235235
}
@@ -246,7 +246,7 @@ private function _parseMultipart($boundary, $content) {
246246
if ($part === '') {
247247
continue;
248248
}
249-
else if ($part === '--') {
249+
elseif ($part === '--') {
250250
break;
251251
}
252252
list($header, $body) = explode("\r\n\r\n", $part, 2);
@@ -956,7 +956,7 @@ public function deleteActivityProfile($activity, $id) {
956956
public function retrieveActivity($activityid) {
957957
$headers = array('Accept-language: *');
958958
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
959-
$headers = 'Accept-language: ' . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . ', *';
959+
$headers = array('Accept-language: ' . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . ', *');
960960
}
961961

962962
$response = $this->sendRequest(

src/SignatureComparisonTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private static function doMatch($a, $b, $description) {
6868
}
6969

7070
if (is_object($a) && ! ($b instanceof $a)) {
71-
$result['reason'] = "Comparison of $description failed: not a " . get_class($this) . " value";
71+
$result['reason'] = "Comparison of $description failed: not a " . get_class($a) . " value";
7272
return $result;
7373
}
7474

src/State.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function getAgent() { return $this->agent; }
5252

5353
public function setRegistration($value) {
5454
if (isset($value) && ! preg_match(Util::UUID_REGEX, $value)) {
55-
throw new InvalidArgumentException('arg1 must be a UUID');
55+
throw new \InvalidArgumentException('arg1 must be a UUID');
5656
}
5757

5858
$this->registration = $value;

src/Statement.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public function verify($options = array()) {
249249
if (isset($options['publicKey'])) {
250250
$publicKeyFile = $options['publicKey'];
251251
}
252-
else if (isset($header['x5c'])) {
252+
elseif (isset($header['x5c'])) {
253253
$cert = "-----BEGIN CERTIFICATE-----\r\n" . chunk_split($header['x5c'][0], 64, "\r\n") . "-----END CERTIFICATE-----\r\n";
254254
$cert = openssl_x509_read($cert);
255255
if (! $cert) {

tests/ActivityProfileTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/*
3+
Copyright 2016 Rustici Software
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
namespace TinCanTest;
19+
20+
use TinCan\ActivityProfile;
21+
use TinCan\Activity;
22+
23+
class ActivityProfileTest extends \PHPUnit_Framework_TestCase {
24+
public function testSetActivity() {
25+
$profile = new ActivityProfile();
26+
$profile->setActivity(['id' => COMMON_ACTIVITY_ID]);
27+
28+
$this->assertInstanceOf('TinCan\Activity', $profile->getActivity());
29+
}
30+
}

tests/AgentProfileTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/*
3+
Copyright 2016 Rustici Software
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
namespace TinCanTest;
19+
20+
use TinCan\AgentProfile;
21+
use TinCan\Agent;
22+
use TinCan\Group;
23+
24+
class AgentProfileTest extends \PHPUnit_Framework_TestCase {
25+
public function testSetAgent() {
26+
$profile = new AgentProfile();
27+
$profile->setAgent(['mbox' => COMMON_MBOX]);
28+
29+
$this->assertInstanceOf('TinCan\Agent', $profile->getAgent());
30+
31+
$profile->setAgent(['objectType' => 'Group']);
32+
33+
$this->assertInstanceOf('TinCan\Group', $profile->getAgent());
34+
}
35+
}

tests/ContextActivitiesTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,26 @@ public function testCompareWithSignature() {
276276
}
277277
$this->runSignatureCases("TinCan\ContextActivities", $cases);
278278
}
279+
280+
/**
281+
* @dataProvider invalidListSetterDataProvider
282+
*/
283+
public function testListSetterThrowsInvalidArgumentException($publicMethodName, $invalidValue) {
284+
$this->setExpectedException(
285+
'InvalidArgumentException',
286+
'type of arg1 must be Activity, array of Activity properties, or array of Activity/array of Activity properties'
287+
);
288+
$obj = new ContextActivities();
289+
$obj->$publicMethodName($invalidValue);
290+
}
291+
292+
public function invalidListSetterDataProvider() {
293+
$invalidValue = 1;
294+
return [
295+
["setCategory", $invalidValue],
296+
["setParent", $invalidValue],
297+
["setGrouping", $invalidValue],
298+
["setOther", $invalidValue]
299+
];
300+
}
279301
}

tests/ContextTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,23 @@ public function testCompareWithSignature() {
359359
];
360360
$this->runSignatureCases("TinCan\Context", $cases);
361361
}
362+
363+
public function testSetInstructorConvertToGroup() {
364+
$obj = new Context();
365+
$obj->setInstructor(
366+
[
367+
'objectType' => 'Group'
368+
]
369+
);
370+
$this->assertInstanceOf('TinCan\Group', $obj->getInstructor());
371+
}
372+
373+
public function testSetRegistrationInvalidArgumentException() {
374+
$this->setExpectedException(
375+
'InvalidArgumentException',
376+
'arg1 must be a UUID'
377+
);
378+
$obj = new Context();
379+
$obj->setRegistration('232....3.3..3./2/2/1m3m3m3');
380+
}
362381
}

0 commit comments

Comments
 (0)