Skip to content

Commit

Permalink
Merge pull request #14986 from phalcon/fix/config-factory-load
Browse files Browse the repository at this point in the history
Fixed incorrect return type hints for ConfigFactory
  • Loading branch information
sergeyklay authored May 2, 2020
2 parents 0ed7e37 + 963f4ca commit 3049c86
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Fixed default value of the following `Phalcon\Annotations\Annotation`'s properties: `$arguments` and `$exprArguments` [#14977](https://github.com/phalcon/cphalcon/issues/14977)
- Fixed return type hints of the following `Phalcon\Annotations\Annotation`'s methods: `getArgument`, `getName` and `getNamedArgument` [#14977](https://github.com/phalcon/cphalcon/issues/14977)
- Fixed incorrect return type hint for `Phalcon\Http\Response\Cookies::setSignKey` [#14982](https://github.com/phalcon/cphalcon/issues/14982)
- Fixed return type hints for `Phalcon\Config\ConfigFactory::load` and `Phalcon\Config\ConfigFactory::newInstance` to explicitly indicate the return type as `Phalcon\Config` instance [#14978](https://github.com/phalcon/cphalcon/issues/14978)

# [4.0.5](https://github.com/phalcon/cphalcon/releases/tag/v4.0.5) (2020-03-07)
## Added
Expand Down
14 changes: 4 additions & 10 deletions phalcon/Config/ConfigFactory.zep
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,14 @@
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Phalcon\Config;

use Phalcon\Config;
use Phalcon\Config\Adapter\Grouped;
use Phalcon\Config\Adapter\Ini;
use Phalcon\Config\Adapter\Json;
use Phalcon\Config\Adapter\Php;
use Phalcon\Config\Adapter\Yaml;
use Phalcon\Factory\AbstractFactory;
use Phalcon\Factory\Exception as FactoryException;
use Phalcon\Helper\Arr;

/**
Expand Down Expand Up @@ -55,7 +49,7 @@ class ConfigFactory extends AbstractFactory
* 'callbacks' => null
* ]
*/
public function load(config) -> object
public function load(config) -> <Config>
{
var adapter, extension, first, oldConfig, second;

Expand Down Expand Up @@ -117,7 +111,7 @@ class ConfigFactory extends AbstractFactory
/**
* Returns a new Config instance
*/
public function newInstance(string name, string fileName, var params = null) -> object
public function newInstance(string name, string fileName, var params = null) -> <Config>
{
var definition, options;

Expand Down
13 changes: 9 additions & 4 deletions tests/_data/fixtures/Traits/FactoryTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

declare(strict_types=1);
Expand All @@ -15,6 +15,7 @@

use Phalcon\Config;
use Phalcon\Config\Adapter\Ini;

use function dataDir;
use function outputDir;

Expand All @@ -35,8 +36,10 @@ trait FactoryTrait

/**
* Initializes the main config
*
* @return void
*/
protected function init()
protected function init(): void
{
$configFile = dataDir('assets/config/factory.ini');

Expand All @@ -47,8 +50,10 @@ protected function init()

/**
* Initializes the logger config - this is special because it is nested
*
* @return void
*/
protected function initLogger()
protected function initLogger(): void
{
$options = [
'logger' => [
Expand Down
32 changes: 25 additions & 7 deletions tests/unit/Config/ConfigFactory/LoadCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

declare(strict_types=1);
Expand All @@ -29,22 +29,30 @@ class LoadCest
{
use FactoryTrait;

public function _before(UnitTester $I)
/**
* Executed before each test
*
* @param UnitTester $I
* @return void
*/
public function _before(UnitTester $I): void
{
$this->init();
}

/**
* Tests Phalcon\Config\ConfigFactory :: load() - Config
*
* @param UnitTester $I
*
* @author Wojciech Ślawski <[email protected]>
* @since 2017-03-02
*/
public function configFactoryLoadConfig(UnitTester $I)
{
$I->wantToTest('Config\ConfigFactory - load() - Config');

$options = $this->config->config;
$options = $this->config->get('config');

/** @var Ini $ini */
$ini = (new ConfigFactory())->load($options);
Expand All @@ -63,7 +71,7 @@ public function configFactoryLoadConfig(UnitTester $I)
);

/** @var Ini $ini */
$ini = (new ConfigFactory())->load($ini->config->toArray());
$ini = (new ConfigFactory())->load($ini->get('config')->toArray());

$I->assertInstanceOf(
Ini::class,
Expand All @@ -74,6 +82,8 @@ public function configFactoryLoadConfig(UnitTester $I)
/**
* Tests Phalcon\Config\ConfigFactory :: load() - array
*
* @param UnitTester $I
*
* @author Wojciech Ślawski <[email protected]>
* @since 2017-03-02
*/
Expand All @@ -95,6 +105,8 @@ public function configFactoryLoadArray(UnitTester $I)
/**
* Tests Phalcon\Config\ConfigFactory :: load() - string
*
* @param UnitTester $I
*
* @author Wojciech Ślawski <[email protected]>
* @since 2017-11-24
*/
Expand All @@ -116,6 +128,8 @@ public function configFactoryLoadString(UnitTester $I)
/**
* Tests Phalcon\Config\ConfigFactory :: load() - exception
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-06-19
*/
Expand Down Expand Up @@ -169,6 +183,8 @@ function () {
/**
* Tests Phalcon\Config\ConfigFactory :: load() - yaml callback
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-06-19
*/
Expand Down Expand Up @@ -198,6 +214,8 @@ public function configFactoryLoadYamlCallback(UnitTester $I)
/**
* Tests Phalcon\Config\ConfigFactory :: load() - two calls new instances
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-12-07
* @issue 14584
Expand All @@ -211,11 +229,11 @@ public function configFactoryLoadTwoCallsNewInstances(UnitTester $I)
$configFile1 = dataDir('assets/config/config.php');
$config = $factory->load($configFile1);

$I->assertEquals("/phalcon/", $config->phalcon->baseUri);
$I->assertEquals("/phalcon/", $config->get('phalcon')->baseUri);

$configFile2 = dataDir('assets/config/config-2.php');
$config2 = $factory->load($configFile2);

$I->assertEquals("/phalcon4/", $config2->phalcon->baseUri);
$I->assertEquals("/phalcon4/", $config2->get('phalcon')->baseUri);
}
}
6 changes: 4 additions & 2 deletions tests/unit/Config/ConfigFactory/NewInstanceCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
*
* (c) Phalcon Team <[email protected]>
*
* For the full copyright and license information, please view the LICENSE.txt
* file that was distributed with this source code.
* For the full copyright and license information, please view the
* LICENSE.txt file that was distributed with this source code.
*/

declare(strict_types=1);
Expand All @@ -27,6 +27,8 @@ class NewInstanceCest
/**
* Tests Phalcon\Logger\LoggerFactory :: newInstance()
*
* @param UnitTester $I
*
* @author Phalcon Team <[email protected]>
* @since 2019-05-03
*/
Expand Down

0 comments on commit 3049c86

Please sign in to comment.