Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#6] Test passing PHP config files to Factory
Browse files Browse the repository at this point in the history
- Tested both using the Factory to get individual PHP files, as well as
  including PHP files in a mixed strategy
- Made factory Abstract to prevent instantiation
  • Loading branch information
weierophinney committed Mar 1, 2012
1 parent e07cb7b commit f3ba45e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Factory.php
Expand Up @@ -21,12 +21,14 @@
namespace Zend\Config;

/**
* Declared abstract to prevent instantiation
*
* @category Zend
* @package Zend_Config
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class Factory
abstract class Factory
{
/**
* Readers used for config files.
Expand Down
18 changes: 16 additions & 2 deletions test/FactoryTest.php
Expand Up @@ -74,16 +74,30 @@ public function testFromXmlFiles()
$this->assertEquals('baz', $config['test']['bar']);
}

public function testFromIniAndXmlFiles()
public function testFromPhpFiles()
{
$files = array (
__DIR__ . '/TestAssets/Php/include-base.php',
__DIR__ . '/TestAssets/Php/include-base2.php'
);

$config = Factory::fromFiles($files);
$this->assertEquals('bar', $config['base']['foo']);
$this->assertEquals('baz', $config['test']['bar']);
}

public function testFromIniAndXmlAndPhpFiles()
{
$files = array (
__DIR__ . '/TestAssets/Ini/include-base.ini',
__DIR__ . '/TestAssets/Xml/include-base2.xml'
__DIR__ . '/TestAssets/Xml/include-base2.xml',
__DIR__ . '/TestAssets/Php/include-base3.php',
);

$config = Factory::fromFiles($files);
$this->assertEquals('bar', $config['base']['foo']);
$this->assertEquals('baz', $config['test']['bar']);
$this->assertEquals('baz', $config['last']['bar']);
}

public function testNonExistentFileThrowsRuntimeException()
Expand Down
6 changes: 6 additions & 0 deletions test/TestAssets/Php/include-base.php
@@ -0,0 +1,6 @@
<?php
return array(
'test' => array(
'bar' => 'baz',
),
);
6 changes: 6 additions & 0 deletions test/TestAssets/Php/include-base2.php
@@ -0,0 +1,6 @@
<?php
return array(
'base' => array(
'foo' => 'bar',
),
);
6 changes: 6 additions & 0 deletions test/TestAssets/Php/include-base3.php
@@ -0,0 +1,6 @@
<?php
return array(
'last' => array(
'bar' => 'baz',
),
);

0 comments on commit f3ba45e

Please sign in to comment.