Skip to content

Commit

Permalink
Merge branch 'master' into support/2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorbrandao committed Feb 7, 2016
2 parents 67b526d + dd3792b commit f2388cc
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 62 deletions.
58 changes: 6 additions & 52 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
* @link http://www.ppi.io
*/

namespace PPI\Framework;

use PPI\Framework\Config\ConfigManager;
Expand Down Expand Up @@ -140,53 +141,6 @@ public function __construct(array $options = array())
}
}

/**
* Set an App option.
*
* @param $option
* @param $value
*
* @throws \RuntimeException
*
* @return $this
*/
public function setOption($option, $value)
{
if (true === $this->booted) {
throw new \RuntimeException('Setting App options after boot() is now allowed');
}

// "root_dir" to "rootDir"
$property = preg_replace('/_(.?)/e', "strtoupper('$1')", $option);
if (!property_exists($this, $property)) {
throw new \RuntimeException(sprintf('App property "%s" (option "%s") does not exist', $property, $option));
}

$this->$property = $value;

return $this;
}

/**
* Get an App option.
*
* @param $option
*
* @throws \RuntimeException
*
* @return string
*/
public function getOption($option)
{
// "root_dir" to "rootDir"
$property = preg_replace('/_(.?)/e', "strtoupper('$1')", $option);
if (!property_exists($this, $property)) {
throw new \RuntimeException(sprintf('App property "%s" (option "%s") does not exist', $property, $option));
}

return $property;
}

public function __clone()
{
if ($this->debug) {
Expand Down Expand Up @@ -389,7 +343,7 @@ public function isDebug()
public function getRootDir()
{
if (null === $this->rootDir) {
$this->rootDir = realpath(getcwd().'/app');
$this->rootDir = realpath(getcwd() . '/app');
}

return $this->rootDir;
Expand Down Expand Up @@ -478,7 +432,7 @@ public function getStartTime()
*/
public function getCacheDir()
{
return $this->rootDir.'/cache/'.$this->environment;
return $this->rootDir . '/cache/' . $this->environment;
}

/**
Expand All @@ -490,7 +444,7 @@ public function getCacheDir()
*/
public function getLogDir()
{
return $this->rootDir.'/logs';
return $this->rootDir . '/logs';
}

/**
Expand All @@ -513,8 +467,8 @@ public function getCharset()
public function getConfigManager()
{
if (null === $this->configManager) {
$cachePath = $this->getCacheDir().'/application-config-cache.'.$this->getName().'.php';
$this->configManager = new ConfigManager($cachePath, !$this->debug, $this->rootDir.'/config');
$cachePath = $this->getCacheDir() . '/application-config-cache.' . $this->getName() . '.php';
$this->configManager = new ConfigManager($cachePath, !$this->debug, $this->rootDir . '/config');
}

return $this->configManager;
Expand Down
17 changes: 7 additions & 10 deletions tests/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
*/
class AppTest extends \PHPUnit_Framework_TestCase
{

private $contollerUnderTest;

public function setUp()
Expand All @@ -41,7 +40,7 @@ public function testConstructor()
$debug = true;
$rootDir = __DIR__;
$name = 'testName';
$app = new AppForTest(array('environment' => $env, 'debug' => $debug, 'rootDir' => $rootDir, 'name' => $name,));
$app = new AppForTest(array('environment' => $env, 'debug' => $debug, 'rootDir' => $rootDir, 'name' => $name));

$this->assertEquals($env, $app->getEnvironment());
$this->assertEquals($debug, $app->isDebug());
Expand Down Expand Up @@ -70,7 +69,7 @@ public function testClone()

public function testGetRootDir()
{
$app = new AppForTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__,));
$app = new AppForTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__));

$this->assertEquals(__DIR__, realpath($app->getRootDir()));

Expand All @@ -81,16 +80,16 @@ public function testGetRootDir()

public function testGetName()
{
$app = new AppForTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__,));
$app = new AppForTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__));
$this->assertEquals(basename(__DIR__), $app->getName());

$app = new AppForTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__, 'name' => 'testName',));
$app = new AppForTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__, 'name' => 'testName'));
$this->assertEquals('testName', $app->getName());
}

public function testRunWithControllerIndexAction()
{
$app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__,));
$app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__));

$this->controllerUnderTest = [new ControllerForAppTest(), 'indexAction'];

Expand All @@ -105,7 +104,7 @@ public function testRunWithControllerIndexAction()

public function testRunWithControllerInvokeAction()
{
$app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__,));
$app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__));

$this->controllerUnderTest = new ControllerForAppTest();

Expand All @@ -120,7 +119,7 @@ public function testRunWithControllerInvokeAction()

public function testDispatch()
{
$app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__,));
$app = new AppForDispatchTest(array('environment' => 'test', 'debug' => true, 'rootDir' => __DIR__));

$this->controllerUnderTest = [new ControllerForAppTest(), 'indexAction'];

Expand All @@ -145,7 +144,6 @@ private function setupMockRouter()

public function setupMockControllerResolver()
{

$mockControllerResolver = $this->getMockBuilder('PPI\Framework\Module\Controller\ControllerResolver')->disableOriginalConstructor()->getMock();

$mockControllerResolver->expects($this->once())->method('getController')->willReturn(
Expand Down Expand Up @@ -178,5 +176,4 @@ private function runApp($app, $request, $response)

return $output;
}

}

0 comments on commit f2388cc

Please sign in to comment.