Skip to content
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

Merged
merged 1 commit into from Dec 5, 2017

Conversation

andrewandante
Copy link
Contributor

For tidyness

_config.php Outdated
if (!defined('DEBUGBAR_DIR')) {
define('DEBUGBAR_DIR', 'debugbar');
if (!Environment::getEnv('DEBUGBAR_DIR')) {
Environment::setEnv('DEBUGBAR_DIR', 'resources/lekoala/silverstripe-debugbar');
Copy link

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...

Copy link

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

Copy link
Contributor Author

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...

@andrewandante andrewandante force-pushed the make_into_vendormodule branch 3 times, most recently from 4f4cd47 to ed9248e Compare November 17, 2017 17:35
@andrewandante
Copy link
Contributor Author

Well, tests to fix, but that's the general idea.

@andrewandante andrewandante force-pushed the make_into_vendormodule branch 24 times, most recently from 7f8b7bc to de2d2b2 Compare November 20, 2017 14:45
@andrewandante andrewandante force-pushed the make_into_vendormodule branch 5 times, most recently from 1b309d7 to 03ffdfa Compare November 20, 2017 16:06
@andrewandante
Copy link
Contributor Author

Requires silverstripe/vendor-plugin#10 to fix the tests, cos ModuleLoader is awkward

@@ -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()),

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())

Copy link
Contributor Author

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 :)

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',

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.

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.

Copy link
Contributor Author

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.

Copy link

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...

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.

@@ -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()));

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().

@tractorcow
Copy link

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.

@@ -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()),

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?

@andrewandante andrewandante force-pushed the make_into_vendormodule branch 7 times, most recently from 17caf83 to b210c64 Compare November 21, 2017 15:46

class DatabaseCollectorTest extends SapphireTest
class DatabaseCollectorTest extends FunctionalTest
Copy link

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
Copy link

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());
Copy link

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?

Copy link
Contributor Author

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()
Copy link

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();
Copy link

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

Copy link
Contributor Author

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

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@andrewandante
Copy link
Contributor Author

ping @tractorcow

@robbieaverill robbieaverill merged commit 055c36a into lekoala:master Dec 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants