Skip to content

Commit

Permalink
Merge 0bda174 into 72bae6d
Browse files Browse the repository at this point in the history
  • Loading branch information
alias-mac committed Feb 3, 2014
2 parents 72bae6d + 0bda174 commit fb7a00c
Show file tree
Hide file tree
Showing 35 changed files with 280 additions and 143 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
}
],
"autoload": {
"psr-0": {
"Insulin": "src/",
"Sugar": "src/"
"psr-4": {
"Insulin\\": "src/",
"Insulin\\Sugar\\": "src/"
}
},
"require": {
Expand Down
137 changes: 68 additions & 69 deletions composer.lock

Large diffs are not rendered by default.

28 changes: 14 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false"
strict = "true"
syntaxCheck = "false"
bootstrap = "autoload.php">
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
strict="true"
syntaxCheck="false"
bootstrap="autoload.php">

<testsuites>
<testsuite name="Insulin Test Suite">
<directory>src/*/*/Tests</directory>
<directory>src/*/Tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src</directory>
<exclude>
<directory>src/*/*/Resources</directory>
<directory>src/*/*/Tests</directory>
<directory>src/*/Resources</directory>
<directory>src/*/Tests</directory>
</exclude>
</whitelist>
</filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ public function doRun(InputInterface $input, OutputInterface $output)
$this->registerCommands();

if (true === $input->hasParameterOption(array('--shell', '-s'))) {
// @codeCoverageIgnoreStart
$shell = new Shell($this);
$shell->setProcessIsolation($input->hasParameterOption(array('--process-isolation')));
$shell->run();

return 0;
// @codeCoverageIgnoreEnd
}

$result = parent::doRun($input, $output);
Expand Down Expand Up @@ -192,15 +194,6 @@ protected function registerCommands()

$searchPath = array_filter($searchPath, 'is_dir');

if (empty($searchPath)) {
throw new \RuntimeException(
sprintf(
'No search path for commands available for run level "%s".',
$this->kernel->getBootedLevel()
)
);
}

$finder = new Finder();
$finder->files()->name('*Command.php')->in($searchPath);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
40 changes: 17 additions & 23 deletions src/Insulin/Console/Kernel.php → src/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,6 @@ public function getContainer()
return $this->container;
}

/**
* Used internally.
*/
public function setClassCache(array $classes)
{
file_put_contents(
$this->getCacheDir() . '/classes.map',
sprintf('<?php return %s;', var_export($classes, true))
);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -469,12 +458,8 @@ protected function initializeContainer()
$fresh = true;
if (!$cache->isFresh()) {
$container = $this->buildContainer();
$this->dumpContainer(
$cache,
$container,
$class,
$this->getContainerBaseClass()
);
$container->compile();
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());

$fresh = false;
}
Expand Down Expand Up @@ -575,7 +560,6 @@ protected function buildContainer()
$container = $this->getContainerBuilder();

$container->addObjectResource($this);
$container->compile();

return $container;
}
Expand Down Expand Up @@ -632,27 +616,37 @@ protected function dumpContainer(
* @return string
* The PHP string with the comments removed.
*/
protected static function stripComments($source)
public static function stripComments($source)
{
if (!function_exists('token_get_all')) {
return $source;
}

$rawChunk = '';
$output = '';
foreach (token_get_all($source) as $token) {
$tokens = token_get_all($source);
for (reset($tokens); false !== $token = current($tokens); next($tokens)) {
if (is_string($token)) {
$output .= $token;
$rawChunk .= $token;
} elseif (T_START_HEREDOC === $token[0]) {
$output .= preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $rawChunk).$token[1];
do {
$token = next($tokens);
$output .= $token[1];
} while ($token[0] !== T_END_HEREDOC);
$rawChunk = '';
} elseif (!in_array($token[0], array(T_COMMENT, T_DOC_COMMENT))) {
$output .= $token[1];
$rawChunk .= $token[1];
}
}

// replace multiple new lines with a single newline
$output = preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $output);
$output .= preg_replace(array('/\s+$/Sm', '/\n+/S'), "\n", $rawChunk);

return $output;
}


/**
* Provide a way to serialize a kernel. Currently save the debug status.
*
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions src/Insulin/Console/Shell.php → src/Console/Shell.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* An Insulin Shell wraps an Application to add shell capabilities to it.
*
* This extends from Symfony's Shell default abilities.
*
* @codeCoverageIgnore because we are only applying the logo in the header.
*/
class Shell extends BaseShell
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,47 @@ public function testCoreCommandsAvailableWithBootSugarConfiguration()
$this->assertRegExp('/sugar:version/', $insulinTester->getDisplay());
}

