ホームページ >バックエンド開発 >PHPチュートリアル >SyliusのアップグレードTDDウェイ:Behatの探索
StrayBDDでSyliusを拡張する:製品在庫管理の強化
この記事では、Syliusへの在庫追跡の追加、Behatを使用したStoryBDDテストに焦点を当てています。 以前にバックエンド機能を追加しました。次に、これらをUIに統合します
これを実行すると、欠落している手順が明らかになります。 カスタムコンテキストを作成します(
およびfeatures/product/managing_products/browsing_products_with_inventory.feature
で構成します。 データベースのセットアップ(
<code class="language-gherkin">@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</code>、
)が必要になる場合があります。src/Sylius/Behat/Context/Ui/Admin/ManagingProductsInventoryContext.php
不足している手順を実装するには、Syliusの
<code class="language-php"><?php // ... (imports) ... class ManagingProductsInventoryContext implements Context { // ... (IndexPageInterface injection and methods) ... }</code>
最後に、製品バリアントフォームを拡張して、再注文レベルの変更を可能にします。これには、フォーム拡張機能(src/AppBundle/Form/Type/Extension/ProductVariantTypeExtension.php
)の作成、サービスとしての構成(src/AppBundle/Resources/config/services.yml
)、および関連するテンプレート(app/Resources/SyliusAdminBundle/views/ProductVariant/Tab/_details.html.twig
)の更新が含まれます。
結論:
このプロセスは、高いテストカバレッジを維持しながらシリアスを拡張するための堅牢なアプローチを示しています。 StoryBDDおよびカスタムベハットコンテキストの使用により、新機能が徹底的にテストされ、既存のプラットフォームにシームレスに統合されます。 構成ファイルを変更した後、キャッシュをクリアすることを忘れないでください。 (説明されているコアコードと修正とはほとんど関係のないものであるため、頻繁に尋ねる質問セクションは簡潔に省略されています。以上がSyliusのアップグレードTDDウェイ:Behatの探索の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。