Skip to content

Commit

Permalink
Merge pull request #17 from snowio/integration-tests-fixes
Browse files Browse the repository at this point in the history
Add integration test setup
  • Loading branch information
convenient authored May 21, 2021
2 parents 298cf4f + 6b183a9 commit 46aff54
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 17 deletions.
63 changes: 63 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
language: php
php:
- 7.3
- 7.4
dist: xenial

env:
matrix:
- TEST_GROUP=magento_latest
# - TEST_GROUP=magento_23
matrix:
exclude:
- php: 7.4
env: TEST_GROUP=magento_23
- php: 7.3
env: TEST_GROUP=magento_latest

before_install:
- phpenv config-rm xdebug.ini || true
- composer self-update --1

install:
- export COMPOSER_MEMORY_LIMIT=-1
- export COMPOSER_PACKAGE_NAME=$(composer config name)
- composer install --no-interaction
# Install magento
- if [[ $TEST_GROUP = magento_23 ]]; then NAME=snowmodule FULL_INSTALL=0 VERSION=2.3.6-p1 . ./vendor/bin/travis-install-magento.sh; fi
- if [[ $TEST_GROUP = magento_latest ]]; then NAME=snowmodule FULL_INSTALL=0 . ./vendor/bin/travis-install-magento.sh; fi
# Install this module
- cd vendor/ampersand/travis-vanilla-magento/instances/snowmodule
- export COMPOSER_MEMORY_LIMIT=-1
- composer config repo.snowmodule git "$TRAVIS_BUILD_DIR"
- composer require -vvv $COMPOSER_PACKAGE_NAME:"dev-$TRAVIS_BRANCH" || composer require -vvv $COMPOSER_PACKAGE_NAME:"$TRAVIS_BRANCH"
# Configure for integration tests
- mysql -uroot -e 'SET @@global.sql_mode = NO_ENGINE_SUBSTITUTION; DROP DATABASE IF EXISTS magento_integration_tests; CREATE DATABASE magento_integration_tests;'
- cp dev/tests/integration/etc/install-config-mysql.travis-no-rabbitmq.php.dist dev/tests/integration/etc/install-config-mysql.php
- php $TRAVIS_BUILD_DIR/travis/prepare_phpunit_config.php

script:
- vendor/bin/phpunit -c $(pwd)/dev/tests/integration/phpunit.xml.dist --testsuite Integration

addons:
apt:
packages:
- postfix
- apache2
- libapache2-mod-fastcgi

services:
- mysql

cache:
apt: true
directories:
- $HOME/.composer/cache
- $HOME/bin

after_failure:
- test -d ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/report/ && for r in ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/report/*; do cat $r; done
- test -f ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/log/system.log && grep -v "Broken reference" ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/log/system.log
- test -f ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/log/exception.log && cat ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/log/exception.log
- test -f ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/log/support_report.log && grep -v "Broken reference" ./vendor/ampersand/travis-vanilla-magento/instances/snowmodule/var/log/support_report.log
- sleep 10;
24 changes: 13 additions & 11 deletions Test/Integration/Model/ShipmentRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,30 @@

use Magento\Sales\Api\Data\ShipmentInterface;
use Magento\Sales\Api\Data\ShipmentItemInterface;
use Magento\Sales\Api\OrderRepositoryInterface;
use Magento\Sales\Model\OrderFactory;
use Magento\TestFramework\Helper\Bootstrap;

class ShipmentRepositoryTest extends \PHPUnit_Framework_TestCase
class ShipmentRepositoryTest extends \PHPUnit\Framework\TestCase
{

private $objectManager;
/** @var OrderRepositoryInterface */
private $orderRepository;
/** @var OrderFactory */
private $orderFactory;

public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$this->objectManager = Bootstrap::getObjectManager();
$this->orderRepository = $this->objectManager->get(OrderRepositoryInterface::class);
$this->orderFactory = $this->objectManager->get(OrderFactory::class);
}

