Skip to content

Commit

Permalink
Make XML the default configuration format
Browse files Browse the repository at this point in the history
Signed-off-by: Luís Cobucci <[email protected]>
  • Loading branch information
lcobucci committed Mar 1, 2023
1 parent 91fcd78 commit 80d9f93
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 21 deletions.
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ vendor/bin/roave-backward-compatibility-check --help

## Configuration

The file `.roave-backward-compatibility-check.json` is read from the current working directory (when it exists) and sets configuration for the command.
The file `.roave-backward-compatibility-check.xml` is read from the current working directory (when it exists) and sets configuration for the command.

It's expected to be a JSON encoded file that, optionally, contains the following properties:

* `baseline`: list of regexes used to filter detected changes; useful to avoid detection of known BC-breaks
It's expected to be an XML file that follows our [schema](resources/schema.xsd):

**Example:**

```json
{
"baseline": [
"#\\[BC\\] CHANGED: The parameter \\$a of TestArtifact\\\\TheClass\\#method()#",
"#\\[BC\\] CHANGED: The parameter \\$b of TestArtifact\\\\TheClass\\#method2()#"
]
}
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<roave-bc-check
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/roave/backward-compatibility-check/resources/schema.xsd">
<baseline>
<ignored-regex>#\[BC\] CHANGED: The parameter \$a of of TestArtifact\\TheClass\#method\(\)#</ignored-regex>
<ignored-regex>#\[BC\] CHANGED: The parameter \$b of of TestArtifact\\TheClass\#method2\(\)#</ignored-regex>
</baseline>
</roave-bc-check>
```
4 changes: 2 additions & 2 deletions src/Command/DetermineConfigurationFromFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
use Psl\Type;
use Roave\BackwardCompatibility\Configuration\Configuration;
use Roave\BackwardCompatibility\Configuration\ParseConfigurationFile;
use Roave\BackwardCompatibility\Configuration\ParseJsonConfigurationFile;
use Roave\BackwardCompatibility\Configuration\ParseXmlConfigurationFile;
use Symfony\Component\Console\Output\OutputInterface;

/** @internal */
final class DetermineConfigurationFromFilesystem
{
public function __construct(
private readonly ParseConfigurationFile $parser = new ParseJsonConfigurationFile(),
private readonly ParseConfigurationFile $parser = new ParseXmlConfigurationFile(),
) {
}

Expand Down
18 changes: 10 additions & 8 deletions test/e2e/Command/AssertBackwardsCompatibleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ final class AssertBackwardsCompatibleTest extends TestCase

JSON;

private const BASELINE_CONFIGURATION = <<<'JSON'
{
"baseline": ["#\\[BC\\] CHANGED: The parameter \\$a of TestArtifact\\\\TheClass\\#method()#"]
}

JSON;
private const BASELINE_CONFIGURATION = <<<'XML'
<?xml version="1.0" encoding="UTF-8" ?>
<roave-bc-check>
<baseline>
<ignored-regex>#\[BC\] CHANGED: The parameter \$a of TestArtifact\\TheClass\#method.*#</ignored-regex>
</baseline>
</roave-bc-check>
XML;

private const CLASS_VERSIONS = [
<<<'PHP'
Expand Down Expand Up @@ -273,15 +275,15 @@ public function testWillPickLatestTaggedVersionOnNoGivenFrom(): void

public function testWillAllowSpecifyingBaselineConfiguration(): void
{
File\write($this->sourcesRepository . '/.roave-backward-compatibility-check.json', self::BASELINE_CONFIGURATION);
File\write($this->sourcesRepository . '/.roave-backward-compatibility-check.xml', self::BASELINE_CONFIGURATION);

$output = Shell\execute(__DIR__ . '/../../../bin/roave-backward-compatibility-check', [
'--from=' . $this->versions[0],
'--to=' . $this->versions[1],
], $this->sourcesRepository, [], Shell\ErrorOutputBehavior::Append);

self::assertStringContainsString(
'.roave-backward-compatibility-check.json" as configuration file',
'.roave-backward-compatibility-check.xml" as configuration file',
$output,
);
}
Expand Down

0 comments on commit 80d9f93

Please sign in to comment.