Skip to content
Snippets Groups Projects
Commit 489a3e59 authored by Vadim Justus's avatar Vadim Justus
Browse files

Add example integration test with fixtures

parent 39081a8c
No related branches found
No related tags found
No related merge requests found
<?php
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
namespace Met\ExampleMagento2ModuleTesting\Test\Integration\Model;
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
use PHPUnit\Framework\TestCase;
/**
* @copyright Copyright (c) 2019 TechDivision GmbH (http://www.techdivision.com)
* @link http://www.techdivision.com/
* @author Vadim Justus <v.justus@techdivision.com>
*/
class PipelineInitializer extends TestCase
{
/**
* @magentoDataFixtures Met_ExampleMagento2ModuleTesting::Test/Integration/_files/some-fixture.php
*/
public function testFoobar()
{
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->create(SearchCriteriaBuilder::class);
/** @var OrderRepositoryInterface $orderRepository */
$orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class);
$searchCriteria = $searchCriteriaBuilder->create();
$orders = $orderRepository->getList($searchCriteria)->getItems();
$this->assertCount(6, $orders);
}
}
<?php
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
use Magento\Catalog\Model\Product\Type;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\Order\Address;
use Magento\Sales\Model\Order\Item;
use Magento\Sales\Model\Order\Payment;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;
$addressData = [
'firstname' => 'guest',
'lastname' => 'guest',
'email' => 'customer@example.com',
'street' => 'street',
'city' => 'Los Angeles',
'region' => 'CA',
'postcode' => '1',
'country_id' => 'US',
'telephone' => '1'
];
$paymentMethods = [
0 => 'checkmo',
1 => 'test_cc',
2 => 'test_cc',
3 => 'invoice',
4 => 'paypal_expr',
5 => 'paypal_expr',
];
$orderStatus = [
0 => 'pending',
1 => 'pending',
2 => 'processing',
3 => 'pending',
4 => 'processing',
5 => 'processing',
];
for ($counter = 0; $counter <= 5; $counter++) {
/** @var $billingAddress Address */
$billingAddress = Bootstrap::getObjectManager()->create(Address::class, ['data' => $addressData]);
$billingAddress->setAddressType('billing');
$shippingAddress = clone $billingAddress;
$shippingAddress->setId(null)->setAddressType('shipping');
/** @var $payment Payment */
$payment = Bootstrap::getObjectManager()->create(Payment::class);
$payment->setMethod($paymentMethods[$counter]);
/** @var $orderItem Item */
$orderItem = Bootstrap::getObjectManager()->create(Item::class);
$orderItem->setProductId($counter)
->setProductType(Type::TYPE_SIMPLE)
->setName('product name')
->setSku('MET0000' . $counter)
->setBasePrice(100 + $counter)
->setQtyOrdered(1)
->setQtyShipped(1)
->setIsQtyDecimal(true);
/** @var StoreManagerInterface $storeManager */
$storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
/** @var $order Order */
$order = Bootstrap::getObjectManager()->create(Order::class);
$order->addItem($orderItem)
->setIncrementId('METEXAMPLE-10' . $counter)
->setSubtotal(100 + $counter)
->setBaseSubtotal(100 + $counter)
->setCustomerIsGuest(true)
->setCustomerEmail('admin@example.com')
->setStatus($orderStatus[$counter])
->setBillingAddress($billingAddress)
->setShippingAddress($shippingAddress)
->setStoreId($storeManager->getStore()->getId())
->setPayment($payment);
/** @var OrderRepositoryInterface $orderRepository */
$orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class);
$orderRepository->save($order);
}
<?php
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
declare(strict_types=1);
use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Registry;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\TestFramework\Helper\Bootstrap;
/** @var Registry $registry */
$registry = Bootstrap::getObjectManager()->get(Registry::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);
/** @var OrderRepositoryInterface $orderRepository */
$orderRepository = Bootstrap::getObjectManager()->get(OrderRepositoryInterface::class);
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class);
$searchCriteria = $searchCriteriaBuilder->addFilter(
'increment_id',
'METEXAMPLE-%',
'like'
)->create();
$orders = $orderRepository->getList($searchCriteria);
foreach ($orders->getItems() as $order) {
$orderRepository->delete($order);
}
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
{
"name": "met/example-magento2-module-testing",
"description": "Example module for Magento 2 automated testing on MET CI",
"require": {
"magento/framework": "*",
"magento/module-sales": "*"
},
"type": "magento2-module",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"Met\\ExampleMagento2ModuleTesting\\": ""
}
}
}
\ No newline at end of file
<?xml version="1.0"?>
<!--
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*
* @copyright Copyright (c) 2019 TechDivision GmbH (http://www.techdivision.com)
* @author Vadim Justus <v.justus@techdivision.com>
* @link http://www.techdivision.com/
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Met_ExampleMagento2ModuleTesting" setup_version="1.0.0">
<sequence>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
<?php
/**
* Copyright (c) 2019 TechDivision GmbH
* All rights reserved
*
* This product includes proprietary software developed at TechDivision GmbH, Germany
* For more information see http://www.techdivision.com/
*
* To obtain a valid license for using this software please contact us at
* license@techdivision.com
*/
\Magento\Framework\Component\ComponentRegistrar::register(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
'Met_ExampleMagento2ModuleTesting',
__DIR__
);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment