PoolTest.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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\Pool;
  9. class PoolTest extends TestCase
  10. {
  11. /**
  12. * @dataProvider testArgumentsDataProvider
  13. */
  14. public function testArguments($setFunction, $arguments, $getFunction, $invalid)
  15. {
  16. $pool = new Pool('bogus', []);
  17. foreach ($arguments as $argument) {
  18. if ($invalid) {
  19. try {
  20. $pool->{$setFunction}($argument);
  21. } catch (ConfigurationsException $e) {
  22. $this->assertNotEquals($argument, $pool->{$getFunction}());
  23. }
  24. } elseif ($invalid === false) {
  25. $pool->{$setFunction}($argument);
  26. $this->assertEquals($argument, $pool->{$getFunction}());
  27. }
  28. }
  29. }
  30. public function testArgumentsDataProvider()
  31. {
  32. return [
  33. 'origins arguments valid' => [
  34. 'setOrigins', [[['name' => 'test', 'address' => 'server1.example.com']]], 'getOrigins', false
  35. ],
  36. 'setNotificationEmail arguments valid' => [
  37. 'setNotificationEmail', ['user@example.com'], 'getNotificationEmail', false
  38. ],
  39. 'origins arguments invalid no address' => [
  40. 'setOrigins', [['name' => 'test']], 'getOrigins', true
  41. ],
  42. 'origins arguments invalid no name' => [
  43. 'setOrigins', [['address' => 'server1.example.com']], 'getOrigins', true
  44. ],
  45. 'setNotificationEmail arguments invalid' => [
  46. 'setNotificationEmail', ['userexample.com'], 'getNotificationEmail', true
  47. ]
  48. ];
  49. }
  50. }