diff options
author | Stanley Cheung <stanleycheung@google.com> | 2016-02-12 16:37:19 -0800 |
---|---|---|
committer | Stanley Cheung <stanleycheung@google.com> | 2016-02-12 16:37:19 -0800 |
commit | cccf9295e6e6d2da8c8c283b5c1ee0001975e525 (patch) | |
tree | bfd0cf2b6aab8d0d57565b202c3ac401b7998f04 /src/php/tests/unit_tests/TimevalTest.php | |
parent | 2ba7885f5c9af63f6cea9faa7351ca0b54331b85 (diff) |
php: add more unit tests to improve code coverage
Diffstat (limited to 'src/php/tests/unit_tests/TimevalTest.php')
-rwxr-xr-x | src/php/tests/unit_tests/TimevalTest.php | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/php/tests/unit_tests/TimevalTest.php b/src/php/tests/unit_tests/TimevalTest.php index 1d2a8d303e..43abba126a 100755 --- a/src/php/tests/unit_tests/TimevalTest.php +++ b/src/php/tests/unit_tests/TimevalTest.php @@ -91,4 +91,69 @@ class TimevalTest extends PHPUnit_Framework_TestCase $back_to_now = $deadline->subtract($delta); $this->assertSame(0, Grpc\Timeval::compare($back_to_now, $now)); } + + public function testSimilar() + { + $a = Grpc\Timeval::now(); + $delta = new Grpc\Timeval(1000); + $b = $a->add($delta); + $thresh = new Grpc\Timeval(1100); + $this->assertTrue(Grpc\Timeval::similar($a, $b, $thresh)); + $thresh = new Grpc\Timeval(900); + $this->assertFalse(Grpc\Timeval::similar($a, $b, $thresh)); + } + + public function testSleepUntil() + { + $curr_microtime = microtime(true); + $now = Grpc\Timeval::now(); + $delta = new Grpc\Timeval(1000); + $deadline = $now->add($delta); + $deadline->sleepUntil(); + $done_microtime = microtime(true); + $this->assertTrue(($done_microtime - $curr_microtime) > 0.0009); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testConstructorInvalidParam() + { + $delta = new Grpc\Timeval('abc'); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testAddInvalidParam() + { + $a = Grpc\Timeval::now(); + $a->add(1000); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testSubtractInvalidParam() + { + $a = Grpc\Timeval::now(); + $a->subtract(1000); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testCompareInvalidParam() + { + $a = Grpc\Timeval::compare(1000, 1100); + } + + /** + * @expectedException InvalidArgumentException + */ + public function testSimilarInvalidParam() + { + $a = Grpc\Timeval::similar(1000, 1100, 1200); + } + } |