PHP code example of ecomdev / testcontainers-magento-data
1. Go to this page and download the library: Download ecomdev/testcontainers-magento-data library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ecomdev / testcontainers-magento-data example snippets
use EcomDev\TestContainers\MagentoData\DbContainerBuilder;
$container = DbContainerBuilder::mysql()
->build();
use EcomDev\TestContainers\MagentoData\DbContainerBuilder;
$container = DbContainerBuilder::mysql()
->withSampleData()
->build();
use EcomDev\TestContainers\MagentoData\DbContainerBuilder;
use PDO;
$container = DbContainerBuilder::mysql()
->withMagentoVersion('2.4.7-p2')
->withSampleData()
->build();
$connectionSettings = $container->getConnectionSettings();
$connection = new PDO(
$connectionSettings->dsn(),
$connectionSettings->user,
$connectionSettings->password
);
$result = $connection->query('SELECT COUNT(*) FROM catalog_product_entity');
// Outputs 2040
echo $result->fetch(PDO::FETCH_COLUMN);
use EcomDev\TestContainers\MagentoData\DbContainerBuilder;
$container = DbContainerBuilder::mariadb()
->withMagentoVersion('2.4.7-p2')
->withSampleData()
->build();
use EcomDev\TestContainers\MagentoData\OpenSearchContainerBuilder;
use GuzzleHttp\Client;
$container = OpenSearchContainerBuilder::new()
->withSampleData()
->build();
$client = new Client([
'base_uri' => $container->getBaseUrl()
]);
$result = json_decode(
$client->get('magento2_product_1/_count')->getBody()->getContents(),
true
);
// Outputs 181
echo $result['count'];
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.