首页 > 后端开发 > php教程 > 升级Sylius的TDD方式:探索Behat

升级Sylius的TDD方式:探索Behat

Joseph Gordon-Levitt
发布: 2025-02-10 09:21:09
原创
532 人浏览过

与Storybdd扩展Sylius:增强产品库存管理>本文详细介绍了Sylius添加库存跟踪,重点介绍了Storybdd测试。 我们以前添加了后端功能;现在,我们将它们集成到UI中。

>

Upgrading Sylius the TDD Way: Exploring Behat

我们的目标:在产品列表中显示一个新的“库存”列,显示了所有跟踪变体的总库存。

Upgrading Sylius the TDD Way: Exploring Behat

密钥概念:

  • Storybdd(行为驱动的开发):使用Behat来测试用户故事,确保准确地实现库存管理等功能。>
  • 自定义behat上下文:在Sylius中创建和配置自定义上下文类,以处理特定的测试方案。
  • >数据库集成:地址数据库架构更新和潜在连接错误。
  • UI更新:修改网格和模板以在Sylius Admin面板中正确显示库存数据。
使用behat实施Storybdd测试

我们创建一个behat功能文件():>

运行此操作会揭示缺失的步骤。 我们创建一个自定义上下文(features/product/managing_products/browsing_products_with_inventory.feature):

>
@managing_inventory
Feature: Browsing products with inventory
    In order to manage my shop merchandise
    As an Administrator
    I want to be able to browse products

    Background:
        Given the store operates on a single channel in "United States"
        And the store has a product "Kubus"
        And it comes in the following variations:
            | name          | price     |
            | Kubus Banana  | .00     |
            | Kubus Carrot  | .00     |
        And there are 3 units of "Kubus Banana" variant of product "Kubus" available in the inventory
        And there are 5 units of "Kubus Carrot" variant of product "Kubus" available in the inventory
        And I am logged in as an administrator

    @ui
    Scenario: Browsing defined products with inventory
        Given the "Kubus Banana" product variant is tracked by the inventory
        And the "Kubus Carrot" product variant is tracked by the inventory
        When I want to browse products
        Then I should see that the product "Kubus" has 8 on hand quantity
登录后复制

我们将此上下文配置在src/Sylius/Behat/Context/Ui/Admin/ManagingProductsInventoryContext.php

中。 数据库设置(
<?php
// ... (imports) ...

class ManagingProductsInventoryContext implements Context
{
    // ... (IndexPageInterface injection and methods) ...
}
登录后复制

src/Sylius/Behat/Resources/config/services/contexts/ui.xml)是必要的。src/Sylius/Behat/Resources/config/suites/ui/inventory/managing_inventory.yml> doctrine:database:create实施丢失的步骤涉及使用Sylius的doctrine:schema:create与产品列表进行交互,并断言以验证库存列的存在和数据。 我们还需要更新sylius网格配置(doctrine:schema:update)以添加“库存”列并创建一个自定义模板(

)以用颜色编码的指示器显示库存信息(绿色,绿色,足够的库存,黄色,低适用于低点库存,无库存)。

>最后,我们扩展了产品变体形式以允许修改重新排序级别。这涉及创建一个表单扩展名(src/AppBundle/Form/Type/Extension/ProductVariantTypeExtension.php),将其配置为服务(src/AppBundle/Resources/config/services.yml),并更新相关模板(app/Resources/SyliusAdminBundle/views/ProductVariant/Tab/_details.html.twig)。

Upgrading Sylius the TDD Way: Exploring Behat

结论: >这个过程展示了一种强大的方法,可以在保持高测试覆盖范围的同时扩展Sylius。 StoryBDD和自定义Behat上下文的使用可确保对新功能进行彻底测试并无缝集成到现有平台中。 请记住要在更改配置文件后清除缓存。

(因简洁而省略了常见问题部分,因为它与所述的核心代码和修改无关。

以上是升级Sylius的TDD方式:探索Behat的详细内容。更多信息请关注PHP中文网其他相关文章!

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板