Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created new UnwrapStrToUpper mutator #551

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion box.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
"Herrera\\Box\\Compactor\\Json",
"Herrera\\Box\\Compactor\\Php",
"KevinGH\\Box\\Compactor\\PhpScoper"
]
],
"files": ["resources/schema.json"]
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
"ext-json": "*",
"ext-libxml": "*",
"composer/xdebug-handler": "^1.3",
"justinrainbow/json-schema": "^5.2",
"nikic/php-parser": "^4.1",
"ocramius/package-versions": "^1.2",
"padraic/phar-updater": "^1.0.4",
Expand Down
70 changes: 68 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 104 additions & 0 deletions resources/schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"$schema": "https://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"timeout",
"source"
],
"properties": {
"timeout": {
"type": "integer",
"description": "The allowed timeout in seconds configured for Infection."
},
"source": {
"type": "object",
"required": [
"directories"
],
"additionalProperties": false,
"properties": {
"directories": {
"type": "array",
"minItems": 1,
"description": "Contains all folders with source code you want to mutate.",
"items": {
"type": "string"
}
},
"excludes": {
"type": "array",
"minItems": 1,
"description": "Contains all folders or files you want to exclude withing your source folders.",
"items": {
"type": "string"
}
}
}
},
"logs": {
"type": "object",
"minProperties": 1,
"additionalProperties": false,
"properties": {
"text": {
"type": "string",
"description": "Human readable text log file."
},
"summary": {
"type": "string",
"definition": "Summary log file, which display the amount of mutants per category, (Killed, Errored, Escaped, Timed Out & Not Covered)."
},
"debug": {
"type": "string",
"description": "Debug log file, which displays what mutations were found on what line, per category."
},
"perMutator": {
"type": "string",
"description": "Markdown file which will give a break-down of the effectiveness of each mutator."
},
"badge": {
"type": "object",
"additionalProperties": false,
"properties": {
"branch": {
"type": "string",
"description": "Mutation score badge for your github project."
}
}
}
}
},
"tmpDir": {
"type": "string",
"description": "Folder where Infection creates its configs, caches and other stuff."
},
"phpUnit": {
"type": "object",
"description": "PHPUnit additional settings.",
"additionalProperties": false,
"properties": {
"configDir": {
"type": "string",
"description": "Path to directory containing PHPUnit configuration file."
},
"customPath": {
"type": "string",
"description": "Custom path to PHPUnit executable."
}
}
},
"mutators": {
"type": "object",
"description": "Contains the settings for different mutations and profiles"
},
"testFramework": {
"type": "string",
"description": "Sets the framework to use for testing. Defaults to phpunit."
},
"bootstrap": {
"type": "string",
"description": "Use to specify a file to include as part of the startup to pre-configure the infection environment. Useful for adding custom autoloaders not included in composer."
}
}
}
2 changes: 1 addition & 1 deletion src/Command/InfectionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private function getTestFrameworkExtraOptions(string $testFrameworkKey): TestFra
private function runConfigurationCommand(Locator $locator): void
{
try {
$locator->locateAnyOf(InfectionConfig::POSSIBLE_CONFIG_FILE_NAMES);
$locator->locateOneOf(InfectionConfig::POSSIBLE_CONFIG_FILE_NAMES);
} catch (\Exception $e) {
$configureCommand = $this->getApplication()->find('configure');
$config = $this->getContainer()->get('infection.config');
Expand Down
112 changes: 112 additions & 0 deletions src/Config/ConfigCreatorFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* This code is licensed under the BSD 3-Clause License.
*
* Copyright (c) 2017-2018, Maks Rafalko
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

declare(strict_types=1);

namespace Infection\Config;

use Infection\Config\Validator as ConfigValidator;
use Infection\Finder\Exception\LocatorException;
use Infection\Finder\LocatorInterface;
use Infection\Json\JsonFile;
use Symfony\Component\Filesystem\Filesystem;

/**
* @internal
*/
final class ConfigCreatorFacade
{
/**
* @var ConfigValidator
*/
private $configValidator;

/**
* @var LocatorInterface
*/
private $locator;

/**
* @var Filesystem
*/
private $filesystem;

public function __construct(LocatorInterface $locator, Filesystem $filesystem)
{
$this->locator = $locator;
$this->filesystem = $filesystem;

$this->configValidator = new Validator();
}

public function createConfig(?string $customConfigPath): InfectionConfig
{
try {
$infectionConfigFile = $this->locateConfigFile($customConfigPath);

$content = (new JsonFile($infectionConfigFile))->decode();

$configLocation = \pathinfo($infectionConfigFile, PATHINFO_DIRNAME);
} catch (LocatorException $e) {
// Generate an empty class to trigger `configure` command.
$content = new \stdClass();

$configLocation = getcwd();
}

// getcwd() may return false in rare circumstances
\assert(\is_string($configLocation));

$infectionConfig = new InfectionConfig($content, $this->filesystem, $configLocation);

$this->configValidator->validate($infectionConfig);

return $infectionConfig;
}

private function locateConfigFile(?string $customConfigPath): string
{
$configPaths = [];

if ($customConfigPath) {
$configPaths[] = $customConfigPath;
}

$configPaths = array_merge(
$configPaths,
InfectionConfig::POSSIBLE_CONFIG_FILE_NAMES
);

return $this->locator->locateOneOf($configPaths);
}
}
9 changes: 0 additions & 9 deletions src/Config/Exception/InvalidConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@
*/
final class InvalidConfigException extends \RuntimeException
{
public static function invalidJson(string $configFile, string $errorMessage): self
{
return new self(sprintf(
'The configuration file "%s" does not contain valid JSON: %s.',
$configFile,
$errorMessage
));
}

public static function invalidMutator(string $mutator): self
{
return new self(sprintf(
Expand Down