示例#1
0
        });
    });
    describe("->get()", function () {
        it("returns a value from the array", function () {
            $config = new Repository($this->config);
            expect($config->get('database'))->toBe($this->config['database']);
        });
        it("returns the value of a multi dimensional array using dot notation", function () {
            $config = new Repository($this->config);
            expect($config->get('database.mysql'))->toBe($this->config['database']['mysql']);
            expect($config->get('database.mysql.host'))->toBe($this->config['database']['mysql']['host']);
        });
    });
    describe("->all()", function () {
        it("returns the full config array", function () {
            $config = new Repository($this->config);
            expect($config->all())->toBe($this->config);
        });
    });
    describe("array access config repository", function () {
        it("accesses config values using ArrayAccess", function () {
            $config = new Repository($this->config);
            unset($config['foo']);
            $config['name'] = 'Mike';
            expect($config['database'])->toBe($this->config['database']);
            expect($config['name'])->toBe('Mike');
            expect(isset($config['database']))->toBe(true);
            expect($config['foo'])->toBeNull();
        });
    });
});
示例#2
0
            expect($config->get('database'))->toBe($array);
        });
        it("loads an array of configuration files", function () {
            $config = new Repository();
            $loader = new Loader($config, new Factory());
            $database = (require __DIR__ . '/config/database.php');
            $view = (require __DIR__ . '/config/view.php');
            $loader->loadFiles([__DIR__ . '/config/database.php', __DIR__ . '/config/view.php']);
            expect($config->get('database'))->toBe($database);
            expect($config->get('view'))->toBe($view);
        });
        it("throws a RuntimeException if the file type is not php", function () {
            $closure = function () {
                $loader = new Loader(new Repository(), new Factory());
                $loader->loadFiles(__DIR__ . '/config/invalid.ini');
            };
            expect($closure)->toThrow(new RuntimeException());
        });
    });
    describe("->load()", function () {
        it("loads all config files from a directory", function () {
            $config = new Repository();
            $loader = new Loader($config, new Factory());
            $database = (require __DIR__ . '/config/database.php');
            $view = (require __DIR__ . '/config/view.php');
            $loader->load(__DIR__ . '/config');
            expect($config->get('database'))->toBe($database);
            expect($config->get('view'))->toBe($view);
        });
    });
});