diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 0000000..5dfe41c --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,40 @@ +# This is a basic workflow to help you get started with Actions + +name: Integration Tests + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + pull_request: + types: [opened, reopened,synchronize] + branches: + - develop + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Setup PHP with PECL extension + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + + # Runs a single command using the runners shell + - name: Run composer install + run: composer install + + # Runs a single command using the runners shell + - name: Run unit tests + run: php vendor/bin/phpunit tests/Integration \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..624e409 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,40 @@ +# This is a basic workflow to help you get started with Actions + +name: Unit Tests + +# Controls when the action will run. +on: + # Triggers the workflow on push or pull request events but only for the main branch + push: + pull_request: + types: [opened, reopened,synchronize] + branches: + - develop + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + # This workflow contains a single job called "build" + build: + # The type of runner that the job will run on + runs-on: ubuntu-latest + + # Steps represent a sequence of tasks that will be executed as part of the job + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Setup PHP with PECL extension + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + + # Runs a single command using the runners shell + - name: Run composer install + run: composer install + + # Runs a single command using the runners shell + - name: Run unit tests + run: php vendor/bin/phpunit tests/Unit \ No newline at end of file diff --git a/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/RequireCommerceCommand.php b/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/RequireCommerceCommand.php index 508129a..f960f26 100644 --- a/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/RequireCommerceCommand.php +++ b/src/Magento/ComposerRootUpdatePlugin/Plugin/Commands/RequireCommerceCommand.php @@ -51,6 +51,11 @@ class RequireCommerceCommand extends ExtendableRequireCommand */ protected $console; + /** + * @var array + */ + protected $repos; + /** * Use the native RequireCommand config with options/doc additions for the root project composer.json update * diff --git a/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php b/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php index 03f31f4..c0530fe 100644 --- a/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php +++ b/src/Magento/ComposerRootUpdatePlugin/Utils/PackageUtils.php @@ -125,7 +125,7 @@ public function getEditionLabel(string $packageEdition): ?string public function findRequire(Composer $composer, string $packageMatcher) { $requires = array_values($composer->getPackage()->getRequires()); - if (@preg_match($packageMatcher, null) === false) { + if (@preg_match($packageMatcher, '') === false) { foreach ($requires as $link) { if ($packageMatcher == $link->getTarget()) { return $link; diff --git a/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_no_override.composer.json b/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_no_override.composer.json index c514c55..8bde6ea 100644 --- a/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_no_override.composer.json +++ b/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_no_override.composer.json @@ -30,6 +30,9 @@ "vendor1/different-conflicting2": "2.0.0", "vendor1/different-conflicting3": "3.0.0" }, + "config": { + "allow-plugins": true + }, "extra": { "extra-key1": "install1", "extra-key2": "target2", diff --git a/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_override.composer.json b/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_override.composer.json index 5ca9e7a..3333647 100644 --- a/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_override.composer.json +++ b/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/expected_override.composer.json @@ -22,6 +22,9 @@ "Magento\\Sniffs\\": "dev/tests/framework/Magento/Sniffs/" } }, + "config": { + "allow-plugins": true + }, "conflict": { "vendor1/conflicting1": "1.0.0", "vendor1/conflicting2": "2.1.0", diff --git a/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/test.composer.json b/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/test.composer.json index e29e39f..210bc53 100644 --- a/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/test.composer.json +++ b/tests/Integration/Magento/ComposerRootUpdatePlugin/_files/test.composer.json @@ -37,5 +37,8 @@ "sample-data": "Suggested Sample Data 1.0.0", "vendor/suggested": "Another Suggested Package" }, + "config": { + "allow-plugins": true + }, "minimum-stability": "dev" } diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php index e9333ed..dc8327b 100644 --- a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php +++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootPackageRetrieverTest.php @@ -15,7 +15,7 @@ use Composer\Package\RootPackageInterface; use Composer\Plugin\PluginInterface; use Composer\Repository\ComposerRepository; -use Composer\Repository\RepositoryInterface; +use Composer\Repository\LockArrayRepository; use Composer\Repository\RepositoryManager; use Composer\Util\RemoteFilesystem; use Magento\ComposerRootUpdatePlugin\Utils\Console; @@ -153,7 +153,7 @@ public function testGetOriginalRootNotOnRepo_NoConfirm() public function testGetTargetRootFromRepo() { - $this->repo->expects($this->any())->method('loadPackages')->willReturn( + $this->repo->expects($this->atLeast(1))->method('loadPackages')->willReturn( [ 'namesFound' => [$this->originalRoot->getName()], 'packages' => [ @@ -210,7 +210,16 @@ protected function setUp(): void 'isLocked', 'getLockedRepository' ]); - $lockedRepo = $this->getMockForAbstractClass(RepositoryInterface::class); + $lockedRepo = $this->getMockForAbstractClass( + LockArrayRepository::class, + [], + '', + true, + true, + true, + ['getPackages'], + false + ); $originalProduct = $this->getMockForAbstractClass(PackageInterface::class); $originalProduct->method('getName')->willReturn('magento/product-enterprise-edition'); $originalProduct->method('getVersion')->willReturn('1.1.0.0'); @@ -232,11 +241,15 @@ protected function setUp(): void $this->originalRoot->method('getVersion')->willReturn('1.1.0.0'); $this->originalRoot->method('getStabilityPriority')->willReturn(0); - $this->targetRoot = $this->createPartialMock(Package::class, ['getName', 'getVersion', 'getStabilityPriority']); + $this->targetRoot = $this->createPartialMock( + Package::class, + ['getName', 'getVersion', 'getStabilityPriority', 'getPrettyVersion'] + ); $this->targetRoot->id = 2; $this->targetRoot->method('getName')->willReturn('magento/project-enterprise-edition'); $this->targetRoot->method('getVersion')->willReturn('2.0.0.0'); $this->targetRoot->method('getStabilityPriority')->willReturn(0); + $this->targetRoot->method('getPrettyVersion')->willReturn(''); $repoManager = $this->createPartialMock(RepositoryManager::class, ['getRepositories']); if ($apiMajorVersion == '1') { diff --git a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootProjectUpdaterTest.php b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootProjectUpdaterTest.php index c878e8c..1edfa2f 100644 --- a/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootProjectUpdaterTest.php +++ b/tests/Unit/Magento/ComposerRootUpdatePlugin/Updater/RootProjectUpdaterTest.php @@ -16,6 +16,7 @@ use Composer\Package\Package; use Composer\Package\RootPackage; use Composer\Repository\ComposerRepository; +use Composer\Repository\LockArrayRepository; use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryManager; use Composer\Semver\Constraint\Constraint; @@ -273,7 +274,16 @@ public function setUp(): void $repo = $this->createPartialMock(ComposerRepository::class, []); $repoManager = $this->createPartialMock(RepositoryManager::class, ['getRepositories']); $repoManager->method('getRepositories')->willReturn([$repo]); - $lockedRepo = $this->getMockForAbstractClass(RepositoryInterface::class); + $lockedRepo = $this->getMockForAbstractClass( + LockArrayRepository::class, + [], + '', + true, + true, + true, + ['getPackages'], + false + ); $lockedRepo->method('getPackages')->willReturn([ new Package('magento/product-community-edition', '1.0.0.0', '1.0.0') ]);