From 43d7170316cc1b2abe825b399a5bce69a7d2bb6a Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 21 Mar 2018 09:25:03 +0000 Subject: [PATCH] Exceptions unit tests --- tests/Unit/ExceptionsTest.php | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 tests/Unit/ExceptionsTest.php diff --git a/tests/Unit/ExceptionsTest.php b/tests/Unit/ExceptionsTest.php new file mode 100644 index 0000000..5310fdd --- /dev/null +++ b/tests/Unit/ExceptionsTest.php @@ -0,0 +1,41 @@ +expectException(Exception::class); + (new BucketManager)->getRandomBucket(); + } + + public function testCreatingWeightedBucketWithStringWeight() + { + $this->expectException(Exception::class); + (new WeightedBucket(new Bucket('https://php.net/')))->setWeight('not a number!'); + } + + public function testCreatingWeightedBucketWithFloatWeight() + { + $this->expectException(Exception::class); + (new WeightedBucket(new Bucket('https://php.net/')))->setWeight(2.75); + } + + public function testCreatingWeightedBucketWithNegativeWeight() + { + $this->expectException(Exception::class); + (new WeightedBucket(new Bucket('https://php.net/')))->setWeight(-1); + } + + public function testCreatingWeightedBucketWithZeroWeight() + { + $this->expectException(Exception::class); + (new WeightedBucket(new Bucket('https://php.net/')))->setWeight(0); + } + +}