skywire/testframework

此包的最新版本(2.4.0)没有提供许可证信息。

2.4.0 2022-09-09 09:47 UTC

This package is auto-updated.

Last update: 2024-09-09 14:20:58 UTC


README

用于辅助单元和集成测试的基本类

版本

版本 1 与 PHPUnit 4 和 5 兼容。

版本 2 与 PHPUnit 6 兼容。

单元测试

您的单元测试应该扩展 Skywire\TestFramework\Unit\TestCase,这将设置类型为 Magento\Framework\TestFramework\Unit\Helper\ObjectManagerobjectManager 属性。

集成测试

非控制器集成测试应扩展 Skywire\TestFramework\Integration\TestCase,这将设置类型为 Magento\TestFramework\ObjectManagerobjectManager 属性。

控制器测试

控制器测试应扩展 Magento\TestFramework\TestCase\AbstractController,这将设置类型为 Magento\TestFramework\ObjectManager_objectManager 属性。

固定装载器

您的集成测试可以从 YAML 文件中加载实体。

class CatalogTest extends Skywire\TestFramework\Integration\TestCase
{
    /**
     * @magentoDataFixture loadFixture
     */
    public function testGetProducts();
    
    public static function loadFixture()
    {
        self::loadFixtureFile(realpath(__DIR__ . '/../_files/products.yml'));
    }
}
# _files/product.yml
entities:
    -   factory: \Magento\Catalog\Model\CategoryFactory
        records:
            -   name: Bar
                id: 100
                path: '1/2'
                level: 2
                parent_id: 2
                is_active: true
    -   factory: \Magento\Catalog\Model\ProductFactory
        repository: \Magento\Catalog\Model\ProductRepository
        records:
            -   id: 3000
                attribute_set_id: 4
                name: Foo
                sku: FOOSKU
                category_ids: [100]
            -   id: 3001
                attribute_set_id: 4
                name: Foo2
                sku: FOO2SKU

除了实体,您还可以直接写入表,这可能对实体关系很有用。

# _files/product.yml
entities:
    -   factory: \Magento\Catalog\Model\CategoryFactory
        records:
            -   name: Bar
            ...
    -   factory: \Magento\Catalog\Model\ProductFactory
        repository: \Magento\Catalog\Model\ProductRepository
        records:
            -   id: 3000
                attribute_set_id: 4
                name: Foo
                sku: FOOSKU
            ...

tables:
    -   table: catalog_category_product
        rows:
            -   category_id: 100
                product_id: 3000
                position: 10