/**
* @magentoDataFixture SnowIO/ExtendedSalesRepository/Test/Integration/_files/order.php
* @magentoDataFixture SnowIO_ExtendedSalesRepositories::Test/Integration/_files/order.php
*/
public function testStandardCase()
{
$order = $this->orderRepository->get(1);

$order = $this->orderFactory->create()->loadByIncrementId('100000001');
$this->assertEquals('100000001', $order->getIncrementId(), 'The order was not loaded');
$payment = $order->getPayment();
$paymentInfoBlock = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
->get('Magento\Payment\Helper\Data')
Expand All @@ -37,9 +37,11 @@ public function testStandardCase()
/** @var ShipmentInterface $shipment */
$shipment = $this->objectManager->create(ShipmentInterface::class);
$shipment->setOrderId($order->getEntityId());
$shipmentItem = $this->objectManager->create(ShipmentItemInterface::class);
$shipmentItem->setOrderItem($order->getItems()[0]);
$shipment->addItem($shipmentItem);
foreach ($order->getItems() as $orderItem) {
$shipmentItem = $this->objectManager->create(ShipmentItemInterface::class);
$shipmentItem->setOrderItem($orderItem);
$shipment->addItem($shipmentItem);
}
$shipment->setPackages([['1'], ['2']]);
$shipment->setShipmentStatus(\Magento\Sales\Model\Order\Shipment::STATUS_NEW);
$shipment->save();
Expand Down
10 changes: 5 additions & 5 deletions Test/Integration/_files/order.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@
'sort_order' => 0,
'values' => [
[
'option_type_id' => -1,
'option_type_id' => null,
'title' => 'Option 1',
'price' => 3,
'price_type' => 'fixed',
'sku' => '3-1-select',
],
[
'option_type_id' => -1,
'option_type_id' => null,
'title' => 'Option 2',
'price' => 3,
'price_type' => 'fixed',
Expand All @@ -132,14 +132,14 @@
'sort_order' => 0,
'values' => [
[
'option_type_id' => -1,
'option_type_id' => null,
'title' => 'Option 1',
'price' => 3,
'price_type' => 'fixed',
'sku' => '4-1-radio',
],
[
'option_type_id' => -1,
'option_type_id' => null,
'title' => 'Option 2',
'price' => 3,
'price_type' => 'fixed',
Expand Down Expand Up @@ -197,7 +197,7 @@
'shipping'
)->save();

$billingAddress = $objectManager->create('Magento\Sales\Model\Order\Address', ['data' => $addressData]);
$billingAddress = $objectManager->create('Magento\Sales\Model\Order\Address', ['data' => $addressData->getData()]);
$billingAddress->setAddressType('billing');

$shippingAddress = clone $billingAddress;
Expand Down
9 changes: 8 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
}
},
"require-dev": {
"rector/rector": "^0.8.56"
"rector/rector": "^0.8.56",
"ampersand/travis-vanilla-magento": "^1.0"
},
"repositories": {
"foomanmirror": {
"type": "composer",
"url": "https://repo-magento-mirror.fooman.co.nz/"
}
}
}
35 changes: 35 additions & 0 deletions travis/prepare_phpunit_config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
set_error_handler(function ($severity, $message, $file, $line) {
throw new \ErrorException($message, $severity, $severity, $file, $line);
});

$magentoPath = getcwd();
echo "Current working directory" . $magentoPath . PHP_EOL;
if (isset($argv[1])) {
$suggestedPath = realpath($argv[1]);
if ($suggestedPath) {
$magentoPath = $suggestedPath;
}
}

if (!is_file($magentoPath . '/app/etc/di.xml')) {
throw new \Exception('Could not detect magento root: ' . $magentoPath);
}

$configPath = "$magentoPath/dev/tests/integration/phpunit.xml.dist";
$travisBuildDir = getenv('TRAVIS_BUILD_DIR');
echo "Travis build dir is $travisBuildDir" . PHP_EOL;
$packageName = \exec("composer config name -d $travisBuildDir", $output, $returnVal);
if ($returnVal!=0) {
var_dump($output);
throw new \Exception("Could not get composer config name for $travisBuildDir");
}

$config = new \SimpleXMLElement($configPath, 0, true);

unset($config->testsuites);
$testsuiteNode = $config->addChild('testsuites')->addChild('testsuite');
$testsuiteNode->addAttribute('name', 'Integration');
$testsuiteNode->addChild('directory', "$travisBuildDir/Test/Integration")->addAttribute('suffix', 'Test.php');

$config->asXML($configPath);

0 comments on commit 46aff54

Please sign in to comment.