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

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

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