dimanche 26 juin 2016

Proper require unit test

I have been writing a unit test for an app and wanted to test a method which has require. The way I see it

public $configPath = __DIR__.'/path/to/config.php';

private function getConfig()
{
    if (!empty($this->config)) {
        return $this->config;
    }

    return $this->config = require $this->configPath;
}

public method foo()
{
    $config = $this->getConfig(); 
    //logic here
}

In the test case, the respective snippet is

$class->config = ['bar' => 'baz'];

$class->foo();

I am wondering if this could be considered as the proper way or other technique/solution should be used?

Aucun commentaire:

Enregistrer un commentaire