summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorNeuman Vong <neuman@twilio.com>2011-03-25 16:08:00 -0700
committerNeuman Vong <neuman@twilio.com>2011-03-25 16:10:34 -0700
commit24e03229ce504897bf7674039367905469d19ef7 (patch)
tree6235af5773ff43296bad4c5ad3c814d99026a832 /tests
downloadphp-jwt-24e03229ce504897bf7674039367905469d19ef7.zip
php-jwt-24e03229ce504897bf7674039367905469d19ef7.tar.gz
php-jwt-24e03229ce504897bf7674039367905469d19ef7.tar.bz2
Start tracking project
Diffstat (limited to 'tests')
-rw-r--r--tests/Bootstrap.php9
-rw-r--r--tests/JWTTest.php31
-rw-r--r--tests/phpunit.xml7
3 files changed, 47 insertions, 0 deletions
diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php
new file mode 100644
index 0000000..235b6d3
--- /dev/null
+++ b/tests/Bootstrap.php
@@ -0,0 +1,9 @@
+<?php
+
+error_reporting(E_ALL | E_STRICT);
+ini_set('display_errors', 1);
+
+$root = realpath(dirname(dirname(__FILE__)));
+require_once $root . '/JWT.php';
+
+unset($root);
diff --git a/tests/JWTTest.php b/tests/JWTTest.php
new file mode 100644
index 0000000..4549f1b
--- /dev/null
+++ b/tests/JWTTest.php
@@ -0,0 +1,31 @@
+<?php
+
+class JWTTests extends PHPUnit_Framework_TestCase {
+ function testEncodeDecode() {
+ $msg = JWT::encode('abc', 'my_key');
+ $this->assertEquals(JWT::decode($msg, 'my_key'), 'abc');
+ }
+
+ function testDecodeFromPython() {
+ $msg = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.Iio6aHR0cDovL2FwcGxpY2F0aW9uL2NsaWNreT9ibGFoPTEuMjMmZi5vbz00NTYgQUMwMDAgMTIzIg.E_U8X2YpMT5K1cEiT_3-IvBYfrdIFIeVYeOqre_Z5Cg';
+ $this->assertEquals(
+ JWT::decode($msg, 'my_key'),
+ '*:http://application/clicky?blah=1.23&f.oo=456 AC000 123'
+ );
+ }
+
+ function testUrlSafeCharacters() {
+ $encoded = JWT::encode('f?', 'a');
+ $this->assertEquals('f?', JWT::decode($encoded, 'a'));
+ }
+
+ function testMalformedUtf8StringsFail() {
+ $this->setExpectedException('DomainException');
+ JWT::encode(pack('c', 128), 'a');
+ }
+
+ function testMalformedJsonThrowsException() {
+ $this->setExpectedException('DomainException');
+ JWT::jsonDecode('this is not valid JSON string');
+ }
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
new file mode 100644
index 0000000..ebfe3cf
--- /dev/null
+++ b/tests/phpunit.xml
@@ -0,0 +1,7 @@
+<phpunit bootstrap="./Bootstrap.php">
+ <testsuites>
+ <testsuite name="Services Twilio Test Suite">
+ <directory>./</directory>
+ </testsuite>
+ </testsuites>
+</phpunit>