Skip to content

Commit

Permalink
Merge pull request #50 from AmpersandHQ/test-third-party-modules
Browse files Browse the repository at this point in the history
Test third party modules (fix issue #5)
  • Loading branch information
convenient authored Mar 16, 2021
2 parents 6f50927 + 63cf92d commit 89edb2c
Show file tree
Hide file tree
Showing 35 changed files with 443 additions and 161 deletions.
11 changes: 11 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('dev/instances')
->exclude('dev/phpunit/unit/resources/')
->in(__DIR__)
;

$config = new PhpCsFixer\Config();
$config->setUsingCache(false);
return $config->setFinder($finder);
24 changes: 12 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ env:
- TEST_GROUP=22
- TEST_GROUP=23
- TEST_GROUP=24
- TEST_GROUP=24nodb

before_install:
- phpenv config-rm xdebug.ini || true
Expand All @@ -14,24 +15,23 @@ install:
- composer self-update 1.10.16
- composer install
# Run static analysis tests before trying to install the modules in magento
- vendor/bin/php-cs-fixer fix --dry-run --diff src/
- vendor/bin/php-cs-fixer fix --dry-run --diff dev/phpunit
- vendor/bin/php-cs-fixer fix --dry-run --diff dev/TestModule
- vendor/bin/php-cs-fixer fix --dry-run --diff dev/TestVendorModule
- vendor/bin/php-cs-fixer fix --diff --dry-run
# Run unit tests before trying to install magento
- vendor/bin/phpunit -c dev/phpunit/unit/phpunit.xml --verbose;
- cd dev
- if [[ $TEST_GROUP = 22 ]]; then phpenv global 7.2; fi
- if [[ $TEST_GROUP = 22 ]]; then ./setup-magento-with-diff.sh 2.2.0 2.2.11 $TEST_GROUP; fi
- if [[ $TEST_GROUP = 23 ]]; then phpenv global 7.2; fi
- if [[ $TEST_GROUP = 23 ]]; then ./setup-magento-with-diff.sh 2.3.0 2.3.6-p1 $TEST_GROUP; fi
- if [[ $TEST_GROUP = 24 ]]; then ./setup-magento-with-diff.sh 2.3.5 2.4.2 $TEST_GROUP; fi
- if [[ $TEST_GROUP = 22 ]]; then phpenv global 7.2; fi
- if [[ $TEST_GROUP = 22 ]]; then ./setup-magento-with-diff.sh 2.2.0 2.2.11 $TEST_GROUP; fi
- if [[ $TEST_GROUP = 23 ]]; then phpenv global 7.2; fi
- if [[ $TEST_GROUP = 23 ]]; then ./setup-magento-with-diff.sh 2.3.0 2.3.6-p1 $TEST_GROUP; fi
- if [[ $TEST_GROUP = 24 ]]; then ./setup-magento-with-diff.sh 2.3.5 2.4.2 $TEST_GROUP; fi
- if [[ $TEST_GROUP = 24nodb ]]; then NODB=1 ./setup-magento-with-diff.sh 2.3.5 2.4.2 $TEST_GROUP; fi
- cd -

script:
- if [[ $TEST_GROUP = 22 ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v23,v24 --verbose; fi
- if [[ $TEST_GROUP = 23 ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v22,v24 --verbose; fi
- if [[ $TEST_GROUP = 24 ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v22,v23 --verbose; fi
- if [[ $TEST_GROUP = 22 ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v23,v24,v24nodb --verbose; fi
- if [[ $TEST_GROUP = 23 ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v22,v24,v24nodb --verbose; fi
- if [[ $TEST_GROUP = 24 ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v22,v23,v24nodb --verbose; fi
- if [[ $TEST_GROUP = 24nodb ]]; then vendor/bin/phpunit -c dev/phpunit/functional/phpunit.xml --exclude-group=v22,v23,v24 --verbose; fi

services:
- mysql
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ampersand-magento2-upgrade-patch-helper

Helper scripts to aid upgrading magento 2 websites
Helper scripts to aid upgrading magento 2 websites, or when upgrading a magento module

[![Build Status](https://travis-ci.org/AmpersandHQ/ampersand-magento2-upgrade-patch-helper.svg?branch=master)](https://travis-ci.org/AmpersandHQ/ampersand-magento2-upgrade-patch-helper)

Expand All @@ -14,10 +14,6 @@ This tool checks for
- html (knockout templates)
- Plugins for methods which have been affected by the upgrade.

## ⚠️ Warning ⚠️

This tool is experimental and a work in progress. It may not catch every preference/override/etc.

If you have any improvements please raise a PR or an Issue.

## How to use
Expand All @@ -26,7 +22,7 @@ All the below should be used on a local setup, never do any of this anywhere nea

It is most reliable if you use this when the instance has been built and is plugged into a database just in case you have theme configuration stored there. Running this without it being plugged into a database could cause some of the theme analysis to be missed.

### Step 1 - Update the Magento core with dependencies then generate a patch
### Step 1 - Composer update the dependencies then generate a patch

In your project `composer install` and move the original vendor directory to a backup location

Expand All @@ -36,13 +32,14 @@ composer install
mv vendor/ vendor_orig/
```

Update your magento version to the one required, with b2b or other extensions if applicable.
Update your magento version (or third party module) to the one required, with b2b or other extensions if applicable.

```bash
composer install
composer require magento/product-enterprise-edition 2.2.6 --no-update
composer require magento/extension-b2b 1.0.6 --no-update
composer update magento/extension-b2b magento/product-enterprise-edition --with-dependencies
composer require thirdparty/some-module "^2.0"
composer update magento/extension-b2b magento/product-enterprise-edition thirdparty/some-module --with-dependencies
```

At this point you may receive errors of incompatible modules, often they are tied to a specific version of magento. Correct the module dependencies and composer require the updated version until you can run `composer install` successfully.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Ampersand\Test\Model\Locale;

class Format extends \Magento\Framework\Locale\Format
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
namespace Ampersand\Test\Model;

class ThirdPartyClass extends \Ampersand\TestVendor\Model\SomeClass
{
}
10 changes: 10 additions & 0 deletions dev/TestModule/app/code/Ampersand/Test/Plugin/PhpCookieManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
namespace Ampersand\Test\Plugin;

class PhpCookieManager
{
public function beforeSetPublicCookie($subject, $name, $value, PublicCookieMetadata $metadata = null)
{
return [$name, $value, $metadata];
}
}
2 changes: 2 additions & 0 deletions dev/TestModule/app/code/Ampersand/Test/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<preference for="Magento\AdvancedPricingImportExport\Model\Export\AdvancedPricing" type="Ampersand\Test\Model\Admin\Export\AdvancedPricing" />
<preference for="Magento\Authorizenet\Model\Directpost" type="Ampersand\Test\Model\Directpost" />
<preference for="Magento\Weee\Model\Total\Quote\Weee" type="Ampersand\Test\Model\Total\Quote\Weee" />
<preference for="Ampersand\TestVendor\Model\SomeClass" type="Ampersand\Test\Model\ThirdPartyClass" />
<preference for="Magento\Framework\Locale\Format" type="Ampersand\Test\Model\Locale\Format" />

<type name="Magento\Sales\Block\Adminhtml\Order\Create\Form">
<plugin name="AmpersandTestPluginBeforeAfterAround" type="Ampersand\Test\Block\Plugin\OrderCreateFormPlugin" sortOrder="1" />
Expand Down
3 changes: 3 additions & 0 deletions dev/TestModule/app/code/Ampersand/Test/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
<preference for="Magento\Authorizenet\Model\Directpost" type="Ampersand\Test\Model\Frontend\Directpost" />
<preference for="Magento\Weee\Model\Total\Quote\Weee" type="Ampersand\Test\Model\Frontend\Total\Quote\Weee" />

<type name="Magento\Framework\Stdlib\Cookie\PhpCookieManager">
<plugin name="examplePlugin" type="Ampersand\Test\Plugin\PhpCookieManager" />
</type>
</config>
1 change: 1 addition & 0 deletions dev/TestModule/app/code/Ampersand/Test/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ampersand_Test" active="true" setup_version="1.0.0">
<sequence>
<module name="Ampersand_TestVendor"/>
<module name="Magento_AdvancedPricing"/>
<module name="Magento_Theme"/>
</sequence>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- template override -->
2 changes: 1 addition & 1 deletion dev/TestVendorModule/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"src/registration.php"
],
"psr-4": {
"Ampersand\\TestVendor\\": "src"
"Ampersand\\TestVendor\\": "src/module"
}
}
}
7 changes: 7 additions & 0 deletions dev/TestVendorModule/src/module/Model/SomeClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace Ampersand\TestVendor\Model;

class SomeClass
{
// Dummy class to be overridden
}
10 changes: 10 additions & 0 deletions dev/TestVendorModule/src/module/etc/module.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ampersand_TestVendor" active="true" setup_version="1.0.0">
<sequence>
<module name="Magento_Theme"/>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- -->
8 changes: 7 additions & 1 deletion dev/TestVendorModule/src/registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
ComponentRegistrar::register(
ComponentRegistrar::THEME,
'frontend/AmpersandVendor/theme',
__DIR__
__DIR__ . '/theme'
);

ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Ampersand_TestVendor',
__DIR__ . '/module'
);
File renamed without changes.
19 changes: 19 additions & 0 deletions dev/phpunit/functional/FunctionalTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,25 @@ public function testMagentoTwoFourVirtualPlugin()
$this->assertEquals(0, $return, "The return code of the command was not zero");
}

/**
* @group v24nodb
*/
public function testMagentoTwoFourNoDb()
{
$this->assertFileExists(BASE_DIR . '/dev/instances/magento24nodb/app/etc/di.xml', "Magento 2.4 directory is wrong");
$this->assertFileNotExists(BASE_DIR . '/dev/instances/magento24nodb/app/etc/env.php', "Magento 2.4 is installed when it shouldnt be");

exec($this->generateAnalyseCommand('/dev/instances/magento24nodb', '--sort-by-type --vendor-namespaces Ampersand'), $output, $return);
$this->assertEquals(0, $return, "The return code of the command was not zero");

$lastLine = array_pop($output);
$this->assertStringStartsWith('You should review the above', $lastLine);

$output = implode(PHP_EOL, $output);

$this->assertEquals($this->fileGetContents('/dev/phpunit/functional/expected_output/magento24nodb.out.txt'), $output);
}

/**
* @param $filepath
* @return string
Expand Down
Loading

0 comments on commit 89edb2c

Please sign in to comment.