#container #test-containers #quick #search #db #image #magento

testcontainers-magento-data

🐳 Test-Containers for Quick Magento Development

1 unstable release

0.1.0 Jan 7, 2025

#662 in Database interfaces

Download history 59/week @ 2025-01-01 62/week @ 2025-01-08

121 downloads per month

MIT license

20KB
432 lines

🐳 Test-Containers for Quick Magento Development

Docker Build Rust Build

This package simplifies the process of automated testing with real database and search engine

✨ Features

  • πŸ“¦ Pre-configured database and search containers: Instantly spin up containers with ready-to-use Magento data
  • βš™οΈ Easy setup and use: Use Rust package to automatically discard container after tests
  • 🎯 Blazingly Fast: Container takes only few seconds to start, so you can focus on testing instead of waiting for db initialization

πŸ“‹ Requirements

  • 🐳 Docker: Ensure Docker is installed and operational on your system.

πŸ“¦ Available images

All the available Docker image version can be found in build repository EcomDev/testcontainer-magento-data

Installation

Use cargo with --dev flag to add it as dependency for your tests

cargo add --dev testcontainers-magento-data

Examples

MySQL container

Run queries against Magento database build with sample data

use sqlx::MySqlPool;
use testcontainers_magento_data::runners::AsyncRunner;
use testcontainers_magento_data::core::ImageBuilder;
use testcontainers_magento_data::images::{DbConnection, DbContainer};

#[tokio::test]
async fn starts_container_with_sample_data() {
    let container = DbContainer::mariadb()
        .with_sample_data()
        .with_version("2.4.7-p2")
        .start()
        .await
        .unwrap();

    let connection = MySqlPool::connect(&container.connection_url().await.unwrap())
        .await
        .unwrap();

    let total: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM catalog_product_entity")
        .fetch_one(&connection)
        .await
        .unwrap();

    assert_eq!(total, 2040);
}

πŸ“œ License

This project is licensed under the MIT License.

See the LICENSE file for more details.

Dependencies

~25–43MB
~708K SLoC