MemcachedCasterTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\VarDumper\Tests\Caster;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\VarDumper\Test\VarDumperTestTrait;
  13. /**
  14. * @author Jan Schädlich <jan.schaedlich@sensiolabs.de>
  15. */
  16. class MemcachedCasterTest extends TestCase
  17. {
  18. use VarDumperTestTrait;
  19. public function testCastMemcachedWithDefaultOptions()
  20. {
  21. if (!class_exists('Memcached')) {
  22. $this->markTestSkipped('Memcached not available');
  23. }
  24. $var = new \Memcached();
  25. $var->addServer('127.0.0.1', 11211);
  26. $var->addServer('127.0.0.2', 11212);
  27. $expected = <<<EOTXT
  28. Memcached {
  29. servers: array:2 [
  30. 0 => array:3 [
  31. "host" => "127.0.0.1"
  32. "port" => 11211
  33. "type" => "TCP"
  34. ]
  35. 1 => array:3 [
  36. "host" => "127.0.0.2"
  37. "port" => 11212
  38. "type" => "TCP"
  39. ]
  40. ]
  41. options: {}
  42. }
  43. EOTXT;
  44. $this->assertDumpEquals($expected, $var);
  45. }
  46. public function testCastMemcachedWithCustomOptions()
  47. {
  48. if (!class_exists('Memcached')) {
  49. $this->markTestSkipped('Memcached not available');
  50. }
  51. $var = new \Memcached();
  52. $var->addServer('127.0.0.1', 11211);
  53. $var->addServer('127.0.0.2', 11212);
  54. // set a subset of non default options to test boolean, string and integer output
  55. $var->setOption(\Memcached::OPT_COMPRESSION, false);
  56. $var->setOption(\Memcached::OPT_PREFIX_KEY, 'pre');
  57. $var->setOption(\Memcached::OPT_DISTRIBUTION, \Memcached::DISTRIBUTION_CONSISTENT);
  58. $expected = <<<'EOTXT'
  59. Memcached {
  60. servers: array:2 [
  61. 0 => array:3 [
  62. "host" => "127.0.0.1"
  63. "port" => 11211
  64. "type" => "TCP"
  65. ]
  66. 1 => array:3 [
  67. "host" => "127.0.0.2"
  68. "port" => 11212
  69. "type" => "TCP"
  70. ]
  71. ]
  72. options: {
  73. OPT_COMPRESSION: false
  74. OPT_PREFIX_KEY: "pre"
  75. OPT_DISTRIBUTION: 1
  76. }
  77. }
  78. EOTXT;
  79. $this->assertDumpEquals($expected, $var);
  80. }
  81. }