LoadBalancerTest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * @author Martijn Smidt <martijn@squeezely.tech>
  4. * User: HemeraOne
  5. * Date: 13/05/2019
  6. */
  7. use Cloudflare\API\Configurations\ConfigurationsException;
  8. use Cloudflare\API\Configurations\LoadBalancer;
  9. class LoadBalancerTest extends TestCase
  10. {
  11. /**
  12. * @dataProvider testArgumentsDataProvider
  13. */
  14. public function testArguments($setFunction, $arguments, $getFunction, $invalid)
  15. {
  16. $loadBalancer = new LoadBalancer('bogus', [], 'bogus');
  17. foreach ($arguments as $argument) {
  18. if ($invalid === true) {
  19. try {
  20. $loadBalancer->{$setFunction}($argument);
  21. } catch (ConfigurationsException $e) {
  22. $this->assertNotEquals($argument, $loadBalancer->{$getFunction}());
  23. }
  24. } elseif ($invalid === false) {
  25. $loadBalancer->{$setFunction}($argument);
  26. $this->assertEquals($argument, $loadBalancer->{$getFunction}());
  27. }
  28. }
  29. }
  30. public function testArgumentsDataProvider()
  31. {
  32. return [
  33. 'steeringPolicy arguments valid' => [
  34. 'setSteeringPolicy', ['off', 'geo', 'random', 'dynamic_latency', ''], 'getSteeringPolicy', false
  35. ],
  36. 'sessionAffinity arguments valid' => [
  37. 'setSessionAffinity', ['none', 'cookie', 'ip_cookie', ''], 'getSessionAffinity', false
  38. ],
  39. 'sessionAffinityTtl arguments valid' => [
  40. 'setSessionAffinityTtl', [3600], 'getSessionAffinityTtl', false
  41. ],
  42. 'steeringPolicy arguments invalid' => [
  43. 'setSteeringPolicy', ['invalid'], 'getSteeringPolicy', true
  44. ],
  45. 'sessionAffinity arguments invalid' => [
  46. 'setSessionAffinity', ['invalid'], 'getSessionAffinity', true
  47. ],
  48. 'sessionAffinityTtl arguments invalid' => [
  49. 'setSessionAffinityTtl', [1337], 'getSessionAffinityTtl', true
  50. ],
  51. ];
  52. }
  53. }