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

Language PHP Lines 96
MD5 Hash 32d92e2385adc3a44081d4616c270b34 Estimated Cost $1,830 (why?)
Repository https://bitbucket.org/pcelta/zf2.git View Raw File View Project SPDX
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 * @package   Zend_ModuleManager
 */

namespace ZendTest\ModuleManager\Listener;

use InvalidArgumentException;
use PHPUnit_Framework_TestCase as TestCase;
use Zend\Config\Config;
use Zend\ModuleManager\Listener\ListenerOptions;

class ListenerOptionsTest extends TestCase
{
    public function testCanConfigureWithArrayInConstructor()
    {
        $options = new ListenerOptions(array(
            'cache_dir'               => __DIR__,
            'config_cache_enabled'    => true,
            'config_cache_key'        => 'foo',
            'module_paths'            => array('module','paths'),
            'config_glob_paths'       => array('glob','paths'),
            'config_static_paths'       => array('static','custom_paths'),
        ));
        $this->assertSame($options->getCacheDir(), __DIR__);
        $this->assertTrue($options->getConfigCacheEnabled());
        $this->assertNotNull(strstr($options->getConfigCacheFile(), __DIR__));
        $this->assertNotNull(strstr($options->getConfigCacheFile(), '.php'));
        $this->assertSame('foo', $options->getConfigCacheKey());
        $this->assertSame(array('module', 'paths'), $options->getModulePaths());
        $this->assertSame(array('glob', 'paths'), $options->getConfigGlobPaths());
        $this->assertSame(array('static', 'custom_paths'), $options->getConfigStaticPaths());
    }

    public function testCanAccessKeysAsProperties()
    {
        $options = new ListenerOptions(array(
            'cache_dir'               => __DIR__,
            'config_cache_enabled'    => true,
            'config_cache_key'        => 'foo',
            'module_paths'            => array('module','paths'),
            'config_glob_paths'       => array('glob','paths'),
            'config_static_paths'       => array('static','custom_paths'),
        ));
        $this->assertSame($options->cache_dir, __DIR__);
        $options->cache_dir = 'foo';
        $this->assertSame($options->cache_dir, 'foo');
        $this->assertTrue(isset($options->cache_dir));
        unset($options->cache_dir);
        $this->assertFalse(isset($options->cache_dir));

        $this->assertTrue($options->config_cache_enabled);
        $options->config_cache_enabled = false;
        $this->assertFalse($options->config_cache_enabled);
        $this->assertEquals('foo', $options->config_cache_key);
        $this->assertSame(array('module', 'paths'), $options->module_paths);
        $this->assertSame(array('glob', 'paths'), $options->config_glob_paths);
        $this->assertSame(array('static', 'custom_paths'), $options->config_static_paths);
    }

    public function testSetModulePathsAcceptsConfigOrTraverable()
    {
        $config = new Config(array(__DIR__));
        $options = new ListenerOptions;
        $options->setModulePaths($config);
        $this->assertSame($config, $options->getModulePaths());
    }

    public function testSetModulePathsThrowsInvalidArgumentException()
    {
        $this->setExpectedException('InvalidArgumentException');
        $options = new ListenerOptions;
        $options->setModulePaths('asd');
    }

    public function testSetConfigGlobPathsAcceptsConfigOrTraverable()
    {
        $config = new Config(array(__DIR__));
        $options = new ListenerOptions;
        $options->setConfigGlobPaths($config);
        $this->assertSame($config, $options->getConfigGlobPaths());
    }

    public function testSetConfigGlobPathsThrowsInvalidArgumentException()
    {
        $this->setExpectedException('InvalidArgumentException');
        $options = new ListenerOptions;
        $options->setConfigGlobPaths('asd');
    }
}
Back to Top