-
Notifications
You must be signed in to change notification settings - Fork 79
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
[WIP] Testing and adapting for php7 if necessary. (Including an increase in Code Coverage) #47
Conversation
I'm assuming this PR is a work in progress. See #46 which may be helpful. |
Yep you're correct thanks for the link. I've changed the title to reflect. |
Ready for merge. |
@johnpbloch as you raised issue #46, would you like to review this PR? |
@garemoko Are you happy with this PR? |
@WillSkates thanks for the poke. I was hoping that @johnpbloch might be set up to test this. Nevertheless, I'll add this to me to-do list to test this branch with php 5.4 which I have installed now, and then see if I can upgrade to php 7 and test with that. |
Sorry, I was travelling at the time, and this fell off my radar since then. I'm checking the tests right now. Regarding a code review, I'm very much not familiar with the codebase, so I'll leave that to someone who is better qualified to review it. |
Well, the PHP7 tests aren't passing for me locally, but neither are the tests in master, so this is probably something wrong with my environment. I will try again later. |
@johnpbloch No problem, thank you for coming back so quickly after the poke. Could you please paste your output? You will need to provide some configuration before you run them i.e. https://github.com/WillSkates/TinCanPHP/blob/master/tests/Config.php.travis-ci @garemoko It might be worth looking at using a VM or a Docker image to run the test suite in. |
Output of tests on master: TinCanPHP (master=) $ /c/PHP56/php vendor/phpunit/phpunit/phpunit tests
PHPUnit 5.1.4 by Sebastian Bergmann and contributors.
.............................................................. 62 / 189 ( 32%)
.........................F.F............F...F................. 124 / 189 ( 65%)
.......................................E......FFFF............ 186 / 189 ( 98%)
... 189 / 189 (100%)
Time: 11.73 seconds, Memory: 7.00Mb
There was 1 error:
1) StatementTest::testVerifyIncorrectPubKey
openssl_pkey_get_details() expects parameter 1 to be resource, boolean given
C:\Users\John\Projects\TinCanPHP\tests\StatementTest.php:811
--
There were 8 failures:
1) RemoteLRSTest::testSaveStatementsWithAttachments
success
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:171
2) RemoteLRSTest::testRetrieveStatementWithAttachments
attachment content
Failed asserting that null is identical to '{"foo":"bar"}'.
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:242
3) RemoteLRSTest::testRetrieveActivity
retrieved activity
'{"error":true,"success":false...ce"}]}' does not match expected type "object".
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:481
4) RemoteLRSTest::testRetrievePerson
retrieved person
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
TinCan\Person Object (
'objectType' => 'Person'
'name' => Array (
- 0 => 'Example User'
)
'mbox' => Array (
- 0 => 'mailto:[email protected]'
)
- 'mbox_sha1sum' => null
- 'openid' => null
- 'account' => null
+ 'mbox_sha1sum' => Array ()
+ 'openid' => Array ()
+ 'account' => Array ()
)
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:541
5) StatementVariationsTest::testAttachmentsString
successful request
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:116
6) StatementVariationsTest::testAttachmentsBinaryFile
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:152
7) StatementVariationsTest::testSignedAndVerified
verify signature
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:186
8) StatementVariationsTest::testSignedAndVerifiedX5c
verify signature
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:220
FAILURES!
Tests: 189, Assertions: 711, Errors: 1, Failures: 8.
Non-exception error occurred:
2: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!
C:\Users\John\Projects\TinCanPHP\src\Statement.php (254) Output from the php7 branch: TinCanPHP (php7=) $ vendor/bin/phpunit tests
PHPUnit 5.1.4 by Sebastian Bergmann and contributors.
.............................................................. 62 / 191 ( 32%)
...........................F.F............F...F............... 124 / 191 ( 64%)
.........................................E......FFFF.......... 186 / 191 ( 97%)
..... 191 / 191 (100%)
Time: 17.39 seconds, Memory: 6.00Mb
There was 1 error:
1) StatementTest::testVerifyIncorrectPubKey
openssl_pkey_get_details() expects parameter 1 to be resource, boolean given
C:\Users\John\Projects\TinCanPHP\tests\StatementTest.php:828
--
There were 8 failures:
1) RemoteLRSTest::testSaveStatementsWithAttachments
success
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:171
2) RemoteLRSTest::testRetrieveStatementWithAttachments
attachment content
Failed asserting that null is identical to '{"foo":"bar"}'.
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:242
3) RemoteLRSTest::testRetrieveActivity
retrieved activity
'{"error":true,"success":false...ce"}]}' does not match expected type "object".
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:481
4) RemoteLRSTest::testRetrievePerson
retrieved person
Failed asserting that two objects are equal.
--- Expected
+++ Actual
@@ @@
TinCan\Person Object (
'objectType' => 'Person'
'name' => Array (
- 0 => 'Example User'
)
'mbox' => Array (
- 0 => 'mailto:[email protected]'
)
- 'mbox_sha1sum' => null
- 'openid' => null
- 'account' => null
+ 'mbox_sha1sum' => Array ()
+ 'openid' => Array ()
+ 'account' => Array ()
)
C:\Users\John\Projects\TinCanPHP\tests\RemoteLRSTest.php:541
5) StatementVariationsTest::testAttachmentsString
successful request
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:116
6) StatementVariationsTest::testAttachmentsBinaryFile
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:152
7) StatementVariationsTest::testSignedAndVerified
verify signature
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:186
8) StatementVariationsTest::testSignedAndVerifiedX5c
verify signature
Failed asserting that false is true.
C:\Users\John\Projects\TinCanPHP\tests\StatementVariationsTest.php:220
FAILURES!
Tests: 191, Assertions: 700, Errors: 1, Failures: 8.
Non-exception error occurred:
2: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate!
C:\Users\John\Projects\TinCanPHP\src\Statement.php (254) Contents of test/Config.php: <?php
$LRSs = [
[
'endpoint' => 'http://localhost:8000/data/xAPI/',
'username' => '402da968f21dee8300df6cc7ded89dea5e3665e8',
'password' => '142a594f5dbcdf8d5d693b27d92d46925a08ce95',
'version' => '1.0.1'
]
];
$KEYs = [
'public' => __DIR__ . '/keys/travis/cacert.pem',
'private' => __DIR__ . '/keys/travis/privkey.pem',
'password' => 'travis',
]; The LRS credentials are from the instance of LearningLocker I have set up locally for testing our own LRS systems and I started this file from scratch and added the credentials directly from the web interface before running the tests, so I know they're correct. The learninglocker version is a bit out of date though, which may be contributing to this. I'll test this again with a more recent version of LL. |
@johnpbloch I imagine that these tests were originally designed against SCORM Cloud. Aside from actual bugs in whichever Learning Locker version you're using, there may be legitimate style issues that cause failed tests. For example on test 4, Learning Locker has returned empty arrays where the test expected the properties to be null. Either are arguably valid by the spec. Ideally the tests should be made to work with any conformant LRS, but that's out of scope of this PR. |
Note: you can get a free SCORM Cloud account for testing here: https://cloud.scorm.com/sc/guest/SignUpForm |
You can also trigger a Travis build yourself on your own fork through their site which will run the tests as I will ultimately. Just beware that simultaneous test runs against the same Cloud account can be problematic, unfortunately the tests aren't safe that way. |
EDIT: Thank you for the input everyone. If the tests pass successfully with Travis the library should work for anyone shouldn't it? |
If I understand what you are asking, not really, short of a bug in Travis which happens from time to time. That consistency is one of the big reasons to rely on Travis. |
@brianjmiller Yeah sorry I'll rewrite that. Are you happy with the PR in general? |
Apologies my hand slipped and I accidentally clicked close instead of comment. |
@@ -22,4 +22,4 @@ todo.md | |||
# eclipse project files | |||
.buildpath | |||
.project | |||
.settings | |||
.settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please avoid whitespace changes in files that haven't otherwise changed in order to avoid wrongly updating the "last updated" date.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hasn't been addressed.
'until', 'limit', | ||
'format' | ||
]; | ||
foreach ($content as $k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why make these separated out, and then change the original array construct for agent to be an inlined version? Does this change apply something for PHP7?
Made a closer first pass. Isolating the changes needed for a specific context would make this kind of thing much simpler in the future, IOW there seem to be relatively few changes necessary to get actual PHP7 compatibility, which could have been isolated from the test coverage pieces, which should have definitely been isolated from subjective code changes. I'll continue to work on this tomorrow, I want to maintain history if you feel it is important. If you'd rather take on a task of splitting this work up, and/or squashing/rebasing then feel free, let me know if you plan to. |
); | ||
$obj = Activity::fromJSON(''); | ||
} | ||
|
||
public function testFromJSONInvalidMalformed() { | ||
$this->setExpectedException( | ||
'InvalidArgumentException', | ||
'Invalid JSON: ' . JSON_ERROR_SYNTAX | ||
'TinCan\JSONParseErrorException' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While a better overall implementation this is a loss of granularity of the unit tests, we no longer test distinguishing malformed versus null/empty. We should maintain that level of detail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh, on further inspection these tests weren't doing what they were originally thought to do anyways. JSON_ERROR_NONE
actually ends up being '' which doesn't change the error message which is why they were passing to begin with.
Hi @brianjmiller. I'm fine to look at cleaning this up for you now that you are active here again. Closing this in favor of a 'cleaner' solution. |
@WillSkates 👍 . I suspect you have, but if you haven't, take a look at #50, I'm planning to accumulate the bare minimum for PHP 7 support there. It leverages the new Exception from this PR though altered a little bit and committed differently (commit message credits you though) and the corresponding changes to test files related to that change. Everything else in here I believe can be brought over in a patch (or minor) version and mostly hinges around testing AFAICT. Splitting up the remaining parts of this PR will help get them through more quickly, for instance, straight additions of new test files (so long as they conform to the rest of the style) should be easy to add as they can't affect functionality. Followed by other adjustments to tests, and then tests and code with the latter being the most dangerous and therefore comes more scrutiny. Isolating groups of changes make it far easier to review and tweak, multiple PRs is better than larger ones. In any case, I look forward to your submissions and appreciate the work (and patience) so far. |
Hi @brianjmiller, Can you please set two milestones:
We can label my PR's against those. Cheers, |
I think the first is a lofty goal, though you are welcome to try. If we're that close then I'd seriously look at where the metric comes from. Having said that, happy to create a milestone. #50 achieves the second, we're there, I'm looking at the namshi/jose issue (#61) a little today. But I plan to cut a last minor version with the existing changes on master and then merge #50 and cut the major release. If you have something that you absolutely want in a major release (because it breaks backwards compat) better get it in very soon. |
@brianjmiller I've already achieved it. I doubt #50 does it fully as the cc in that branch isn't sufficient. I'll see what I can get you when. If you want to push for a major version before then you can but I'd advise against it. |
Is there some reason to advise against it? Current tests pass and they "cover" the "difficult" parts which is the JSON serialization/deserialization, and HTTP requests which are the parts likely to break in PHP 7. AFAICT all other changes in the other PR are either tests or to facilitate tests of what amounts to existing code, and therefore by virtue of it passing so should the result of #50. |
@brianjmiller I ran into places where I had to solve problems that were exposed by new tests. However I honestly can't remember them one by one so it isn't much to go on. I'll defer to you and I can work to improve your test coverage and solve them as we go in following minor versions. Adding this to your local phpunit.xml.dist will give you a more accurate display of the code coverage as it is:
|
Added, in a manor of speaking, to #50, along with some other fixes to make coverage output correctly with latest PHPUnit. |
Heh, so I've gone through the bulk of the added files (all but one) and so far I've run into 3 issues, but none of which are related to PHP 7 support, they are just bugs that are in the 0.x series anyways, so by rights those will likely get fixed as part of it and I'll end up doing another patch release (though I hadn't planned to). I wish they'd been part of a separate PR! Oh well. |
Yeah I definitely agree that they should have been in a separate PR. Your work to split this out is very much appreciated. I'd still like to have a chat on VOIP about the lib in general if you are willing seeing as we still haven't actually met but we've both put in a fair amount of effort on this. You have my email address anyway :D. |
A little research suggests the reason I felt "100% test coverage" was a lofty goal (and not yet achieved) and is summed up by this:
So the coverage is basically line coverage (which is an okay metric, but not great for regression management in a theoretical zero backwards compatibility change use case). I still think it is a worthy goal, but it is really important to understand just what the coverage metric is giving us and to understand the type of risks still present when making extraneous changes. Reference: https://phpunit.de/manual/current/en/code-coverage-analysis.html |
No description provided.