Skip to content

Commit af39a2e

Browse files
committed
Merge pull request #32 from texdc/feature-test-config
Reorganize test config
2 parents 8cf4342 + 9da1d8c commit af39a2e

36 files changed

Lines changed: 385 additions & 271 deletions

.gitignore

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
tests/Config.php
1+
tests/config/config.php
22

33
# Third party libraries
44
phpdoc.xml
5+
phpunit.xml
56
php.ini
67

78
# buildables
@@ -11,15 +12,6 @@ sample/vendor
1112
sample/composer.lock
1213
doc/api
1314

14-
# bad.
15-
.DS_Store
16-
*.swp
17-
tmp/
18-
1915
# wild
2016
todo.md
2117

22-
# eclipse project files
23-
.buildpath
24-
.project
25-
.settings

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ php:
66
- 5.4
77
- hhvm
88
before_script:
9-
- cp tests/Config.php.travis-ci tests/Config.php
9+
- cp tests/config/config.travis-ci.php tests/config/config.php
1010
- composer install --dev

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ require 'path/to/TinCan/autoload.php';
2828

2929
### Testing
3030

31-
Tests are implemented using PHPUnit. Configure the LRS endpoint and credentials by copying the `tests/Config.php.template` to `tests/Config.php` then setting the values for your LRS.
31+
Tests are implemented using the latest stable version of PHPUnit. It will be installed when using Composer. Configure the LRS endpoint and credentials by copying the `tests/config/config.dist.php` to `tests/config/config.php` then setting the values for your LRS.
3232

3333
Once configured run:
3434

3535
```
36-
phpunit tests
36+
vendor/bin/phpunit
3737
```
3838

3939
### API Doc Generation
4040

4141
Documentation can be output using [phpDocumentor2](http://phpdoc.org). It will be installed when using Composer. To generate documentation:
4242

4343
```
44-
./vendor/bin/phpdoc.php
44+
vendor/bin/phpdoc
4545
```
4646

4747
From the root of the repository after running `php composer.phar update`. Documentation will be output to `doc/api`.

autoload.php

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,29 @@
1717

1818
if (file_exists('vendor/autoload.php')) {
1919
// prefer the composer autoloader
20-
return require_once('vendor/autoload.php');
20+
require_once('vendor/autoload.php');
21+
}
22+
else if (!class_exists('TinCan\\Version')) {
23+
tincan_register_autoloader('TinCan\\', 'src');
2124
}
2225

23-
spl_autoload_register(function($className) {
24-
$namespace = 'TinCan\\';
25-
if (stripos($className, $namespace) === false) {
26-
return;
27-
}
28-
$sourceDir = __DIR__ . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR;
29-
$fileName = str_replace([$namespace, '\\'], [$sourceDir, DIRECTORY_SEPARATOR], $className) . '.php';
30-
if (is_readable($fileName)) {
31-
include $fileName;
32-
}
33-
});
26+
/**
27+
* Register a namespace autoloader for the TinCan library
28+
*
29+
* A source filepath will be generated based on the current directory.
30+
*
31+
* @param string $namespace a valid namespace, include trailing backslashes ('\\')
32+
* @param string $directory a directory name, not a filepath
33+
*/
34+
function tincan_register_autoloader($namespace, $directory) {
35+
spl_autoload_register(function($className) use ($namespace, $directory) {
36+
if (stripos($className, $namespace) === false) {
37+
return;
38+
}
39+
$sourceDir = __DIR__ . DIRECTORY_SEPARATOR . $directory . DIRECTORY_SEPARATOR;
40+
$fileName = str_replace([$namespace, '\\'], [$sourceDir, DIRECTORY_SEPARATOR], $className) . '.php';
41+
if (is_readable($fileName)) {
42+
include $fileName;
43+
}
44+
});
45+
}

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@
3737
"psr-4": {
3838
"TinCan\\": "src/"
3939
}
40+
},
41+
"autoload-dev": {
42+
"psr-4": {
43+
"TinCanTest\\": "tests/"
44+
}
4045
}
4146
}

phpunit.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

phpunit.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

phpunit.xml.dist

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
bootstrap="tests/config/bootstrap.php"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
syntaxCheck="false"
13+
>
14+
<testsuites>
15+
<testsuite name="TinCanPHP Test Suite">
16+
<directory suffix="Test.php">tests</directory>
17+
<exclude>
18+
<directory>tests/config</directory>
19+
<directory>tests/files</directory>
20+
<directory>tests/keys</directory>
21+
</exclude>
22+
</testsuite>
23+
</testsuites>
24+
25+
<logging>
26+
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"
27+
lowUpperBound="50" highLowerBound="80" />
28+
</logging>
29+
30+
<filter>
31+
<whitelist addUncoveredFilesFromWhitelist="true">
32+
<directory suffix=".php">src</directory>
33+
<exclude>
34+
<directory>doc</directory>
35+
<directory>sample</directory>
36+
<directory>tests</directory>
37+
<directory>vendor</directory>
38+
</exclude>
39+
</whitelist>
40+
</filter>
41+
42+
<php>
43+
<const name="COMMON_NAME" value="Example User" />
44+
<const name="COMMON_EMAIL" value="tincanphp@tincanapi.com" />
45+
<const name="COMMON_GROUP_EMAIL" value="tincanphp+group@tincanapi.com" />
46+
<const name="COMMON_MBOX" value="mailto:tincanphp@tincanapi.com" />
47+
<const name="COMMON_MBOX_SHA1" value="6a7e95ee6c0e353e1eb71950a7f489c1dafa6065" />
48+
<const name="COMMON_GROUP_MBOX" value="mailto:tincanphp+group@tincanapi.com" />
49+
<const name="COMMON_GROUP_MBOX_SHA1" value="cbea4c1e0d11d08e36d4e9823c5be97dd0a8b8f8" />
50+
<const name="COMMON_ACCT_HOMEPAGE" value="http://tincanapi.com" />
51+
<const name="COMMON_ACCT_NAME" value="tincanphp-test" />
52+
<const name="COMMON_OPENID" value="http://tincanapi.com/" />
53+
<const name="COMMON_VERB_ID" value="http://adlnet.gov/expapi/verbs/experienced" />
54+
<const name="COMMON_ACTIVITY_ID" value="http://tincanapi.com/TinCanPHP/Test/Activity" />
55+
<const name="COMMON_EXTENSION_ID_1" value="http://id.tincanapi.com/extension/topic" />
56+
<const name="COMMON_EXTENSION_ID_2" value="http://id.tincanapi.com/extension/location" />
57+
</php>
58+
</phpunit>

tests/AboutTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
limitations under the License.
1616
*/
1717

18+
namespace TinCanTest;
19+
1820
use TinCan\About;
1921

20-
class AboutTest extends PHPUnit_Framework_TestCase {
22+
class AboutTest extends \PHPUnit_Framework_TestCase {
2123
const VERSION_1 = '1.0.0';
2224

2325
public function testInstantiation() {

tests/ActivityDefinitionTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
limitations under the License.
1616
*/
1717

18+
namespace TinCanTest;
19+
1820
use TinCan\ActivityDefinition;
1921

20-
class ActivityDefinitionTest extends PHPUnit_Framework_TestCase {
22+
class ActivityDefinitionTest extends \PHPUnit_Framework_TestCase {
2123
const NAME = 'testName';
2224

2325
private $emptyProperties = array(

0 commit comments

Comments
 (0)