Sylius / ShopApiPlugin

Shop API for Sylius.
https://sylius.com
129 stars 89 forks source link

Test for latest products has timing issues #323

Closed witrin closed 5 years ago

witrin commented 6 years ago

The expected order in product/product_list_latest_2_response is LOGAN_HAT_CODE, LOGAN_MUG_CODE. The order in the database should be equal to the fixtures; smallest id is LOGAN_MUG_CODE and largest is LOGAN_SHOES_CODE.

As far as I know created_at is using datetime which currently lacks of supporting milliseconds (https://github.com/doctrine/doctrine2/issues/6305). Thus the ORDER BY in https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/CoreBundle/Doctrine/ORM/ProductRepository.php#L140 depends on the DBMS implementation when all values in created_at are the same.

So in general I see here two issues: One for Sylius and one for this plugin. Regarding the plugin I would say the fixtures should set the created_at explicitly. Something like:

Sylius\Component\Core\Model\Product:
    mug:
        code: "LOGAN_MUG_CODE"
        channels: ["@gb_web_channel"]
        currentLocale: "en_GB"
        created_at: "<dateTimeBetween('-3 hours', '-2 hours')>"
        translations: ["@en_gb_mug_product_translation", "@de_de_mug_product_translation"]
        images: ["@mug_thumbnail"]
        mainTaxon: "@mug_taxon"
        productTaxons: ["@mug_product_taxon"]
        attributes:
            - "@en_gb_mug_holiday_collection_value"
            - "@de_de_mug_holiday_collection_value"
            - "@en_gb_mug_holiday_material_value"
            - "@de_de_mug_holiday_material_value"
    t_shirt:
        code: "LOGAN_T_SHIRT_CODE"
        channels: ["@gb_web_channel"]
        currentLocale: "en_GB"
        created_at: "<dateTimeBetween('-7 hours', '-6 hours')>"
        images: ["@t_shirt_thumbnail", "@small_t_shirt_thumbnail", "@large_t_shirt_thumbnail"]
        mainTaxon: "@t_shirt_taxon"
        productTaxons: ["@women_t_shirt_product_taxon"]
    hat:
        code: "LOGAN_HAT_CODE"
        channels: ["@gb_web_channel"]
        options: ["@hat_size"]
        currentLocale: "en_GB"
        created_at: "<dateTimeBetween('-1 hours', 'now')>"
        translations: ["@en_gb_hat_product_translation", "@de_de_hat_product_translation"]
        associations: ["@cross-sell-hat-association"]
        mainTaxon: "@hat_taxon"
        productTaxons: ["@hat_product_taxon"]
    shoes:
        code: "LOGAN_SHOES_CODE"
        channels: ["@gb_web_channel"]
        currentLocale: "en_GB"
        created_at: "<dateTimeBetween('-5 hours', '-4 hours')>"
        translations: ["@en_gb_shoes_product_translation"]
lchrusciel commented 5 years ago

Implemented in #385