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

[5.4] Refactoring mix method (bis). #19666

Closed
wants to merge 12 commits into from

Conversation

mathieutu
Copy link
Contributor

Some features added, and code style fixed from reviews of the previous PR:
#19639

@taylorotwell have fun, I'm waiting for your wisdom!
😊

}

return new HtmlString($manifestDirectory.$manifest[$path]);
return app('mix')->mix($path, $manifestDirectory);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it looks strange to do (new Mix)->mix() why not something more like (new Mix)->create()..

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep or generate maybe?

Copy link
Contributor Author

@mathieutu mathieutu Jun 19, 2017

Choose a reason for hiding this comment

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

Yeah I thought about that.
create and generate aren't good ones either because you don't create or generate anything, you just find the good path in a file, so find? I didn't find something I liked, so I kept that because in any way, the method will always be called by the mix() helper, as usual.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about load?

Copy link
Contributor

Choose a reason for hiding this comment

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

Could use resolve(). If Taylor merges it, he could always rename it.

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 love resolve thank you! 🎉

{
public function setUp()
{
app()->singleton('path.public', function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔
Yeah, it's true and I also could have created all the other files by the same way actually (file_put_content(json_encode(...))), but I've done it like that.

I, personally, prefer commit two empty files to test a function than add some extra complexity to generate them.

But, anyway, does it really matter ??

*/
protected function getManifest()
{
if (! $this->manifest) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to go further if $this->manifest is not empty. You can favor an early return:

if ($this->manifest) {
    return $this->manifest;
}

if (! file_exists($manifestPath = public_path($this->manifestDirectory.$this->manifestFilename))) {
    throw new MixException('The Mix manifest does not exist.');
}

$this->manifest = json_decode(file_get_contents($manifestPath), true);

if (json_last_error() === JSON_ERROR_NONE) {
    return $this->manifest;
}

throw new MixException("The Mix manifest isn't a proper json file.");

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's your code right here, you made me change mine to yours for no valid reason, and now you're again changing your mind. It's just about a basic refactoring and you're commenting every line I'm writing for 3 days each time I make a new commit.

I have work to do, and I haven't not enough time to satisfy all your dreams on a basic function like this one. So, I don't know what's your goal, but please stop, or do it yourself!

Copy link
Contributor

@lucasmichot lucasmichot Jun 19, 2017

Choose a reason for hiding this comment

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

It's just about a basic refactoring

It's a great PR but a critical function.

*
* @param string $manifestFilename
*
* @return Mix
Copy link
Contributor

Choose a reason for hiding this comment

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

We use @return $this

*
* @param string $hmrFilename
*
* @return Mix
Copy link
Contributor

Choose a reason for hiding this comment

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

We use @return $this


/**
* @expectedException \Illuminate\View\Mix\MixException
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

The exception message should also be tested here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope, we don't care about the message, it's just to check that is enabled.

Copy link
Contributor

@lucasmichot lucasmichot Jun 19, 2017

Choose a reason for hiding this comment

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

We care as your test fails with @expectedExceptionMessage Mix is disabled
If the same exception is used for different purposes within a context, then the exception message should be tested too.

Copy link
Contributor Author

@mathieutu mathieutu Jun 19, 2017

Choose a reason for hiding this comment

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

No, not at all!
This exception message doesn't exists, we are not expecting any special exception, just check the mix method is enabled.
Please read the code instead of commenting every line I'm writing!

Copy link
Contributor

Choose a reason for hiding this comment

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

I've read it for some days already - I think that I got the picture
When you run $this->getMix()->disable()->enable()->mix('foo.css'); is thrown \Illuminate\View\Mix\MixException which is tested, and this exception comes with the message The Mix manifest does not exist.
So this exception message should be also tested.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, we don't suceed to understand each other, I'm just switching in our mutual native language, it will be easier for us. 😕

Ici on s'en fout de savoir ce qui arrive après, on veut juste s'assurer que la méthode enable "marche" comme il faut. Dès l'instant où il y a autre chose que le comportement de disable, donc une exception, peu importe laquelle dans ce cas là, ça veut dire que ça marche.

On peut rajouter le test du message, mais c'est une question de logique ici, on ne cherche pas à savoir quel message va être affiché, juste s'assurer que la fonction continue, et ne s'arrête pas sur le disable.


private function getMix()
{
return new \Illuminate\View\Mix\Mix;
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to declare a useless method here.
$this->mix = new \Illuminate\View\Mix\Mix; can be in setUp method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Guy, I think you should make all the PRs just by yourself.

It's just about a basic refactoring, I've added here tests that didn't exist and you're commenting every line I'm writing for 3 days each time I make a new commit.

I have work to do, and I haven't not enough time to satisfy all your dreams on a basic function like this one. So, I don't know what's your goal, but please stop, or do it yourself!

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe there is some misunderstanding out there.
You plan to refactor a mix function that everyone is using on 5.4 impacting current users, and that will be soon merged to 5.5.
This is a function loaded on each page request displaying a view, so it's expected to be performant and highly tested, right?

No need to be pissed and get personal

Copy link
Contributor Author

@mathieutu mathieutu Jun 19, 2017

Choose a reason for hiding this comment

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

Yeah, but you can understand that this is much better than before, and you agree that each commit I'm making, you add some things.
I'm ok to discuss, exchange some "good" practices, and I agree than I have not your experience about the coding style of this framework. It's why I used your advices and pieces of code, even if sometimes I don't agree with.

But please if we can just tell everything once, and don't come back each time on the same piece of code, we will save time both. Especially like here when it's here in a test, than even didn't exist!!

Imho you will have a lot more value to write tests than just make PRs to rewrite docblocks and code style of others!

I personally have a job, make opensource on my free time because I love it, and you are just disgusting me about that and it's a bit too bad...

If you want, you can make a PR to my branch I will merge it immediately, and so it's ok we're done and we can move to important stuffs!

Copy link
Contributor

@lucasmichot lucasmichot Jun 19, 2017

Choose a reason for hiding this comment

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

Hey Mathieu, pas de problème ;-)
I have a job too, and do this on my free-time too - I am just making sure that you're great PR will be merged and ready to rock

Next time I will PR you fork if you feels that easier, up to you

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok Lucas.
So, I'll do all the modifications tonight. Do you see now something else to update? I think it will be the last time, this is THE moment to tell me! 🙃

@mathieutu
Copy link
Contributor Author

@lucasmichot it's ok for you?
Can I ping taylor to merge it?


public function testMixMethodWhenDisabled()
{
$this->assertEquals(new HTMLString('Mix is disabled!'), $this->mix->disable()->resolve('foo.css'));
Copy link
Contributor

Choose a reason for hiding this comment

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

Casing of HTMLString should be HtmlString

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! thx!

@mathieutu
Copy link
Contributor Author

mathieutu commented Jun 23, 2017

@taylorotwell I think we're ok, you can merge it!
🎉

@taylorotwell
Copy link
Member

taylorotwell commented Jun 25, 2017

The object design on this seems weird. Why does the Mix object have this stateful $path variable and this init method that sets all this state? Shouldn't you just be passing a path in and getting a path out? I don't understand why it's hanging onto all this information.

@devcircus
Copy link
Contributor

At the end if the day, make sure we have a way to use a custom manifest file name.

@sebastiandedeyne
Copy link
Contributor

First off, really hope to see something like this merged in since it could drastically reduce build times on CI environments.

If variables like $hmrFilename and $manifestFilename really are things people care about modifying, maybe mix should get it's own config file? I think that'd make more sense than all these getters and setters, no?

@lucasmichot
Copy link
Contributor

@mathieutu , I believe this PR should be updated to comply #19764 which has been merged recently

@taylorotwell
Copy link
Member

See above comment about conflicts and please send this to 5.5 and I will try to rewrite some of it. Thanks.

@mathieutu
Copy link
Contributor Author

@lucasmichot We agree that the PR you mentioned can't actually be working at all?!

see #19764 (comment)

I've fixed it in #19895.

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.

8 participants