-
-
Notifications
You must be signed in to change notification settings - Fork 810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.3.] Nut debug tweaks #6543
Merged
bobdenotter
merged 6 commits into
bolt:release/3.3
from
GwendolenLynch:hotfix/nut-debug-tweaks
Apr 6, 2017
Merged
[3.3.] Nut debug tweaks #6543
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2da347f
Rename DebugServiceRegistration to DebugServiceProviders
GwendolenLynch dca3f42
Add sorting options to DebugEvents
GwendolenLynch 173d852
Rename columns and sorting options in DebugRoutes
GwendolenLynch 2638674
Naming and phrasing updates
GwendolenLynch b79112f
Remove table headers
GwendolenLynch 7d4bb7a
[Tests] coverage for Nut debug:* commands
GwendolenLynch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
|
||
namespace Bolt\Nut; | ||
|
||
use Silex\Application; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Helper\TableStyle; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Nut command to dump system provider registration order. | ||
* | ||
* @author Gawain Lynch <gawain.lynch@gmail.com> | ||
*/ | ||
class DebugServiceProviders extends BaseCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('debug:service-providers') | ||
->setAliases(['debug:providers']) | ||
->setDescription('Dumps service providers and their order.') | ||
->addOption('sort-class', null, InputOption::VALUE_NONE, 'Sort by provider class names.') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$table = new Table($output); | ||
$rightAligned = new TableStyle(); | ||
$rightAligned->setPadType(STR_PAD_LEFT); | ||
|
||
$table->setHeaders([ | ||
['Provider Class Name', 'Order'] | ||
]); | ||
$table->setColumnStyle(1, $rightAligned); | ||
|
||
$reflect = new \ReflectionProperty(Application::class, 'providers'); | ||
$reflect->setAccessible(true); | ||
$registrations = $reflect->getValue($this->app); | ||
|
||
if ($input->getOption('sort-class')) { | ||
uasort($registrations, function ($a, $b) { | ||
$a = get_class($a); | ||
$b = get_class($b); | ||
if ($a === $b) { | ||
return 0; | ||
} | ||
|
||
return ($a < $b) ? -1 : 1; | ||
}); | ||
} | ||
|
||
foreach ($registrations as $index => $registration) { | ||
$table->addRow([get_class($registration), $index + 1]); | ||
} | ||
|
||
$table->render(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Bolt\Tests\Nut; | ||
|
||
use Bolt\Nut\DebugEvents; | ||
use Bolt\Tests\BoltUnitTest; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
/** | ||
* Test for \Bolt\Nut\DebugEvents | ||
* | ||
* @author Gawain Lynch <gawain.lynch@gmail.com> | ||
*/ | ||
class DebugEventsTest extends BoltUnitTest | ||
{ | ||
use TableHelperTrait; | ||
|
||
protected $regexExpectedA = '/(kernel\.request).+(Symfony.Component.HttpKernel.EventListener.RouterListener::onKernelRequest).+(32)/'; | ||
protected $regexExpectedB = '/(Bolt.Routing.Canonical::onRequest).+(31)/'; | ||
|
||
public function testRunNormal() | ||
{ | ||
$tester = $this->getCommandTester(); | ||
|
||
$tester->execute([]); | ||
$result = $tester->getDisplay(); | ||
|
||
$this->assertRegExp($this->regexExpectedA, $result); | ||
$this->assertRegExp($this->regexExpectedB, $result); | ||
} | ||
|
||
public function testSortListener() | ||
{ | ||
$tester = $this->getCommandTester(); | ||
|
||
$expectedOutput = $this->getNormalOuput(); | ||
$expectedA = $this->getMatchingLineNumber($this->regexExpectedA, $expectedOutput); | ||
$expectedB = $this->getMatchingLineNumber($this->regexExpectedB, $expectedOutput); | ||
$this->assertGreaterThan($expectedA, $expectedB); | ||
|
||
$tester->execute(['--sort-listener' => true]); | ||
$result = $tester->getDisplay(); | ||
|
||
$expectedA = $this->getMatchingLineNumber($this->regexExpectedA, $result); | ||
$expectedB = $this->getMatchingLineNumber($this->regexExpectedB, $result); | ||
$this->assertLessThan($expectedA, $expectedB); | ||
} | ||
|
||
/** | ||
* @return CommandTester | ||
*/ | ||
protected function getCommandTester() | ||
{ | ||
$app = $this->getApp(); | ||
$command = new DebugEvents($app); | ||
|
||
return new CommandTester($command); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I was saying it seems to make more sense to have a value here instead of an option for each sorting.
--sort name/path/method
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but was thinking of consistency with the others