diff --git a/.gitattributes b/.gitattributes index 523e2f5c..44ad0a16 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,17 +1,18 @@ * text=auto *.php text eol=lf -tests/ export-ignore -build export-ignore -.github export-ignore +tests/ export-ignore +build/ export-ignore +.github/ export-ignore -.php_cs export-ignore -.gitattributes export-ignore -.gitignore export-ignore -.travis.yml export-ignore -.editorconfig export-ignore -codecov.yml export-ignore -phpstan.neon export-ignore -phpunit.xml.dist export-ignore -CONTRIBUTING.md export-ignore -README.md export-ignore +.php_cs export-ignore +.gitattributes export-ignore +.gitignore export-ignore +.travis.yml export-ignore +.editorconfig export-ignore +codecov.yml export-ignore +phpstan.neon export-ignore +phpunit.xml.dist export-ignore +infection.json.dist export-ignore +CONTRIBUTING.md export-ignore +README.md export-ignore diff --git a/.gitignore b/.gitignore index 7a7c9725..a61a84dd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ composer.lock .php_cs.cache .phpunit.result.cache +infectionlog.json +infectionlog.txt /build/logs /vendor diff --git a/.prettyci.composer.json b/.prettyci.composer.json deleted file mode 100644 index 6e0e891a..00000000 --- a/.prettyci.composer.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "require-dev": { - "narrowspark/php-cs-fixer-config": "^3.4.0" - } -} diff --git a/.travis.yml b/.travis.yml index 4b16e035..aed3358c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,9 @@ jobs: - php: nightly - php: 7.4snapshot include: + - stage: Test + php: 7.2 + env: PHPUNIT=true SETUP=lowest REMOVE_XDEBUG=true COMPOSER_VERSION=1.7.0 - stage: Test php: 7.2 env: PHPUNIT=true SETUP=high REMOVE_XDEBUG=true COMPOSER_VERSION=1.7.0 @@ -67,6 +70,17 @@ jobs: env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.9.0 script: - composer phpstan +# - stage: Static Analysis +# php: 7.2 +# env: REMOVE_XDEBUG=false SETUP=high COMPOSER_VERSION=1.9.0 +# script: +# - composer psalm + + - stage: Mutation + php: 7.2 + env: REMOVE_XDEBUG=true SETUP=high COMPOSER_VERSION=1.9.0 + script: + - ulimit -n 4096 && phpdbg -qrr ./vendor/bin/infection -vvv --test-framework-options='--testsuite=unit' --min-msi=48 --min-covered-msi=70 - stage: Coverage php: 7.2 diff --git a/appveyor.yml b/appveyor.yml index b263be31..fd172e03 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -9,7 +9,7 @@ environment: matrix: - dependencies: lowest PHP_VERSION: 7.2 - COMPOSER_VERSION: 1.6.5 + COMPOSER_VERSION: 1.7.0 - dependencies: high PHP_VERSION: 7.2 COMPOSER_VERSION: 1.7.0 diff --git a/composer.json b/composer.json index 0026ab99..4f0ef19b 100644 --- a/composer.json +++ b/composer.json @@ -37,7 +37,8 @@ "nyholm/nsa": "^1.1.0", "phpunit/phpunit": "^8.3.3", "ocramius/package-versions": "^1.4.0 || ^1.5.0", - "narrowspark/coding-standard": "^2.0.0" + "narrowspark/coding-standard": "^2.1.1", + "infection/infection": "^0.13.4" }, "config": { "optimize-autoloader": true, @@ -45,7 +46,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "2.0.x-dev" }, "class": [ "Narrowspark\\Automatic\\Security\\SecurityPlugin", @@ -66,8 +67,7 @@ "psr-4": { "Narrowspark\\Automatic\\Test\\": "tests/Automatic/", "Narrowspark\\Automatic\\Common\\Test\\": "tests/Common/", - "Narrowspark\\Automatic\\Security\\Test\\": "tests/Security/", - "Narrowspark\\Automatic\\Functional\\Test\\": "tests/Functional/" + "Narrowspark\\Automatic\\Security\\Test\\": "tests/Security/" }, "files": [ "tests/Automatic/TmpDirMock.php" @@ -79,10 +79,15 @@ "coverage": "phpunit --coverage-html=\"build/logs\"", "cs": "php-cs-fixer fix", "phpstan": "phpstan analyse -c phpstan.neon -l 7 src --memory-limit=-1", + "psalm": "psalm", "test": "phpunit", + "infection": "infection", "test-common": "phpunit --testsuite=\"Narrowspark Automatic Common Test Suite\"", "test-automatic": "phpunit --testsuite=\"Narrowspark Automatic Test Suite\"", - "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend" + "changelog": "changelog-generator generate --config=\".changelog\" --file --prepend", + "auto-scripts": { + + } }, "support": { "issues": "https://github.com/narrowspark/automatic/issues", diff --git a/infection.json.dist b/infection.json.dist new file mode 100644 index 00000000..f6c770f0 --- /dev/null +++ b/infection.json.dist @@ -0,0 +1,14 @@ +{ + "timeout": 15, + "source": { + "directories": [ + "src" + ] + }, + "logs": { + "text": "infection.log" + }, + "mutators": { + "@default": true + } +} diff --git a/phpunit.xml.dist b/phpunit.xml.dist index dcec5a1f..945fb682 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 00000000..42f355b2 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Automatic/Automatic.php b/src/Automatic/Automatic.php index ea1a1cc5..08bfd09b 100644 --- a/src/Automatic/Automatic.php +++ b/src/Automatic/Automatic.php @@ -926,7 +926,7 @@ private function getErrorMessage(IOInterface $io): ?string return 'You must enable the openssl extension in your "php.ini" file'; } - if (\version_compare(self::getComposerVersion(), '1.6.0', '<')) { + if (\version_compare(self::getComposerVersion(), '1.7.0', '<')) { return \sprintf('Your version "%s" of Composer is too old; Please upgrade', Composer::VERSION); } diff --git a/src/Security/SecurityPlugin.php b/src/Security/SecurityPlugin.php index c33ffba8..c467be0d 100644 --- a/src/Security/SecurityPlugin.php +++ b/src/Security/SecurityPlugin.php @@ -225,7 +225,7 @@ public function auditComposerLock(Event $event): void private function getErrorMessage(): ?string { // @codeCoverageIgnoreStart - if (\version_compare(self::getComposerVersion(), '1.6.0', '<')) { + if (\version_compare(self::getComposerVersion(), '1.7.0', '<')) { return \sprintf('Your version "%s" of Composer is too old; Please upgrade', Composer::VERSION); } // @codeCoverageIgnoreEnd diff --git a/tests/Automatic/AutomaticTest.php b/tests/Automatic/AutomaticTest.php index 3633f9ef..9e0615dd 100644 --- a/tests/Automatic/AutomaticTest.php +++ b/tests/Automatic/AutomaticTest.php @@ -96,6 +96,8 @@ protected function tearDown(): void public function testGetSubscribedEvents(): void { + NSA::setProperty($this->automatic, 'activated', true); + $this->assertCount(15, Automatic::getSubscribedEvents()); NSA::setProperty($this->automatic, 'activated', false); @@ -493,6 +495,8 @@ public function testExecuteAutoScriptsWithNumericArray(): void public function testExecuteAutoScriptsWithoutScripts(): void { + \putenv('COMPOSER=' . __DIR__ . '/Fixture/composer-empty-scripts.json'); + $eventMock = $this->mock(Event::class); $eventMock->shouldReceive('stopPropagation') ->never(); @@ -509,6 +513,9 @@ public function testExecuteAutoScriptsWithoutScripts(): void $this->automatic->setContainer($containerMock); $this->automatic->executeAutoScripts($eventMock); + + \putenv('COMPOSER='); + \putenv('COMPOSER'); } public function testPopulateFilesCacheDir(): void @@ -815,6 +822,9 @@ public function testOnPostAutoloadDump(): void { $containerMock = $this->mock(ContainerContract::class); $configuratorMock = $this->mock(ConfiguratorContract::class); + + NSA::setProperty($this->automatic, 'configuratorsLoaded', false); + $configuratorMock->shouldReceive('reset') ->never(); $configuratorMock->shouldReceive('add') diff --git a/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php b/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php index b098dfa0..901bfb19 100644 --- a/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php +++ b/tests/Automatic/Configurator/ComposerAutoScriptsConfiguratorTest.php @@ -131,4 +131,12 @@ public function testUnconfigure(): void \unlink($composerJsonPath); } + + /** + * {@inheritdoc} + */ + protected function allowMockingNonExistentMethods(bool $allow = false): void + { + parent::allowMockingNonExistentMethods(true); + } } diff --git a/tests/Automatic/Fixture/composer-empty-scripts.json b/tests/Automatic/Fixture/composer-empty-scripts.json new file mode 100644 index 00000000..aa93a57d --- /dev/null +++ b/tests/Automatic/Fixture/composer-empty-scripts.json @@ -0,0 +1,12 @@ +{ + "name": "narrowspark/automatic", + "type": "composer-plugin", + "description": "Composer plugin for automatically project configuration and creation.", + "license": "MIT", + "config": { + "optimize-autoloader": true, + "preferred-install": "dist" + }, + "scripts": { + } +}