PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/ModuleManager/Listener/ListenerOptionsTest.php

https://bitbucket.org/aboozar/zf2
PHP | 96 lines | 79 code | 9 blank | 8 comment | 0 complexity | 999214b8a128e8b599bde8c3a06efb03 MD5 | raw file
Possible License(s): BSD-3-Clause
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  7. * @license http://framework.zend.com/license/new-bsd New BSD License
  8. * @package Zend_ModuleManager
  9. */
  10. namespace ZendTest\ModuleManager\Listener;
  11. use BadMethodCallException;
  12. use InvalidArgumentException;
  13. use PHPUnit_Framework_TestCase as TestCase;
  14. use Zend\Config\Config;
  15. use Zend\ModuleManager\Listener\ListenerOptions;
  16. class ListenerOptionsTest extends TestCase
  17. {
  18. public function testCanConfigureWithArrayInConstructor()
  19. {
  20. $options = new ListenerOptions(array(
  21. 'cache_dir' => __DIR__,
  22. 'config_cache_enabled' => true,
  23. 'config_cache_key' => 'foo',
  24. 'module_paths' => array('module','paths'),
  25. 'config_glob_paths' => array('glob','paths'),
  26. 'config_static_paths' => array('static','custom_paths'),
  27. ));
  28. $this->assertSame($options->getCacheDir(), __DIR__);
  29. $this->assertTrue($options->getConfigCacheEnabled());
  30. $this->assertNotNull(strstr($options->getConfigCacheFile(), __DIR__));
  31. $this->assertNotNull(strstr($options->getConfigCacheFile(), '.php'));
  32. $this->assertSame('foo', $options->getConfigCacheKey());
  33. $this->assertSame(array('module', 'paths'), $options->getModulePaths());
  34. $this->assertSame(array('glob', 'paths'), $options->getConfigGlobPaths());
  35. $this->assertSame(array('static', 'custom_paths'), $options->getConfigStaticPaths());
  36. }
  37. public function testCanAccessKeysAsProperties()
  38. {
  39. $options = new ListenerOptions(array(
  40. 'cache_dir' => __DIR__,
  41. 'config_cache_enabled' => true,
  42. 'config_cache_key' => 'foo',
  43. 'module_paths' => array('module','paths'),
  44. 'config_glob_paths' => array('glob','paths'),
  45. 'config_static_paths' => array('static','custom_paths'),
  46. ));
  47. $this->assertSame($options->cache_dir, __DIR__);
  48. $options->cache_dir = 'foo';
  49. $this->assertSame($options->cache_dir, 'foo');
  50. $this->assertTrue(isset($options->cache_dir));
  51. unset($options->cache_dir);
  52. $this->assertFalse(isset($options->cache_dir));
  53. $this->assertTrue($options->config_cache_enabled);
  54. $options->config_cache_enabled = false;
  55. $this->assertFalse($options->config_cache_enabled);
  56. $this->assertEquals('foo', $options->config_cache_key);
  57. $this->assertSame(array('module', 'paths'), $options->module_paths);
  58. $this->assertSame(array('glob', 'paths'), $options->config_glob_paths);
  59. $this->assertSame(array('static', 'custom_paths'), $options->config_static_paths);
  60. }
  61. public function testSetModulePathsAcceptsConfigOrTraverable()
  62. {
  63. $config = new Config(array(__DIR__));
  64. $options = new ListenerOptions;
  65. $options->setModulePaths($config);
  66. $this->assertSame($config, $options->getModulePaths());
  67. }
  68. public function testSetModulePathsThrowsInvalidArgumentException()
  69. {
  70. $this->setExpectedException('InvalidArgumentException');
  71. $options = new ListenerOptions;
  72. $options->setModulePaths('asd');
  73. }
  74. public function testSetConfigGlobPathsAcceptsConfigOrTraverable()
  75. {
  76. $config = new Config(array(__DIR__));
  77. $options = new ListenerOptions;
  78. $options->setConfigGlobPaths($config);
  79. $this->assertSame($config, $options->getConfigGlobPaths());
  80. }
  81. public function testSetConfigGlobPathsThrowsInvalidArgumentException()
  82. {
  83. $this->setExpectedException('InvalidArgumentException');
  84. $options = new ListenerOptions;
  85. $options->setConfigGlobPaths('asd');
  86. }
  87. }