/**
* Confirm that all the core commands with bootstrap level
* `BOOT_SUGAR_ROOT` will be available by default.
*/
public function testDebugOutput()
{
$kernel = $this->getKernel(Kernel::BOOT_INSULIN, null, true);

$insulin = new Application($kernel);
$insulin->setAutoExit(false);

$insulinTester = new ApplicationTester($insulin);
$insulinTester->run(array('command' => 'list'));

$this->assertRegExp('/Memory usage: (.*)MB \(peak: (.*)MB\), time: (.*)s/', $insulinTester->getDisplay());
}

/**
* Gets a mock kernel to test the Insulin Application.
*
* @param $level
* @param integer $level
* The level of the boot reached.
* @param array $methods
* Additional methods to mock (besides the required to boot to the given
* level).
* @param boolean $debug
* Set it to `true` to run the Kernel in debug mode.
*
* @return \Insulin\Console\KernelInterface
*/
private function getKernel($level)
private function getKernel($level, $methods = array(), $debug = false)
{
$kernel = $this->getMock(
'Insulin\Console\Kernel',
array('getBootedLevel', 'getRootDir')
);
$mockMethods = array('getBootedLevel', 'getRootDir');
if (!empty($methods)) {
$mockMethods = array_merge($mockMethods, $methods);
}
$kernel = $this->getMockBuilder('Insulin\Console\Kernel')
->setMethods($mockMethods)
->setConstructorArgs(array($debug))
->getMock();

$kernel->expects($this->any())->method('getBootedLevel')->will(
$this->returnValue($level)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function testPerformanceBoot()
array('getBootstrapLevels', 'bootTo')
);
$kernel->expects($this->once())->method('getBootstrapLevels')->will(
$this->returnValue(array('1'))
$this->returnValue(array(1))
);

/* @var $kernel \Insulin\Console\KernelInterface */
Expand All @@ -93,10 +93,10 @@ public function testPerformanceBoot()
*/
public function testBootFailure()
{
$kernel = $this->getMock(
'Insulin\Console\Kernel',
array('getBootstrapLevels', 'bootTo')
);
$kernel = $this->getMockBuilder('Insulin\Console\Kernel')
->setMethods(array('getBootstrapLevels', 'bootTo'))
->setConstructorArgs(array(true))
->getMock();

$kernel->expects($this->once())->method('getBootstrapLevels')->will(
$this->returnValue(array(1))
Expand Down Expand Up @@ -125,4 +125,126 @@ public function testShutdownsWhenBooted()
$kernel->shutdown();
$this->assertNull($kernel->getContainer());
}

/**
* Confirm that we can't shutdown the Kernel if there is no valid boot.
*/
public function testShutdownsWhenNotBooted()
{
$kernel = $this->getMock(
'Insulin\Console\Kernel',
array('isBooted')
);
$kernel->expects($this->once())->method('isBooted')->will(
$this->returnValue(false)
);

/* @var $kernel \Insulin\Console\Kernel */
$kernel->shutdown();
}

/**
* Confirm that we can get the booted level if kernel is booted.
*/
public function testGetBootedLevel()
{
$kernel = $this->getMock(
'Insulin\Console\Kernel',
array('getBootstrapLevels', 'bootTo')
);

$kernel->expects($this->once())->method('getBootstrapLevels')->will(
$this->returnValue(array(1, 2))
);

$kernel->boot();
$this->assertEquals(2, $kernel->getBootedLevel());

}

/**
* Confirm that we comments are striped from PHP files correctly.
*/
public function testStripComments()
{
if (!function_exists('token_get_all')) {
$this->markTestSkipped('The function token_get_all() is not available.');

return;
}
$source = <<<'EOF'
<?php
$string = 'string should not be modified';
$heredoc = <<<HD
Heredoc should not be modified
HD;
$nowdoc = <<<'ND'
Nowdoc should not be modified
ND;
/**
* some class comments to strip
*/
class TestClass
{
/**
* some method comments to strip
*/
public function doStuff()
{
// inline comment
}
}
EOF;
$expected = <<<'EOF'
<?php
$string = 'string should not be modified';
$heredoc =
<<<HD
Heredoc should not be modified
HD;
$nowdoc =
<<<'ND'
Nowdoc should not be modified
ND;
class TestClass
{
public function doStuff()
{
}
}
EOF;

$output = Kernel::stripComments($source);

// Heredocs are preserved, making the output mixing unix and windows line
// endings, switching to "\n" everywhere on windows to avoid failure.
if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
$expected = str_replace("\r\n", "\n", $expected);
$output = str_replace("\r\n", "\n", $output);
}

$this->assertEquals($expected, $output);
}

}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit fb7a00c

Please sign in to comment.