/** * Calling load() with a group that doesn't exist, should get it to use the last reader * to create a new config group * * @test * @covers Kohana_Config::load */ public function test_load_returns_new_config_group_if_one_dnx() { $config = new Kohana_Config(); $group = 'my_group'; $reader1 = $this->getMock('Kohana_Config_Reader'); $reader2 = $this->getMock('Kohana_Config_Reader', array('load'), array(), 'Kohana_Config_Waffles'); // This is a slightly hacky way of doing it, but it works $reader2->expects($this->exactly(2))->method('load')->with($group)->will($this->onConsecutiveCalls($this->returnValue(FALSE), $this->returnValue(clone $reader2))); $config->attach($reader1)->attach($reader2); $new_config = $config->load('my_group'); $this->assertInstanceOf('Kohana_Config_Waffles', $new_config); // Slightly taboo, testing a different api!! $this->assertSame(array(), $new_config->as_array()); }
/** * When we call copy() we expect it to copy the merged config to all writers * * @TODO This test sucks due to limitations in the phpunit mock generator. MAKE THIS AWESOME AGAIN! * @test * @covers Kohana_Config::copy */ public function test_copy_copies_merged_config_to_all_writers() { $config = new Kohana_Config(); $reader1 = $this->getMock('Kohana_Config_Reader', array('load')); $reader2 = $this->getMock('Kohana_Config_Reader', array('load')); $reader1->expects($this->once())->method('load')->with('something')->will($this->returnValue(array('pie' => 'good', 'kohana' => 'awesome'))); $reader2->expects($this->once())->method('load')->with('something')->will($this->returnValue(array('kohana' => 'good'))); $writer1 = $this->getMock('Kohana_Config_Writer', array('write')); $writer2 = $this->getMock('Kohana_Config_Writer', array('write')); // Due to crazy limitations in phpunit's mocking engine we have to be fairly // liberal here as to what order we receive the config items // Good news is that order shouldn't matter *yay* // // Now save your eyes and skip the next... 13 lines! $key = $this->logicalOr('pie', 'kohana'); $val = $this->logicalOr('good', 'awesome'); $writer1->expects($this->exactly(2))->method('write')->with('something', clone $key, clone $val); $writer2->expects($this->exactly(2))->method('write')->with('something', clone $key, clone $val); $config->attach($reader1)->attach($reader2, FALSE)->attach($writer1)->attach($writer2); // Now let's get this thing going! $config->copy('something'); }