diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000..595f673 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,49 @@ +name: Rector + +on: [push, pull_request] + +jobs: + rector: + name: Rector + runs-on: [ubuntu-latest] + + steps: + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.1 + + - name: Checkout code + uses: actions/checkout@v5 + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache dependencies + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install dependencies + run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-* + + - name: Restore result cache + uses: actions/cache/restore@v4 + with: + path: .rector.result.cache + key: rector-result-cache-${{ github.run_id }} + restore-keys: | + rector-result-cache- + + - name: Rector + run: php vendor/bin/rector process --config .rector.php --dry-run + + - name: Save result cache + uses: actions/cache/save@v4 + if: always() + with: + path: .rector.result.cache + key: rector-result-cache-${{ github.run_id }} diff --git a/.gitignore b/.gitignore index fc32c58..2acd102 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ /vendor /.phpstan.cache /.phpunit.cache +/.rector.result.cache .php-cs-fixer.cache .phpmd.result-cache.php composer.lock diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 7675a54..930aa14 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -9,7 +9,7 @@ 'modernize_types_casting' => true, 'nullable_type_declaration_for_default_null_value' => true, 'single_quote' => true, - 'php_unit_test_case_static_method_calls' => true, + 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'], 'trailing_comma_in_multiline' => ['after_heredoc' => true, 'elements' => ['arguments', 'array_destructuring', 'arrays']], ]) ->setFinder( diff --git a/.rector.php b/.rector.php new file mode 100644 index 0000000..e0835aa --- /dev/null +++ b/.rector.php @@ -0,0 +1,47 @@ +withFileExtensions(['php']) + ->withCache( + cacheDirectory: '.rector.result.cache', + cacheClass: FileCacheStorage::class, + ) + ->withPhpSets( + php81: true, + ) + ->withPaths([ + __DIR__, + ]) + ->withSkipPath(__DIR__ . '/vendor') + ->withSkip([ + # skip: use static methods + PreferPHPUnitThisCallRector::class + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + naming: true, + instanceOf: true, + earlyReturn: true, + strictBooleans: false, + carbon: true, + rectorPreset: true, + phpunitCodeQuality: true, + doctrineCodeQuality: false, + symfonyCodeQuality: false, + symfonyConfigs: false, + ); +} catch (InvalidConfigurationException $exception) { + echo $exception->getMessage(); + exit(1); +} diff --git a/composer.json b/composer.json index 705353f..8b94696 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "phpstan/phpstan-phpunit": "^2.0", "phpunit/phpunit": "^9.6", "phpmd/phpmd": "^2.15", - "friendsofphp/php-cs-fixer": "^3.67" + "friendsofphp/php-cs-fixer": "^3.67", + "rector/rector": "^2.1.2" }, "extra": { "class": "OpenMage\\ComposerPlugin\\Plugin" @@ -46,7 +47,9 @@ "phpstan:baseline": "XDEBUG_MODE=off php vendor/bin/phpstan analyze -b .phpstan.dist.baseline.neon", "phpunit:test": "XDEBUG_MODE=off php vendor/bin/phpunit --configuration .phpunit.dist.xml --no-coverage", "phpunit:coverage": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --testdox", - "phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage-composer-plugin --testdox" + "phpunit:coverage-local": "XDEBUG_MODE=coverage php vendor/bin/phpunit --configuration .phpunit.dist.xml --coverage-html build/coverage-composer-plugin --testdox", + "rector:test": "vendor/bin/rector process --config .rector.php --dry-run", + "rector:fix": "vendor/bin/rector process --config .rector.php" }, "scripts-descriptions": { "php-cs-fixer:test": "Run php-cs-fixer", @@ -56,7 +59,9 @@ "phpstan:baseline": "Run phpstan and update baseline", "phpunit:test": "Run PHPUnit", "phpunit:coverage": "Run PHPUnit with code coverage (requires XDEBUG enabled)", - "phpunit:coverage-local": "Run PHPUnit with local HTML code coverage (requires XDEBUG enabled)" + "phpunit:coverage-local": "Run PHPUnit with local HTML code coverage (requires XDEBUG enabled)", + "rector:test": "Run rector", + "rector:fix": "Run rector and fix issues" }, "funding": [ { diff --git a/src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php b/src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php index 1ab8a48..45821ca 100644 --- a/src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php +++ b/src/OpenMage/ComposerPlugin/Copy/AbstractCopyPlugin.php @@ -59,7 +59,7 @@ public function __construct(?Event $event) public function processComposerInstall(): void { $package = $this->getComposerPackage(); - if (!$package || !$this instanceof CopyFromComposerInterface) { + if (!$package instanceof BasePackage || !$this instanceof CopyFromComposerInterface) { return; } @@ -74,13 +74,14 @@ public function processComposerInstall(): void $filesystem = $this->getFileSystem(); if (!$filesystem->exists($copySourcePath) && $this instanceof CopyFromUnpkgInterface) { - if ($event && $event->getIO()->isVerbose()) { + if ($event instanceof Event && $event->getIO()->isVerbose()) { $event->getIO()->write(sprintf( 'Fallback to Unpkg %s for %s', $this->getUnpkgName(), $this->getComposerName(), )); } + $this->processUnpkgInstall(); return; } @@ -96,11 +97,11 @@ public function processComposerInstall(): void try { $filesystem->copy($copySource, $copytarget); - if ($event && $event->getIO()->isVeryVerbose()) { + if ($event instanceof Event && $event->getIO()->isVeryVerbose()) { $event->getIO()->write(sprintf('Copy %s to %s', $copySource, $copytarget)); } } catch (IOException $exception) { - if ($event) { + if ($event instanceof Event) { $event->getIO()->write($exception->getMessage()); } } @@ -119,7 +120,7 @@ public function processUnpkgInstall(): void $event = $this->getEvent(); $sourcePath = $this->getUnpkSourcePath(); - if ($event && $event->getIO()->isVerbose()) { + if ($event instanceof Event && $event->getIO()->isVerbose()) { $event->getIO()->write(sprintf( 'Trying to download %s %s from %s', $this->getUnpkgName(), @@ -133,29 +134,32 @@ public function processUnpkgInstall(): void try { $content = file_get_contents($sourceFilePath); } catch (ErrorException $errorException) { - if ($event) { + if ($event instanceof Event) { $event->getIO()->write($errorException->getMessage()); } + return; } if (!$content) { - if ($event) { + if ($event instanceof Event) { $event->getIO()->write(sprintf('Could not read from %s', $sourceFilePath)); } + return; } try { $targetFilePath = $this->getCopyTargetPath() . '/' . $fileName; $this->getFileSystem()->dumpFile($targetFilePath, $content); - if ($event && $event->getIO()->isVerbose()) { + if ($event instanceof Event && $event->getIO()->isVerbose()) { $event->getIO()->write(sprintf('Added %s', $targetFilePath)); } } catch (IOException $exception) { - if ($event) { + if ($event instanceof Event) { $event->getIO()->write($exception->getMessage()); } + return; } } @@ -169,27 +173,29 @@ public function getComposerPackage(): ?BasePackage $vendorName = $this->getComposerName(); $module = $this->getInstalledComposerPackage($vendorName); - if ($module) { + if ($module instanceof BasePackage) { return $module; } $event = $this->getEvent(); - if (!$event) { + if (!$event instanceof Event) { return null; } $locker = $event->getComposer()->getLocker(); - $repo = $locker->getLockedRepository(); + $lockArrayRepository = $locker->getLockedRepository(); - foreach ($repo->getPackages() as $package) { - if ($package->getName() === $vendorName) { - $this->setInstalledComposerPackage($vendorName, $package); + foreach ($lockArrayRepository->getPackages() as $basePackage) { + if ($basePackage->getName() === $vendorName) { + $this->setInstalledComposerPackage($vendorName, $basePackage); if ($event->getIO()->isVerbose()) { - $event->getIO()->write(sprintf('%s found with version %s', $vendorName, $package->getVersion())); + $event->getIO()->write(sprintf('%s found with version %s', $vendorName, $basePackage->getVersion())); } + return $this->getInstalledComposerPackage($vendorName); } } + return null; } @@ -202,8 +208,9 @@ protected function getUnpkSourcePath(): string $search = ['{{package}}', '{{version}}']; $replace = [$this->getUnpkgName(), $this->getUnpkgVersion()]; $path = str_replace($search, $replace, CopyFromUnpkgInterface::UNPKG_URL); - return $path . ($this->getUnpkgSource() ? $this->getUnpkgSource() . '/' : ''); + return $path . ($this->getUnpkgSource() !== '' && $this->getUnpkgSource() !== '0' ? $this->getUnpkgSource() . '/' : ''); } + return ''; } @@ -216,6 +223,7 @@ protected function getCwd(): string if ($cwd === false) { throw new Exception('This should not happen.'); } + return $cwd; } @@ -225,7 +233,7 @@ protected function getCwd(): string protected function getVendorDirectoryFromComposer(): string { $event = $this->getEvent(); - if (!$event) { + if (!$event instanceof Event) { return ''; } @@ -240,22 +248,20 @@ protected function getVendorDirectoryFromComposer(): string protected function getMageRootDirectoryFromComposer(): string { $event = $this->getEvent(); - if (!$event) { + if (!$event instanceof Event) { return ''; } $composerExtra = $event->getComposer()->getPackage()->getExtra(); - $magentoRootDir = ''; - if (array_key_exists(self::EXTRA_MAGENTO_ROOT_DIR, $composerExtra) && - $composerExtra[self::EXTRA_MAGENTO_ROOT_DIR] !== '.' - ) { - $magentoRootDir = $composerExtra[self::EXTRA_MAGENTO_ROOT_DIR] . '/'; + $composerExtra[self::EXTRA_MAGENTO_ROOT_DIR] !== '.') { + return $composerExtra[self::EXTRA_MAGENTO_ROOT_DIR] . '/'; } - return $magentoRootDir; + + return ''; } - private function getCopyTargetPath(): string + protected function getCopyTargetPath(): string { return sprintf( '%s/%s%s', @@ -270,9 +276,9 @@ protected function getInstalledComposerPackage(string $vendorName): ?BasePackage return $this->composerPackages[$vendorName] ?? null; } - private function setInstalledComposerPackage(string $vendorName, BasePackage $package): void + protected function setInstalledComposerPackage(string $vendorName, BasePackage $basePackage): void { - $this->composerPackages[$vendorName] = $package; + $this->composerPackages[$vendorName] = $basePackage; } public function getFileSystem(): Filesystem diff --git a/src/OpenMage/ComposerPlugin/Copy/CopyInterface.php b/src/OpenMage/ComposerPlugin/Copy/CopyInterface.php index 6f292d1..9ce67ee 100644 --- a/src/OpenMage/ComposerPlugin/Copy/CopyInterface.php +++ b/src/OpenMage/ComposerPlugin/Copy/CopyInterface.php @@ -17,7 +17,9 @@ interface CopyInterface { public const EXTRA_MAGENTO_ROOT_DIR = 'magento-root-dir'; + public const EXTRA_UNPKG_PACKAGES = 'openmage-unpkg-packages'; + public const VENDOR_DIR = 'vendor-dir'; public function getCopyTarget(): string; diff --git a/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMce.php b/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMce.php index 553eb09..788ecbd 100644 --- a/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMce.php +++ b/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMce.php @@ -21,6 +21,7 @@ class TinyMce extends Copy\AbstractCopyPlugin implements Copy\CopyFromComposerInterface { public const TINYMCE_LICENSE_FILE = 'LICENSE_TINYMCE.txt'; + public const TINYMCE_LICENSE_NOTE = 'LICENSE_TINYMCE_OPENMAGE.txt'; public const TINYMCE_LICENSE_FILE_TEXT = <<getComposerPackage(); if (!$package instanceof BasePackage) { + $this->removedTinyMceLicenseFiles(); return; } $version = $package->getVersion(); - switch ((int) $version[0]) { + $versionParts = explode('.', $version); + $versionMain = (int) $versionParts[0]; + + switch ($versionMain) { case 6: $this->removedTinyMceLicenseFiles(); break; - case 7: + default: $this->addTinyMceLicenseFile(); $this->addTinyMceLicenseNote(); break; @@ -90,9 +95,9 @@ private function addTinyMceLicenseFile(): void if (!is_null($this->event) && $this->event->getIO()->isVerbose()) { $this->event->getIO()->write(sprintf('Added %s', self::TINYMCE_LICENSE_FILE)); } - } catch (IOException $exception) { + } catch (IOException $ioException) { if (!is_null($this->event)) { - $this->event->getIO()->write($exception->getMessage()); + $this->event->getIO()->write($ioException->getMessage()); } } } @@ -111,9 +116,9 @@ private function addTinyMceLicenseNote(): void if (!is_null($this->event) && $this->event->getIO()->isVerbose()) { $this->event->getIO()->write(sprintf('Added %s', self::TINYMCE_LICENSE_NOTE)); } - } catch (IOException $exception) { + } catch (IOException $ioException) { if (!is_null($this->event)) { - $this->event->getIO()->write($exception->getMessage()); + $this->event->getIO()->write($ioException->getMessage()); } } } @@ -130,9 +135,9 @@ private function removedTinyMceLicenseFiles(): void if (!is_null($this->event) && $this->event->getIO()->isVeryVerbose()) { $this->event->getIO()->write(sprintf('Removed %s and %s', self::TINYMCE_LICENSE_FILE, self::TINYMCE_LICENSE_NOTE)); } - } catch (IOException $exception) { + } catch (IOException $ioException) { if (!is_null($this->event)) { - $this->event->getIO()->write($exception->getMessage()); + $this->event->getIO()->write($ioException->getMessage()); } } } diff --git a/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMceLanguages.php b/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMceLanguages.php index c69b270..7ed8da3 100644 --- a/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMceLanguages.php +++ b/src/OpenMage/ComposerPlugin/Copy/Plugins/TinyMceLanguages.php @@ -54,6 +54,7 @@ public function processComposerInstall(): void if (!InstalledVersions::isInstalled(self::TINYMCE)) { return; } + parent::processComposerInstall(); } } diff --git a/src/OpenMage/ComposerPlugin/Copy/Unpkg/Config.php b/src/OpenMage/ComposerPlugin/Copy/Unpkg/Config.php index 8aa1080..7eb744b 100644 --- a/src/OpenMage/ComposerPlugin/Copy/Unpkg/Config.php +++ b/src/OpenMage/ComposerPlugin/Copy/Unpkg/Config.php @@ -19,13 +19,19 @@ class Config implements Copy\CopyFromUnpkgInterface { public const CONFIG_FILES = 'files'; + public const CONFIG_SOURCE = 'source'; + public const CONFIG_TARGET = 'target'; + public const CONFIG_VERSION = 'version'; private string $name = ''; + private string $version = ''; + private string $source = ''; + private string $target = ''; /** @@ -75,6 +81,7 @@ private function validateConfigFiles(array $packageConfig): ?array $files = $packageConfig[self::CONFIG_FILES]; return $files; } + return null; } @@ -86,6 +93,7 @@ private function validateConfigVersion(array $packageConfig): ?string if (array_key_exists(self::CONFIG_VERSION, $packageConfig) && is_string($packageConfig[self::CONFIG_VERSION])) { return trim($packageConfig[self::CONFIG_VERSION]); } + return null; } @@ -97,6 +105,7 @@ private function validateConfigSource(array $packageConfig): string if (array_key_exists(self::CONFIG_SOURCE, $packageConfig) && is_string($packageConfig[self::CONFIG_SOURCE])) { return trim($packageConfig[self::CONFIG_SOURCE]); } + return ''; } @@ -109,6 +118,7 @@ private function validateConfigTarget(array $packageConfig): string $target = str_replace(['../', './'], '', $packageConfig[self::CONFIG_TARGET]); return trim($target); } + return ''; } diff --git a/src/OpenMage/ComposerPlugin/Plugin.php b/src/OpenMage/ComposerPlugin/Plugin.php index bfc713f..0782bc9 100644 --- a/src/OpenMage/ComposerPlugin/Plugin.php +++ b/src/OpenMage/ComposerPlugin/Plugin.php @@ -86,6 +86,7 @@ public function processCopy(?Event $event): void $pluginLoaded->processComposerInstall(); continue; } + if ($pluginLoaded instanceof Copy\AbstractCopyPlugin && $pluginLoaded instanceof Copy\CopyFromUnpkgInterface ) { @@ -93,14 +94,14 @@ public function processCopy(?Event $event): void continue; } - if ($this->io) { + if ($this->io instanceof IOInterface) { $this->io->write('Could not load ' . $plugin); } } $plugins = $this->getUnpkgPackagesFromConfig(); - foreach ($plugins as $pluginConfig) { - $pluginLoaded = new Generic($event, $pluginConfig); + foreach ($plugins as $plugin) { + $pluginLoaded = new Generic($event, $plugin); $pluginLoaded->processUnpkgInstall(); } } @@ -125,9 +126,10 @@ private function getUnpkgPackagesFromConfig(): array $config = $extra[CopyInterface::EXTRA_UNPKG_PACKAGES]; if (!is_array($config)) { - if ($this->io) { + if ($this->io instanceof IOInterface) { $this->io->write(sprintf('Configuration is invalid for %s', CopyInterface::EXTRA_UNPKG_PACKAGES)); } + return $packages; } @@ -135,9 +137,10 @@ private function getUnpkgPackagesFromConfig(): array $config = new Config(); $packageConfig = $config->getValidatedConfig($packageConfig); if (!$packageConfig) { - if ($this->io) { + if ($this->io instanceof IOInterface) { $this->io->write(sprintf('Configuration is invalid for %s', $packageName)); } + continue; } @@ -150,6 +153,7 @@ private function getUnpkgPackagesFromConfig(): array $packages[] = $config; } + return $packages; } @@ -163,6 +167,7 @@ private function getPlugins(string $path): array foreach ($filenames as $filename) { $namespaces[] = $this->getFullNamespace($filename) . '\\' . $this->getClassName($filename); } + return $namespaces; } @@ -198,6 +203,7 @@ private function getFilenames(string $path): array foreach ($finderFiles as $finderFile) { $filenames[] = $finderFile->getRealPath(); } + return $filenames; } } diff --git a/tests/unit/Copy/AbstractCopyPluginTest.php b/tests/unit/Copy/AbstractCopyPluginTest.php index 878b998..283c4da 100644 --- a/tests/unit/Copy/AbstractCopyPluginTest.php +++ b/tests/unit/Copy/AbstractCopyPluginTest.php @@ -21,11 +21,11 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Filesystem; -class AbstractCopyPluginTest extends TestCase +final class AbstractCopyPluginTest extends TestCase { - public Subject $subject; + public \PHPUnit\Framework\MockObject\MockObject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = $this->getMockForAbstractClass(Subject::class, [], '', false); } @@ -35,6 +35,6 @@ public function setUp(): void */ public function testGetFileSystem(): void { - static::assertInstanceOf(Filesystem::class, $this->subject->getFileSystem()); + self::assertInstanceOf(Filesystem::class, $this->subject->getFileSystem()); } } diff --git a/tests/unit/Copy/Plugins/ChartJsTest.php b/tests/unit/Copy/Plugins/ChartJsTest.php index f37ad4d..d88fe8a 100644 --- a/tests/unit/Copy/Plugins/ChartJsTest.php +++ b/tests/unit/Copy/Plugins/ChartJsTest.php @@ -21,11 +21,11 @@ use OutOfBoundsException; use PHPUnit\Framework\TestCase; -class ChartJsTest extends TestCase +final class ChartJsTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -35,7 +35,7 @@ public function setUp(): void */ public function testGetUnpkgName(): void { - static::assertSame('chart.js', $this->subject->getUnpkgName()); + self::assertSame('chart.js', $this->subject->getUnpkgName()); } /** @@ -45,9 +45,9 @@ public function testGetUnpkgName(): void public function testGetUnpkgVersion(): void { try { - static::assertIsString($this->subject->getUnpkgVersion()); - } catch (OutOfBoundsException $exception) { - static::assertSame('Package "nnnick/chartjs" is not installed', $exception->getMessage()); + self::assertIsString($this->subject->getUnpkgVersion()); + } catch (OutOfBoundsException $outOfBoundsException) { + self::assertSame('Package "nnnick/chartjs" is not installed', $outOfBoundsException->getMessage()); } } @@ -56,7 +56,7 @@ public function testGetUnpkgVersion(): void */ public function testGetUnpkgSource(): void { - static::assertSame('dist', $this->subject->getUnpkgSource()); + self::assertSame('dist', $this->subject->getUnpkgSource()); } @@ -71,7 +71,7 @@ public function testGetUnpkgFiles(): void 2 => 'helpers.js', 3 => 'helpers.js.map', ]; - static::assertSame($result, $this->subject->getUnpkgFiles()); + self::assertSame($result, $this->subject->getUnpkgFiles()); } /** @@ -79,7 +79,7 @@ public function testGetUnpkgFiles(): void */ public function testGetComposerName(): void { - static::assertSame('nnnick/chartjs', $this->subject->getComposerName()); + self::assertSame('nnnick/chartjs', $this->subject->getComposerName()); } /** @@ -87,7 +87,7 @@ public function testGetComposerName(): void */ public function testGetComposerSource(): void { - static::assertSame('dist', $this->subject->getComposerSource()); + self::assertSame('dist', $this->subject->getComposerSource()); } /** @@ -95,7 +95,7 @@ public function testGetComposerSource(): void */ public function testGetComposerFiles(): void { - static::assertSame(['*.js', '*.map'], $this->subject->getComposerFiles()); + self::assertSame(['*.js', '*.map'], $this->subject->getComposerFiles()); } /** @@ -103,6 +103,6 @@ public function testGetComposerFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('js/lib/chartjs', $this->subject->getCopyTarget()); + self::assertSame('js/lib/chartjs', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/Copy/Plugins/FlatpickrTest.php b/tests/unit/Copy/Plugins/FlatpickrTest.php index a900916..2629815 100644 --- a/tests/unit/Copy/Plugins/FlatpickrTest.php +++ b/tests/unit/Copy/Plugins/FlatpickrTest.php @@ -21,11 +21,11 @@ use OutOfBoundsException; use PHPUnit\Framework\TestCase; -class FlatpickrTest extends TestCase +final class FlatpickrTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -35,7 +35,7 @@ public function setUp(): void */ public function testGetUnpkgName(): void { - static::assertSame('flatpickr', $this->subject->getUnpkgName()); + self::assertSame('flatpickr', $this->subject->getUnpkgName()); } /** @@ -44,9 +44,9 @@ public function testGetUnpkgName(): void public function testGetUnpkgVersion(): void { try { - static::assertIsString($this->subject->getUnpkgVersion()); - } catch (OutOfBoundsException $exception) { - static::assertSame('Package "nnnick/chartjs" is not installed', $exception->getMessage()); + self::assertIsString($this->subject->getUnpkgVersion()); + } catch (OutOfBoundsException $outOfBoundsException) { + self::assertSame('Package "nnnick/chartjs" is not installed', $outOfBoundsException->getMessage()); } } @@ -55,7 +55,7 @@ public function testGetUnpkgVersion(): void */ public function testGetUnpkgSource(): void { - static::assertSame('dist', $this->subject->getUnpkgSource()); + self::assertSame('dist', $this->subject->getUnpkgSource()); } /** @@ -67,7 +67,7 @@ public function testGetUnpkgFiles(): void 0 => 'flatpickr.min.css', 1 => 'flatpickr.min.js', ]; - static::assertSame($result, $this->subject->getUnpkgFiles()); + self::assertSame($result, $this->subject->getUnpkgFiles()); } /** @@ -75,6 +75,6 @@ public function testGetUnpkgFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('js/lib/flatpickr', $this->subject->getCopyTarget()); + self::assertSame('js/lib/flatpickr', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/Copy/Plugins/FlowJsTest.php b/tests/unit/Copy/Plugins/FlowJsTest.php index 3b537c6..f2382b0 100644 --- a/tests/unit/Copy/Plugins/FlowJsTest.php +++ b/tests/unit/Copy/Plugins/FlowJsTest.php @@ -20,11 +20,11 @@ use OpenMage\ComposerPlugin\Copy\Plugins\FlowJs as Subject; use PHPUnit\Framework\TestCase; -class FlowJsTest extends TestCase +final class FlowJsTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -34,7 +34,7 @@ public function setUp(): void */ public function testGetComposerName(): void { - static::assertSame('flowjs/flowjs', $this->subject->getComposerName()); + self::assertSame('flowjs/flowjs', $this->subject->getComposerName()); } /** @@ -42,7 +42,7 @@ public function testGetComposerName(): void */ public function testGetComposerSource(): void { - static::assertSame('dist', $this->subject->getComposerSource()); + self::assertSame('dist', $this->subject->getComposerSource()); } /** @@ -50,7 +50,7 @@ public function testGetComposerSource(): void */ public function testGetComposerFiles(): void { - static::assertSame(['*.js'], $this->subject->getComposerFiles()); + self::assertSame(['*.js'], $this->subject->getComposerFiles()); } /** @@ -58,6 +58,6 @@ public function testGetComposerFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('js/lib/uploader', $this->subject->getCopyTarget()); + self::assertSame('js/lib/uploader', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/Copy/Plugins/JQueryTest.php b/tests/unit/Copy/Plugins/JQueryTest.php index 4ea3dc1..7fb9aac 100644 --- a/tests/unit/Copy/Plugins/JQueryTest.php +++ b/tests/unit/Copy/Plugins/JQueryTest.php @@ -20,11 +20,11 @@ use OpenMage\ComposerPlugin\Copy\Plugins\JQuery as Subject; use PHPUnit\Framework\TestCase; -class JQueryTest extends TestCase +final class JQueryTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -34,7 +34,7 @@ public function setUp(): void */ public function testGetComposerName(): void { - static::assertSame('components/jquery', $this->subject->getComposerName()); + self::assertSame('components/jquery', $this->subject->getComposerName()); } /** @@ -42,7 +42,7 @@ public function testGetComposerName(): void */ public function testGetComposerSource(): void { - static::assertSame('', $this->subject->getComposerSource()); + self::assertSame('', $this->subject->getComposerSource()); } /** @@ -50,7 +50,7 @@ public function testGetComposerSource(): void */ public function testGetComposerFiles(): void { - static::assertSame(['*.js', '*.map'], $this->subject->getComposerFiles()); + self::assertSame(['*.js', '*.map'], $this->subject->getComposerFiles()); } /** @@ -58,6 +58,6 @@ public function testGetComposerFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('js/lib/jquery', $this->subject->getCopyTarget()); + self::assertSame('js/lib/jquery', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/Copy/Plugins/TinyMceLanguagesTest.php b/tests/unit/Copy/Plugins/TinyMceLanguagesTest.php index 7454238..7cf9e99 100644 --- a/tests/unit/Copy/Plugins/TinyMceLanguagesTest.php +++ b/tests/unit/Copy/Plugins/TinyMceLanguagesTest.php @@ -21,11 +21,11 @@ use OutOfBoundsException; use PHPUnit\Framework\TestCase; -class TinyMceLanguagesTest extends TestCase +final class TinyMceLanguagesTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -35,7 +35,7 @@ public function setUp(): void */ public function testGetComposerName(): void { - static::assertSame('mklkj/tinymce-i18n', $this->subject->getComposerName()); + self::assertSame('mklkj/tinymce-i18n', $this->subject->getComposerName()); } /** @@ -44,9 +44,9 @@ public function testGetComposerName(): void public function testGetComposerSource(): void { try { - static::assertSame('langs7', $this->subject->getComposerSource()); - } catch (OutOfBoundsException $exception) { - static::assertSame('Package "tinymce/tinymce" is not installed', $exception->getMessage()); + self::assertSame('langs7', $this->subject->getComposerSource()); + } catch (OutOfBoundsException $outOfBoundsException) { + self::assertSame('Package "tinymce/tinymce" is not installed', $outOfBoundsException->getMessage()); } } @@ -55,7 +55,7 @@ public function testGetComposerSource(): void */ public function testGetComposerFiles(): void { - static::assertSame(['*.css', '*.js'], $this->subject->getComposerFiles()); + self::assertSame(['*.css', '*.js'], $this->subject->getComposerFiles()); } /** @@ -63,6 +63,6 @@ public function testGetComposerFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('js/lib/tinymce/langs', $this->subject->getCopyTarget()); + self::assertSame('js/lib/tinymce/langs', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/Copy/Plugins/TinyMceTest.php b/tests/unit/Copy/Plugins/TinyMceTest.php index 0e7f306..0c03a9a 100644 --- a/tests/unit/Copy/Plugins/TinyMceTest.php +++ b/tests/unit/Copy/Plugins/TinyMceTest.php @@ -20,11 +20,11 @@ use OpenMage\ComposerPlugin\Copy\Plugins\TinyMce as Subject; use PHPUnit\Framework\TestCase; -class TinyMceTest extends TestCase +final class TinyMceTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -34,7 +34,7 @@ public function setUp(): void */ public function testGetComposerName(): void { - static::assertSame('tinymce/tinymce', $this->subject->getComposerName()); + self::assertSame('tinymce/tinymce', $this->subject->getComposerName()); } /** @@ -42,7 +42,7 @@ public function testGetComposerName(): void */ public function testGetComposerSource(): void { - static::assertSame('', $this->subject->getComposerSource()); + self::assertSame('', $this->subject->getComposerSource()); } /** @@ -50,7 +50,7 @@ public function testGetComposerSource(): void */ public function testGetComposerFiles(): void { - static::assertSame(['*.css', '*.js'], $this->subject->getComposerFiles()); + self::assertSame(['*.css', '*.js'], $this->subject->getComposerFiles()); } /** @@ -58,6 +58,6 @@ public function testGetComposerFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('js/lib/tinymce', $this->subject->getCopyTarget()); + self::assertSame('js/lib/tinymce', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/Copy/Unpkg/ConfigTest.php b/tests/unit/Copy/Unpkg/ConfigTest.php index c597708..87853f5 100644 --- a/tests/unit/Copy/Unpkg/ConfigTest.php +++ b/tests/unit/Copy/Unpkg/ConfigTest.php @@ -21,11 +21,11 @@ use OpenMage\ComposerPlugin\Copy\Unpkg\Config as Subject; use PHPUnit\Framework\TestCase; -class ConfigTest extends TestCase +final class ConfigTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(null); } @@ -34,9 +34,9 @@ public function setUp(): void * @covers \OpenMage\ComposerPlugin\Copy\Unpkg\Config::getValidatedConfig() * @dataProvider provideGetValidatedConfig */ - public function testGetValidatedConfig(?array $expectedResult, $packageConfig): void + public function testGetValidatedConfig(?array $expectedResult, ?array $packageConfig): void { - static::assertSame($expectedResult, $this->subject->getValidatedConfig($packageConfig)); + self::assertSame($expectedResult, $this->subject->getValidatedConfig($packageConfig)); } public function provideGetValidatedConfig(): Generator @@ -152,7 +152,7 @@ public function testUnpkgName(): void { $source = ''; $this->subject->setUnpkgName($source); - static::assertSame($source, $this->subject->getUnpkgName()); + self::assertSame($source, $this->subject->getUnpkgName()); } /** @@ -163,7 +163,7 @@ public function testUnpkgVersion(): void { $source = ''; $this->subject->setUnpkgVersion($source); - static::assertSame($source, $this->subject->getUnpkgVersion()); + self::assertSame($source, $this->subject->getUnpkgVersion()); } /** @@ -174,7 +174,7 @@ public function testUnpkgSource(): void { $source = ''; $this->subject->setUnpkgSource($source); - static::assertSame($source, $this->subject->getUnpkgSource()); + self::assertSame($source, $this->subject->getUnpkgSource()); } /** @@ -185,7 +185,7 @@ public function testCopyTarget(): void { $target = ''; $this->subject->setCopyTarget($target); - static::assertSame($target, $this->subject->getCopyTarget()); + self::assertSame($target, $this->subject->getCopyTarget()); } /** @@ -196,6 +196,6 @@ public function testUnpkgFiles(): void { $files = []; $this->subject->setUnpkgFiles($files); - static::assertSame($files, $this->subject->getUnpkgFiles()); + self::assertSame($files, $this->subject->getUnpkgFiles()); } } diff --git a/tests/unit/Copy/Unpkg/GenericTest.php b/tests/unit/Copy/Unpkg/GenericTest.php index b93f8e3..4bba0f3 100644 --- a/tests/unit/Copy/Unpkg/GenericTest.php +++ b/tests/unit/Copy/Unpkg/GenericTest.php @@ -21,11 +21,11 @@ use OpenMage\ComposerPlugin\Copy\Unpkg\Generic as Subject; use PHPUnit\Framework\TestCase; -class GenericTest extends TestCase +final class GenericTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $config = new Config(); $config->setUnpkgName('name'); @@ -50,7 +50,7 @@ public function setUp(): void */ public function testGetUnpkgName(): void { - static::assertSame('name', $this->subject->getUnpkgName()); + self::assertSame('name', $this->subject->getUnpkgName()); } /** @@ -66,7 +66,7 @@ public function testGetUnpkgName(): void */ public function testGetUnpkgVersion(): void { - static::assertSame('version', $this->subject->getUnpkgVersion()); + self::assertSame('version', $this->subject->getUnpkgVersion()); } /** @@ -81,7 +81,7 @@ public function testGetUnpkgVersion(): void */ public function testGetUnpkgSource(): void { - static::assertSame('source', $this->subject->getUnpkgSource()); + self::assertSame('source', $this->subject->getUnpkgSource()); } /** @@ -96,7 +96,7 @@ public function testGetUnpkgSource(): void */ public function testGetUnpkgFiles(): void { - static::assertSame([], $this->subject->getUnpkgFiles()); + self::assertSame([], $this->subject->getUnpkgFiles()); } /** @@ -111,6 +111,6 @@ public function testGetUnpkgFiles(): void */ public function testGetCopyTarget(): void { - static::assertSame('target', $this->subject->getCopyTarget()); + self::assertSame('target', $this->subject->getCopyTarget()); } } diff --git a/tests/unit/PluginTest.php b/tests/unit/PluginTest.php index faa36ac..51a1f5c 100644 --- a/tests/unit/PluginTest.php +++ b/tests/unit/PluginTest.php @@ -20,11 +20,11 @@ use OpenMage\ComposerPlugin\Plugin as Subject; use PHPUnit\Framework\TestCase; -class PluginTest extends TestCase +final class PluginTest extends TestCase { public Subject $subject; - public function setUp(): void + protected function setUp(): void { $this->subject = new Subject(); } @@ -46,7 +46,7 @@ public function testGetSubscribedEvents(): void ], ], ]; - static::assertSame($events, $this->subject->getSubscribedEvents()); + self::assertSame($events, $this->subject->getSubscribedEvents()); } /** @@ -71,6 +71,6 @@ public function testGetSubscribedEvents(): void */ public function testProcessCopy(): void { - static::assertNull($this->subject->processCopy(null)); + self::assertNull($this->subject->processCopy(null)); } }