2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2015-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Composer.
|
|
|
|
*
|
|
|
|
* (c) Nils Adermann <naderman@naderman.de>
|
|
|
|
* Jordi Boggiano <j.boggiano@seld.be>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Util;
|
|
|
|
|
|
|
|
use Composer\IO\NullIO;
|
|
|
|
use Composer\Util\ConfigValidator;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2015-10-23 17:20:56 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ConfigValidator test case
|
|
|
|
*/
|
|
|
|
class ConfigValidatorTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Test ConfigValidator warns on commit reference
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testConfigValidatorCommitRefWarning(): void
|
2015-10-23 17:20:56 +00:00
|
|
|
{
|
|
|
|
$configValidator = new ConfigValidator(new NullIO());
|
2022-08-17 12:20:07 +00:00
|
|
|
[, , $warnings] = $configValidator->validate(__DIR__ . '/Fixtures/composer_commit-ref.json');
|
2015-10-23 17:20:56 +00:00
|
|
|
|
2017-12-03 04:41:58 +00:00
|
|
|
$this->assertContains(
|
2015-10-27 12:51:51 +00:00
|
|
|
'The package "some/package" is pointing to a commit-ref, this is bad practice and can cause unforeseen issues.',
|
|
|
|
$warnings
|
2017-12-03 04:41:58 +00:00
|
|
|
);
|
2015-10-23 17:20:56 +00:00
|
|
|
}
|
2018-01-17 18:15:06 +00:00
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testConfigValidatorWarnsOnScriptDescriptionForNonexistentScript(): void
|
2018-01-17 18:15:06 +00:00
|
|
|
{
|
|
|
|
$configValidator = new ConfigValidator(new NullIO());
|
2022-08-17 12:20:07 +00:00
|
|
|
[, , $warnings] = $configValidator->validate(__DIR__ . '/Fixtures/composer_scripts-descriptions.json');
|
2018-01-17 18:15:06 +00:00
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
'Description for non-existent script "phpcsxxx" found in "scripts-descriptions"',
|
|
|
|
$warnings
|
|
|
|
);
|
|
|
|
}
|
2020-10-22 09:28:19 +00:00
|
|
|
|
2023-10-27 09:36:59 +00:00
|
|
|
public function testConfigValidatorWarnsOnScriptAliasForNonexistentScript(): void
|
|
|
|
{
|
|
|
|
$configValidator = new ConfigValidator(new NullIO());
|
|
|
|
[, , $warnings] = $configValidator->validate(__DIR__ . '/Fixtures/composer_scripts-aliases.json');
|
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
'Aliases for non-existent script "phpcsxxx" found in "scripts-aliases"',
|
|
|
|
$warnings
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testConfigValidatorWarnsOnUnnecessaryProvideReplace(): void
|
2020-10-22 09:28:19 +00:00
|
|
|
{
|
|
|
|
$configValidator = new ConfigValidator(new NullIO());
|
2022-08-17 12:20:07 +00:00
|
|
|
[, , $warnings] = $configValidator->validate(__DIR__ . '/Fixtures/composer_provide-replace-requirements.json');
|
2020-10-22 09:28:19 +00:00
|
|
|
|
|
|
|
$this->assertContains(
|
|
|
|
'The package a/a in require is also listed in provide which satisfies the requirement. Remove it from provide if you wish to install it.',
|
|
|
|
$warnings
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'The package b/b in require is also listed in replace which satisfies the requirement. Remove it from replace if you wish to install it.',
|
|
|
|
$warnings
|
|
|
|
);
|
|
|
|
$this->assertContains(
|
|
|
|
'The package c/c in require-dev is also listed in provide which satisfies the requirement. Remove it from provide if you wish to install it.',
|
|
|
|
$warnings
|
|
|
|
);
|
|
|
|
}
|
2015-10-23 17:20:56 +00:00
|
|
|
}
|