$file) { Assert::equal('develop', $file->repo); Assert::equal('snapshot', $file->package); Assert::equal('77fe1aff5f0bdd78ff2ebb65f91b4029ec8547d7', $file->version); Assert::equal('boostorg', $file->owner); } Assert::equal(array(0,1,2), array_keys($files)); Assert::equal('boost_1_62_0.tar.bz2', $files[0]->name); Assert::equal('boost_1_62_0.tar.bz2', $files[0]->path); Assert::equal('2016-07-20T15:43:49.478Z', $files[0]->created); Assert::equal(88784711, $files[0]->size); Assert::equal('2cd2843c55b87fce62f4751c1077f60e8909a5a8', $files[0]->sha1); Assert::equal('66dbe3586db64a2c9087ddcdc266fea8bdcdff515b4a06ba1c235e8631bcaa4b', $files[0]->sha256); Assert::equal('boost_1_62_0.tar.gz', $files[1]->name); Assert::equal('boost_1_62_0.tar.gz', $files[1]->path); Assert::equal('2016-07-20T15:43:55.469Z', $files[1]->created); Assert::equal(110025970, $files[1]->size); Assert::equal('a993c8150de20dbac4021959cd7485861dc12e06', $files[1]->sha1); Assert::equal('bf2fcc47120b58ecda6581121b4b785d00e394f7fc365f98f669ffe51f2e8689', $files[1]->sha256); Assert::equal('boost_1_62_0.zip', $files[2]->name); Assert::equal('boost_1_62_0.zip', $files[2]->path); Assert::equal('2016-07-20T15:44:15.994Z', $files[2]->created); Assert::equal(167336405, $files[2]->size); Assert::equal('b45d64a38c6195572057fe9874750c7fa329e274', $files[2]->sha1); Assert::equal('0caa60780b58374889926c2d803df429a9ca5987b4c30249e086a1624fa6573b', $files[2]->sha256); } function testSortByVersionDate() { // If there are files from different versions, prioritize the more // recent file. // // TODO: Deal with weird edge case where the dates for two versions // overlap, so that it isn't a consistent order. Seems very // unlikely, and if it does happen, no realy way to work out // the more recent ordering without checking the git repo, // which I don't really want to do. // Maybe use the earlist date for a given version? $json = array( (object) array( 'name' => 'boost_1_62_0.tar.bz2', 'path' => 'boost_1_62_0.tar.bz2', 'version' => 'aaaaaaaa', 'created' => '2016-07-04', ), (object) array( 'name' => 'boost_1_62_0.zip', 'path' => 'boost_1_62_0.zip', 'version' => 'bbbbbbbbb', 'created' => '2016-07-05', ), (object) array( 'name' => 'boost_1_62_0.tar.gz', 'path' => 'boost_1_62_0.tar.gz', 'version' => 'bbbbbbbbb', 'created' => '2016-07-05', ), (object) array( 'name' => 'boost_1_62_0.7z', 'path' => 'boost_1_62_0.7z', 'version' => 'bbbbbbbbb', 'created' => '2016-07-05', ), ); $files = Documentation::getPrioritizedDownloads($json); Assert::equal(array(0,1,2), array_keys($files)); Assert::equal('boost_1_62_0.tar.gz', $files[0]->name); Assert::equal('boost_1_62_0.zip', $files[1]->name); Assert::equal('boost_1_62_0.tar.bz2', $files[2]->name); } function testSortByVersionDateDuplicateExtension() { $json = array( (object) array( 'name' => 'boost_1_62_0.tar.bz2', 'path' => 'boost_1_62_0.tar.bz2', 'version' => 'aaaaaaaa', 'created' => '2016-07-04', ), (object) array( 'name' => 'boost_1_62_0.tar.bz2', 'path' => 'boost_1_62_0.tar.bz2', 'version' => 'bbbbbbbbb', 'created' => '2016-07-05', ), ); $files = Documentation::getPrioritizedDownloads($json); Assert::equal(array(0,1), array_keys($files)); Assert::equal('boost_1_62_0.tar.bz2', $files[0]->name); Assert::equal('boost_1_62_0.tar.bz2', $files[1]->name); Assert::equal('bbbbbbbbb', $files[0]->version); Assert::equal('aaaaaaaa', $files[1]->version); } function testNoMatches() { $json = array( (object) array( 'name' => 'boost_1_62_0.7z', 'path' => 'boost_1_62_0.7z', 'version' => 'aaaaaaaa', 'created' => '2016-07-04', ), (object) array( 'name' => 'boost_1_62_0.txt', 'path' => 'boost_1_62_0.txt', 'version' => 'bbbbbbbbb', 'created' => '2016-07-05', ), ); Assert::exception(function() use($json) { Documentation::getPrioritizedDownloads($json); }, 'RuntimeException', '#Unable to find file#'); } function testEmptyDownload() { Assert::exception(function() { Documentation::getPrioritizedDownloads(array()); }, 'RuntimeException', '#Unable to find file#'); } } $test = new DocumentationTest(); $test->run();