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

Does not report changes in parent constructor #106

Open
norgeindian opened this issue Jul 26, 2023 · 5 comments
Open

Does not report changes in parent constructor #106

norgeindian opened this issue Jul 26, 2023 · 5 comments
Labels
bug Something isn't working cannot reproduce cannot reproduce help wanted Extra attention is needed

Comments

@norgeindian
Copy link
Contributor

We have a preference on class X in which we extend the overridden class and call the constructor of the parent.
During the latest update, the constructor, which we call, has changed. One more parameter has been added.
This issue has not been found by the helper, but leads to a critical error.
It would be awesome to find a way to catch these kind of problems as well.

@convenient
Copy link
Contributor

One more parameter has been added. This issue has not been found by the helper, but leads to a critical error.

Internally we rely a lot on using this tool alongside phpcs and phpstan, just curious if it was picked up by any other means?

I am surprised the change to the constructor on the parent class didnt flag this as a change to preference in general, as any changes to a thing you have a preference on, should be flagged 🤔

Could you give a general example with a few more details?

@norgeindian
Copy link
Contributor Author

@convenient , I actually ran into it before it came into our automated testing process.
But I'm with you, this would have surely been caught by some other tool.
Nevertheless, I would say it would be great if it could be included in the helper as well.

The change came from https://github.com/mollie/magento2.
We updated from version 2.27.0 to 2.29.0.
Our preference is defined in the following way:

<preference for="Mollie\Payment\Model\Client\Orders" type="CustomGento\Mollie\Model\Client\Orders"/>

Our constructor was the following:

    public function __construct(
        OrderLines $orderLines,
        InvoiceSender $invoiceSender,
        OrderRepository $orderRepository,
        CheckoutSession $checkoutSession,
        ManagerInterface $messageManager,
        Registry $registry,
        MollieHelper $mollieHelper,
        ProcessAdjustmentFee $adjustmentFee,
        OrderCommentHistory $orderCommentHistory,
        PartialInvoice $partialInvoice,
        StoreCredit $storeCredit,
        RefundUsingPayment $refundUsingPayment,
        Expires $expires,
        State $orderState,
        Transaction $transaction,
        BuildTransaction $buildTransaction,
        PaymentTokenForOrder $paymentTokenForOrder,
        ProcessTransaction $processTransaction,
        \Mollie\Payment\Service\Mollie\MollieApiClient $mollieApiClient,
        Config $config,
        EventManager $eventManager,
        LinkTransactionToOrder $linkTransactionToOrder,
        OrderLockService $orderLockService
    ) {
        parent::__construct(
            $orderLines,
            $invoiceSender,
            $orderRepository,
            $checkoutSession,
            $messageManager,
            $registry,
            $mollieHelper,
            $adjustmentFee,
            $orderCommentHistory,
            $partialInvoice,
            $storeCredit,
            $refundUsingPayment,
            $expires,
            $orderState,
            $transaction,
            $buildTransaction,
            $paymentTokenForOrder,
            $processTransaction,
            $mollieApiClient,
            $config,
            $eventManager,
            $linkTransactionToOrder,
            $orderLockService
        );

This was fine for 2.27.0, but must include $shouldEmailInvoice in the new version, as the constructor of the original class has been changed to this:

    public function __construct(
        OrderLines $orderLines,
        InvoiceSender $invoiceSender,
        OrderRepository $orderRepository,
        CheckoutSession $checkoutSession,
        ManagerInterface $messageManager,
        Registry $registry,
        MollieHelper $mollieHelper,
        ProcessAdjustmentFee $adjustmentFee,
        OrderCommentHistory $orderCommentHistory,
        PartialInvoice $partialInvoice,
        StoreCredit $storeCredit,
        RefundUsingPayment $refundUsingPayment,
        Expires $expires,
        State $orderState,
        Transaction $transaction,
        BuildTransaction $buildTransaction,
        PaymentTokenForOrder $paymentTokenForOrder,
        ProcessTransaction $processTransaction,
        \Mollie\Payment\Service\Mollie\MollieApiClient $mollieApiClient,
        Config $config,
        EventManager $eventManager,
        LinkTransactionToOrder $linkTransactionToOrder,
        OrderLockService $orderLockService,
        ShouldEmailInvoice $shouldEmailInvoice
    ) {
        $this->orderLines = $orderLines;
        $this->invoiceSender = $invoiceSender;
        $this->orderRepository = $orderRepository;
        $this->checkoutSession = $checkoutSession;
        $this->messageManager = $messageManager;
        $this->registry = $registry;
        $this->mollieHelper = $mollieHelper;
        $this->adjustmentFee = $adjustmentFee;
        $this->storeCredit = $storeCredit;
        $this->refundUsingPayment = $refundUsingPayment;
        $this->orderCommentHistory = $orderCommentHistory;
        $this->partialInvoice = $partialInvoice;
        $this->expires = $expires;
        $this->orderState = $orderState;
        $this->transaction = $transaction;
        $this->buildTransaction = $buildTransaction;
        $this->eventManager = $eventManager;
        $this->paymentTokenForOrder = $paymentTokenForOrder;
        $this->processTransaction = $processTransaction;
        $this->mollieApiClient = $mollieApiClient;
        $this->config = $config;
        $this->linkTransactionToOrder = $linkTransactionToOrder;
        $this->orderLockService = $orderLockService;
        $this->shouldEmailInvoice = $shouldEmailInvoice;
    }

Hope, I could make it obvious, what I mean.

@convenient
Copy link
Contributor

Interesting i believe this should have flagged definitely an issue to review

@convenient convenient added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Jul 28, 2023
convenient added a commit that referenced this issue Aug 4, 2023
@convenient convenient mentioned this issue Aug 4, 2023
3 tasks
@convenient
Copy link
Contributor

convenient commented Aug 4, 2023

Hey @norgeindian

So I've updated the phpunit test for the preference and it works just fine for me #107

The preferences logic doesn't do any deep analysis of what has changed, only that its a PHP file and it is has a preference attached. I think that even a whitespace will be enough to create a diff, which will be picked up by the tool which will scan the filepath and pass it through the following code

https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/src/Ampersand/PatchHelper/Checks/ClassPreferencePhp.php#L50-L86

I would have expected you to have some output like

+-------+------------+---------------------------------------------------------------------------------------+---------------------------------------------------+
| Level | Type       | File                                                                                  | To Check                                          |
+-------+------------+---------------------------------------------------------------------------------------+---------------------------------------------------+
| WARN  | Preference | vendor/mollie/module-payment-or-whatever/Model/Client/Orders.php                      | CustomGento\Mollie\Model\Client\Orders            |
+-------+------------+---------------------------------------------------------------------------------------+---------------------------------------------------+

If you have time I'd recommend following the steps on https://github.com/AmpersandHQ/ampersand-magento2-upgrade-patch-helper/blob/master/docs/TROUBLESHOOTING.md#debug-a-specific-file to debug this specific file and maybe run through xdebug to see why it was not being reported?

@convenient convenient added cannot reproduce cannot reproduce and removed good first issue Good for newcomers labels Aug 4, 2023
@tr33m4n
Copy link
Contributor

tr33m4n commented Feb 9, 2024

Hi @norgeindian, is this still an issue? Just reviewing open issues and seeing where we're at 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cannot reproduce cannot reproduce help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants