2017 © Pedro Peláez
 

library l4-config-mock

Extremely simple mock config class for testing L4 packages.

image

anlutro/l4-config-mock

Extremely simple mock config class for testing L4 packages.

  • Wednesday, August 21, 2013
  • by anlutro
  • Repository
  • 1 Watchers
  • 0 Stars
  • 135 Installations
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Laravel 4 Config Mock

Extremely simple class for mocking Laravel's config abilities., (*1)

Meant for use in developing and testing packages. Set the items on the config instance, and inject it into your class(es)., (*2)

Example

Here's a simple example showing how you can create a library you want to use (how you use it is not included in the example), how to implement it in a service provider and how to write a test for it where you can load your package's config file and set any config values you need to test your class., (*3)

class MyClass
{
    public function setConfig($config)
    {
        $this->config = $config;
    }

    public function hello()
    {
        return $this->config->get('myvendor/mypackage::hello');
    }
}

class MyClassServiceProvider
{
    protected $defer = true;

    public function register()
    {
        $this->app['myclass'] = $this->app->share(function($app) {
            $myclass = new MyClass;
            $myClass->setConfig($app['config']);
        });
    }
}

class MyClassTest extends PHPUnit_Framework_TestCase
{
    public function testHello()
    {
        $config = new anlutro\L4MockConfig\MockConfig;
        // our config file which includes 'hello' => 'my-hello'
        $config->load('/path/to/package/config.php', 'myvendor/mypackage');

        $obj = new MyClass;
        $obj->setConfig($config);

        $this->assertEquals('my-hello', $obj->hello());

        $this->config->set('myvendor/mypackage::hello', 'second-hello');
        $this->assertEquals('second-hello', $obj->hello());
    }
}

The Versions

21/08 2013

dev-master

9999999-dev

Extremely simple mock config class for testing L4 packages.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Andreas Lutro