PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/ZendTest/ModuleManager/Listener/ListenerOptionsTest.php

https://bitbucket.org/gencer/zf2
PHP | 120 lines | 99 code | 14 blank | 7 comment | 0 complexity | 975e6f562487acdac63a344f699d0e68 MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework (http://framework.zend.com/)
  4. *
  5. * @link http://github.com/zendframework/zf2 for the canonical source repository
  6. * @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. */
  9. namespace ZendTest\ModuleManager\Listener;
  10. use PHPUnit_Framework_TestCase as TestCase;
  11. use Zend\Config\Config;
  12. use Zend\ModuleManager\Listener\ListenerOptions;
  13. class ListenerOptionsTest extends TestCase
  14. {
  15. public function testCanConfigureWithArrayInConstructor()
  16. {
  17. $options = new ListenerOptions(array(
  18. 'cache_dir' => __DIR__,
  19. 'config_cache_enabled' => true,
  20. 'config_cache_key' => 'foo',
  21. 'module_paths' => array('module','paths'),
  22. 'config_glob_paths' => array('glob','paths'),
  23. 'config_static_paths' => array('static','custom_paths'),
  24. ));
  25. $this->assertSame($options->getCacheDir(), __DIR__);
  26. $this->assertTrue($options->getConfigCacheEnabled());
  27. $this->assertNotNull(strstr($options->getConfigCacheFile(), __DIR__));
  28. $this->assertNotNull(strstr($options->getConfigCacheFile(), '.php'));
  29. $this->assertSame('foo', $options->getConfigCacheKey());
  30. $this->assertSame(array('module', 'paths'), $options->getModulePaths());
  31. $this->assertSame(array('glob', 'paths'), $options->getConfigGlobPaths());
  32. $this->assertSame(array('static', 'custom_paths'), $options->getConfigStaticPaths());
  33. }
  34. public function testCanAccessKeysAsProperties()
  35. {
  36. $options = new ListenerOptions(array(
  37. 'cache_dir' => __DIR__,
  38. 'config_cache_enabled' => true,
  39. 'config_cache_key' => 'foo',
  40. 'module_paths' => array('module','paths'),
  41. 'config_glob_paths' => array('glob','paths'),
  42. 'config_static_paths' => array('static','custom_paths'),
  43. ));
  44. $this->assertSame($options->cache_dir, __DIR__);
  45. $options->cache_dir = 'foo';
  46. $this->assertSame($options->cache_dir, 'foo');
  47. $this->assertTrue(isset($options->cache_dir));
  48. unset($options->cache_dir);
  49. $this->assertFalse(isset($options->cache_dir));
  50. $this->assertTrue($options->config_cache_enabled);
  51. $options->config_cache_enabled = false;
  52. $this->assertFalse($options->config_cache_enabled);
  53. $this->assertEquals('foo', $options->config_cache_key);
  54. $this->assertSame(array('module', 'paths'), $options->module_paths);
  55. $this->assertSame(array('glob', 'paths'), $options->config_glob_paths);
  56. $this->assertSame(array('static', 'custom_paths'), $options->config_static_paths);
  57. }
  58. public function testSetModulePathsAcceptsConfigOrTraverable()
  59. {
  60. $config = new Config(array(__DIR__));
  61. $options = new ListenerOptions;
  62. $options->setModulePaths($config);
  63. $this->assertSame($config, $options->getModulePaths());
  64. }
  65. public function testSetModulePathsThrowsInvalidArgumentException()
  66. {
  67. $this->setExpectedException('InvalidArgumentException');
  68. $options = new ListenerOptions;
  69. $options->setModulePaths('asd');
  70. }
  71. public function testSetConfigGlobPathsAcceptsConfigOrTraverable()
  72. {
  73. $config = new Config(array(__DIR__));
  74. $options = new ListenerOptions;
  75. $options->setConfigGlobPaths($config);
  76. $this->assertSame($config, $options->getConfigGlobPaths());
  77. }
  78. public function testSetConfigGlobPathsThrowsInvalidArgumentException()
  79. {
  80. $this->setExpectedException('InvalidArgumentException');
  81. $options = new ListenerOptions;
  82. $options->setConfigGlobPaths('asd');
  83. }
  84. public function testSetConfigStaticPathsThrowsInvalidArgumentException()
  85. {
  86. $this->setExpectedException('InvalidArgumentException');
  87. $options = new ListenerOptions;
  88. $options->setConfigStaticPaths('asd');
  89. }
  90. public function testSetExtraConfigAcceptsArrayOrTraverable()
  91. {
  92. $array = array(__DIR__);
  93. $traversable = new Config($array);
  94. $options = new ListenerOptions;
  95. $this->assertSame($options, $options->setExtraConfig($array));
  96. $this->assertSame($array, $options->getExtraConfig());
  97. $this->assertSame($options, $options->setExtraConfig($traversable));
  98. $this->assertSame($traversable, $options->getExtraConfig());
  99. }
  100. public function testSetExtraConfigThrowsInvalidArgumentException()
  101. {
  102. $this->setExpectedException('InvalidArgumentException');
  103. $options = new ListenerOptions;
  104. $options->setExtraConfig('asd');
  105. }
  106. }