-
Notifications
You must be signed in to change notification settings - Fork 0
/
XboxGamercard.test.php
executable file
·62 lines (50 loc) · 1.41 KB
/
XboxGamercard.test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
require_once 'XboxGamercard.class.php';
define('TEST_GAMERTAG', 'Major Nelson');
echo "Testing XboxGamercard Class\n";
$failed = array();
set_error_handler( function($num, $string) { $failed = true; echo "{$errstr}\n"; } );
set_exception_handler( function($e) { $failed = true; echo "{$e->getMessage()}\n"; } );
$gamercard = new XboxGamercard(TEST_GAMERTAG);
equals(count($gamercard->avatars), 4);
notNull($gamercard->avatars['tile']);
notNull($gamercard->avatars['small']);
notNull($gamercard->avatars['large']);
notNull($gamercard->avatars['body']);
equals($gamercard->subscription, SUBSCRIPTION_GOLD);
equals(count($gamercard->games), 5);
greaterThan( $gamercard->gamerscore, 0 );
echo "{$passed} tests passed\n";
$failCount = count($failed);
echo "{$failCount} tests failed\n";
assert($failCount == 0);
function notNull($value) {
if( $value === null ) {
fail("Expected: not null, Got: null");
} else {
passed();
}
}
function greaterThan($value, $expected) {
if(! $value > $expected ) {
fail("Expected: > {$expected}, Got: {$value}");
} else {
passed();
}
}
function equals($value, $expected) {
if( $value != $expected ) {
fail("Expected: {$expected}, Got: {$value}");
} else {
passed();
}
}
function fail($msg) {
global $failed;
echo $msg . "\n";
$failed[] = $msg;
}
function passed() {
global $passed;
$passed++;
}