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

Separated order items subtotal calculation logic from twig extension #11191

Merged
merged 11 commits into from
Apr 9, 2020
Merged

Separated order items subtotal calculation logic from twig extension #11191

merged 11 commits into from
Apr 9, 2020

Conversation

4c0n
Copy link
Contributor

@4c0n 4c0n commented Mar 6, 2020

Q A
Branch? 1.6
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
License MIT

I'd like to be able to use the logic for calculating the subtotal of all order items outside of Twig templates, hence this separation.

@4c0n 4c0n requested a review from a team as a code owner March 6, 2020 12:11
@4c0n
Copy link
Contributor Author

4c0n commented Mar 6, 2020

Sorry I don't know how to fix the memory issues on the php 7.2 installation build. The others pass.

@Zales0123 Zales0123 added DX Issues and PRs aimed at improving Developer eXperience. Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.). labels Mar 9, 2020
/** @var OrderItemsSubtotalCalculatorInterface */
private $calculator;

public function __construct(OrderItemsSubtotalCalculatorInterface $calculator)
Copy link
Member

Choose a reason for hiding this comment

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

It's BC break :( We should keep current logic as a fallback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lchrusciel Thanks for the review! I addressed the BC break, please have another look.

4c0n pushed a commit to nedac-sorbo/SyliusMinimumOrderValuePlugin that referenced this pull request Mar 9, 2020
@4c0n
Copy link
Contributor Author

4c0n commented Apr 1, 2020

@lchrusciel Is there anymore that needs to be done before this can be merged?
I'm waiting on this to release a plugin that allows setting a minimum order value. It can be done by duplicating this logic in the plugin as well, but I'd rather not.

Copy link
Member

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

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

Hey Youri,

thanks a lot for your contribution. I would like to merge it in the nearest days. Could you take my comments into account?

However, we are slightly blocked by red build on v1.6 :(

use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;

final class OrderItemsSubtotalCalculatorTest extends TestCase
Copy link
Member

Choose a reason for hiding this comment

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

The structure of this test seems to be a perfect match for phpspec. It is not necessary but rather recommended. Would you like to give it a try?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps another time. I'm interested to know when do you prefer spec over unit when it comes to testing? Very similar results can be achieved between the two, but I guess the focus does not 100% have to be on structure alone for unit tests?

Copy link
Member

Choose a reason for hiding this comment

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

PHPSpec - unit testing, but to be more precise it is more for designing implementation. Testing every class in total separation, all collaborators are mocked and you need to be precise, what should be asserted (shouldBeCalled) and return (willReturn). Prophecy is a great part of this library, which was recently deprecated on PHPUnit. Also, it forces you for the usage of mocks rather than separated classes.
PHPUnit - functional testing - mostly used for more than one class initialized in the test suite. Some examples, testing of services fetched from the container, FormType testing, testing of configuration and old API testing
Behat - acceptance tests, focused mostly on business value and covered through all of Sylius layers

The distinction between PHPSpec & PHPUnit in terms of unit testing can indeed be a matter of taste, but we've decided to go with PHPSpec, and keeping codebase coherent is important for us.

Is it clearer right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that's pretty clear. I'd hate to jump in and learn about how phpspec works right here and now, but next time I'll do it that way for sure.

@4c0n
Copy link
Contributor Author

4c0n commented Apr 7, 2020

Hey Youri,

thanks a lot for your contribution. I would like to merge it in the nearest days. Could you take my comments into account?

However, we are slightly blocked by red build on v1.6 :(

Do you have any idea about the memory issues of the 7.2 installation build? That is what's failing, maybe because of the new package not being in the composer cache or something like that.
Let's see if the new build has the same issue or not.

@4c0n
Copy link
Contributor Author

4c0n commented Apr 7, 2020

Seems to be something specific to Travis:

=> Storing composer.lock in cache (cache key: e82419b5c6d676d78173acda5ffa8b24)
The command "etc/travis/run-suite install "${SYLIUS_SUITE}"" failed and exited with 1 during .
Your build has been stopped.

Is it possible for you to clear the composer cache somehow?

@lchrusciel
Copy link
Member

I've restarted this build again

@4c0n
Copy link
Contributor Author

4c0n commented Apr 7, 2020

Installing: CoreBundle
> composer install --ansi --no-interaction --prefer-dist --quiet
Warning: proc_open(): fork failed - Cannot allocate memory in phar:///home/travis/.phpenv/versions/7.2.29/bin/composer/vendor/symfony/console/Application.php on line 952
The following exception is caused by a lack of memory or swap, or not having swap configured
Check https://getcomposer.org/doc/articles/troubleshooting.md#proc-open-fork-failed-errors for details
PHP Warning:  proc_open(): fork failed - Cannot allocate memory in phar:///home/travis/.phpenv/versions/7.2.29/bin/composer/vendor/symfony/console/Application.php on line 952
                                                     
  [ErrorException]                                   
  proc_open(): fork failed - Cannot allocate memory  
                                                     

@4c0n
Copy link
Contributor Author

4c0n commented Apr 7, 2020

So composer crashes because it seems to need more memory. Typical 😝

I don't usually work with Travis, so I kind of don't know if it is possible at all to increase the available memory for composer.

@4c0n
Copy link
Contributor Author

4c0n commented Apr 9, 2020

@lchrusciel Hi Lukasz,
In order to resolve the memory issues, I added the creation and activation of a swap file in the CI VM.
The build passes now. Are we good to go?

@lchrusciel
Copy link
Member

Hey @4c0n, In the meantime, I have fixed it in #11341, where I've reduced the number of tags to solve. We should do it anyway. Your proposal is good to go, however, I would like to revert the last change.

Nonetheless, it can be done in separate PR

@lchrusciel lchrusciel merged commit ade9a9e into Sylius:1.6 Apr 9, 2020
@lchrusciel
Copy link
Member

Thanks, Youri! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Issues and PRs aimed at improving Developer eXperience. Enhancement Minor issues and PRs improving the current solutions (optimizations, typo fixes, etc.).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants