diff --git a/Test/Integration/Model/ExampleTest.php b/Test/Integration/Model/ExampleTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b91716286e8147f8a7264d7a5f80e5872547f37a --- /dev/null +++ b/Test/Integration/Model/ExampleTest.php @@ -0,0 +1,44 @@ +<?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); + } +} diff --git a/Test/Integration/_file/some-fixture.php b/Test/Integration/_file/some-fixture.php new file mode 100644 index 0000000000000000000000000000000000000000..28b16fa1b4d04dd5c853beb8ceec0e25c05e78c0 --- /dev/null +++ b/Test/Integration/_file/some-fixture.php @@ -0,0 +1,96 @@ +<?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); +} diff --git a/Test/Integration/_file/some-fixture_rollback.php b/Test/Integration/_file/some-fixture_rollback.php new file mode 100644 index 0000000000000000000000000000000000000000..2d37fe7bb20d82a5398aeaeb3dfb83eeaffdd156 --- /dev/null +++ b/Test/Integration/_file/some-fixture_rollback.php @@ -0,0 +1,42 @@ +<?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); diff --git a/composer.json b/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..00a3fd163e0293d33e5cd3fb604a0d63865036fa --- /dev/null +++ b/composer.json @@ -0,0 +1,17 @@ +{ + "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 diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000000000000000000000000000000000000..8de246f0976db598c970350a30c3af467d5c0449 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,24 @@ +<?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> diff --git a/registration.php b/registration.php new file mode 100644 index 0000000000000000000000000000000000000000..3c6132b85c478020cd6bd05acffeaa77c21283f2 --- /dev/null +++ b/registration.php @@ -0,0 +1,16 @@ +<?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__ +);