示例#1
0
<?php

use Siphon\Config\Repository;
describe("Config Repository", function () {
    before(function () {
        $this->config = ['database' => ['connection' => 'mysql', 'mysql' => ['host' => 'localhost', 'database' => 'db', 'user' => 'mike', 'password' => 'password']], 'foo' => 'bar'];
    });
    describe("->has()", function () {
        it("determines if the config value exists", function () {
            $config = new Repository($this->config);
            expect($config->has('database'))->toBe(true);
            expect($config->has('database.connection'))->toBe(true);
            expect($config->has('nothing'))->toBe(false);
        });
    });
    describe("->set()", function () {
        it("sets values on the config array", function () {
            $config = new Repository($this->config);
            $config->set('a', ['b', 'c']);
            $config->set('d.e', 'f');
            $config->set('z.y.x', ['w', 'u']);
            $array = $config->all();
            expect($array['a'])->toBe(['b', 'c']);
            expect($array['d']['e'])->toBe('f');
            expect($array['z']['y']['x'])->toBe(['w', 'u']);
        });
        it("overwrites the config array if the key is null", function () {
            $config = new Repository($this->config);
            $config->set(null, ['foo', 'bar']);
            $array = $config->all();
            expect($array)->toBe(['foo', 'bar']);