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
Make into vendormodule #91
Make into vendormodule #91
Conversation
663a568
to
cb9d5c0
Compare
_config.php
Outdated
if (!defined('DEBUGBAR_DIR')) { | ||
define('DEBUGBAR_DIR', 'debugbar'); | ||
if (!Environment::getEnv('DEBUGBAR_DIR')) { | ||
Environment::setEnv('DEBUGBAR_DIR', 'resources/lekoala/silverstripe-debugbar'); |
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.
I think that this can be done more nicely with the resource locator...
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.
Rather than setting an env var I'd be using the resource locator in all the place you need the path
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 could be a fun afternoon...
4f4cd47
to
ed9248e
Compare
Well, tests to fix, but that's the general idea. |
7f8b7bc
to
de2d2b2
Compare
1b309d7
to
03ffdfa
Compare
Requires silverstripe/vendor-plugin#10 to fix the tests, cos ModuleLoader is awkward |
code/Collector/ConfigCollector.php
Outdated
@@ -53,8 +54,8 @@ public function getAssets() | |||
$name = $this->getName(); | |||
|
|||
return [ | |||
'base_path' => '/' . DEBUGBAR_DIR . '/javascript', | |||
'base_url' => DEBUGBAR_DIR . '/javascript', | |||
'base_path' => '/' . Director::makeRelative(ModuleLoader::getModule('lekoala/silverstripe-debugbar')->getResource('javascript')->getURL()), |
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.
Please use $resource->getRelativePath()
instead of Director::makeRelative($resource->getURL())
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.
I was having enormous trouble getting that to work as my dev environment lives on a sub-url, i.e.
http://dev/stabless4
- and I could never get the right path. This is the only one that worked. I will try again tomorrow but I want getRelativeURL()
and there wasn't an option :)
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.
Yes, but url isn't a path... you could have a resource that lives locally, but is served via a CDN, in which case there won't be any relation between the url and the path at all.
@@ -172,8 +171,8 @@ public function testGetWidgets() | |||
public function testGetAssets() | |||
{ | |||
$expected = array( | |||
'base_path' => '/debugbar/javascript', | |||
'base_url' => 'debugbar/javascript', | |||
'base_path' => '/resources/lekoala/silverstripe-debugbar/javascript', |
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.
Don't hard-code this assumption; Use the resources API.
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.
A better test isn't an explicit hard-coded array result; It's that the path physically exists, and that the URL Is accessible.
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.
I agree - I think I should move away from relying on the module being in a particular place.
Travis testing is a nightmare with this though - because it runs the composer install
from inside the module, it means all the resources are in the wrong places. Will have a play again tomorrow - and see if I can figure out a standard for testing with modules that expose resources.
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.
I agree and disagree - a known input should result in a known output for a test. whilst we don't want to tightly couple our tests to these exact values, these assumptions should still hold...
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.
"installed in vendor or in root" isn't a known input it's a variable, and it shouldn't matter which it is.
$config = $this->collector->getAssets();
$this->assertDirectoryExists(BASE_PATH . '/' . $config['base_path]);
Otherwise, test for either of the two possible valid locations.
code/DebugBar.php
Outdated
@@ -234,8 +235,8 @@ public static function includeRequirements() | |||
$renderer = $debugbar->getJavascriptRenderer(); | |||
|
|||
// We don't need the true path since we are going to use Requirements API that appends the BASE_PATH | |||
$renderer->setBasePath(DEBUGBAR_DIR . '/assets'); | |||
$renderer->setBaseUrl(DEBUGBAR_DIR . '/assets'); | |||
$renderer->setBasePath(Director::makeRelative(ModuleLoader::getModule('lekoala/silverstripe-debugbar')->getResource('assets')->getURL())); |
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.
As above, use getPath() / getRelativePath() for a path, don't try to infer from getURL().
silverstripe/vendor-plugin#10 isn't the problem, I've commented to that effect on that PR. @andrewandante do you want to chat offline about these changes? Maybe I can help you with the API issues. |
code/Collector/DatabaseCollector.php
Outdated
@@ -173,8 +173,8 @@ public function getWidgets() | |||
public function getAssets() | |||
{ | |||
return array( | |||
'base_path' => '/' . DEBUGBAR_DIR . '/javascript', | |||
'base_url' => DEBUGBAR_DIR.'/javascript', | |||
'base_path' => '/' . Director::makeRelative(ModuleLoader::getModule('lekoala/silverstripe-debugbar')->getResource('javascript')->getURL()), |
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.
Do you think you could consolidate this repeated config into a DebugBarConfig or something?
17caf83
to
b210c64
Compare
|
||
class DatabaseCollectorTest extends SapphireTest | ||
class DatabaseCollectorTest extends FunctionalTest |
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.
Why do we need to use FunctionalTest
now?
|
||
class SilverStripeCollectorTest extends SapphireTest | ||
class SilverStripeCollectorTest extends FunctionalTest |
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.
Why do we need to use FunctionalTest
now?
@@ -26,6 +27,12 @@ public function setUp() | |||
parent::setUp(); | |||
DebugBar::initDebugBar(); | |||
$this->collector = DebugBar::getDebugBar()->getCollector('silverstripe'); | |||
Requirements::set_backend(Requirements_Backend::create()); |
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 looks like a regression in 4.0 - would you mind PR-ing to core to re-add this via a test state class or maybe adding to the sapphireteststate
class?
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.
Turns out it's not actually required - I think caching had something to do with it. Have removed, hopefully Travis still likes me
Requirements::set_backend(Requirements_Backend::create()); | ||
} | ||
|
||
public function tearDown() |
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 stub isn't needed
@@ -167,16 +180,18 @@ public function testGetWidgets() | |||
); | |||
|
|||
$this->assertSame($expected, $result); | |||
$this->logOut(); |
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.
tearDown
should be doing logouts, so this shouldn't be needed
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.
Only in the setUp()
method of FunctionalTest
- so as I will set them back to SapphireTest
I'll leave this in there
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.
ok
b210c64
to
a131941
Compare
fix the tests
a131941
to
8968a74
Compare
ping @tractorcow |
For tidyness