Skip to content

Commit 2ef6a58

Browse files
committed
BC Break: Removed the sources-path argument - from here on, we assume there's a composer.json with an autoload section
This means that your project should (in theory) have a `composer.json` at its root, and the sources for it will automatically be inferred from the `composer.json` definition. Currently, this package declares a `SourceLocator` instance emulating the `"autoload"` section of a `composer.json` configuration, but later it may be provided by BetterReflection directly (Roave/BetterReflection#442). This patch also changes the constructor and default behavior of `AssertBackwardsCompatible`, so it is a major BC break that requires a new major release.
1 parent 477ab98 commit 2ef6a58

File tree

3 files changed

+25
-79
lines changed

3 files changed

+25
-79
lines changed

bin/roave-backward-compatibility-check.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
use Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased;
1919
use Roave\BackwardCompatibility\DetectChanges\Variance\TypeIsContravariant;
2020
use Roave\BackwardCompatibility\DetectChanges\Variance\TypeIsCovariant;
21-
use Roave\BackwardCompatibility\Factory\DirectoryReflectorFactory;
21+
use Roave\BackwardCompatibility\Factory\ComposerInstallationReflectorFactory;
2222
use Roave\BackwardCompatibility\Git\GetVersionCollectionFromGitRepository;
2323
use Roave\BackwardCompatibility\Git\GitCheckoutRevisionToTemporaryPath;
2424
use Roave\BackwardCompatibility\Git\GitParseRevision;
2525
use Roave\BackwardCompatibility\Git\PickLastMinorVersionFromCollection;
2626
use Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer;
27+
use Roave\BackwardCompatibility\LocateSources\LocateSourcesViaComposerJson;
2728
use Roave\BetterReflection\BetterReflection;
2829
use RuntimeException;
2930
use Symfony\Component\Console\Application;
@@ -59,7 +60,7 @@
5960

6061
$apiCompareCommand = new Command\AssertBackwardsCompatible(
6162
new GitCheckoutRevisionToTemporaryPath(),
62-
new DirectoryReflectorFactory($astLocator),
63+
new ComposerInstallationReflectorFactory(new LocateSourcesViaComposerJson($astLocator)),
6364
new GitParseRevision(),
6465
new GetVersionCollectionFromGitRepository(),
6566
new PickLastMinorVersionFromCollection(),

src/Command/AssertBackwardsCompatible.php

+19-33
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use Assert\Assert;
88
use Roave\BackwardCompatibility\Changes;
99
use Roave\BackwardCompatibility\CompareApi;
10-
use Roave\BackwardCompatibility\Factory\DirectoryReflectorFactory;
10+
use Roave\BackwardCompatibility\Factory\ComposerInstallationReflectorFactory;
1111
use Roave\BackwardCompatibility\Formatter\MarkdownPipedToSymfonyConsoleFormatter;
1212
use Roave\BackwardCompatibility\Formatter\SymfonyConsoleTextFormatter;
1313
use Roave\BackwardCompatibility\Git\CheckedOutRepository;
@@ -22,7 +22,6 @@
2222
use Symfony\Component\Console\Command\Command;
2323
use Symfony\Component\Console\Exception\InvalidArgumentException;
2424
use Symfony\Component\Console\Exception\LogicException;
25-
use Symfony\Component\Console\Input\InputArgument;
2625
use Symfony\Component\Console\Input\InputInterface;
2726
use Symfony\Component\Console\Input\InputOption;
2827
use Symfony\Component\Console\Output\ConsoleOutputInterface;
@@ -37,8 +36,8 @@ final class AssertBackwardsCompatible extends Command
3736
/** @var PerformCheckoutOfRevision */
3837
private $git;
3938

40-
/** @var DirectoryReflectorFactory */
41-
private $reflectorFactory;
39+
/** @var ComposerInstallationReflectorFactory */
40+
private $makeComposerInstallationReflector;
4241

4342
/** @var ParseRevision */
4443
private $parseRevision;
@@ -60,7 +59,7 @@ final class AssertBackwardsCompatible extends Command
6059
*/
6160
public function __construct(
6261
PerformCheckoutOfRevision $git,
63-
DirectoryReflectorFactory $reflectorFactory,
62+
ComposerInstallationReflectorFactory $makeComposerInstallationReflector,
6463
ParseRevision $parseRevision,
6564
GetVersionCollection $getVersions,
6665
PickVersionFromVersionCollection $pickFromVersion,
@@ -69,13 +68,13 @@ public function __construct(
6968
) {
7069
parent::__construct();
7170

72-
$this->git = $git;
73-
$this->reflectorFactory = $reflectorFactory;
74-
$this->parseRevision = $parseRevision;
75-
$this->getVersions = $getVersions;
76-
$this->pickFromVersion = $pickFromVersion;
77-
$this->locateDependencies = $locateDependencies;
78-
$this->compareApi = $compareApi;
71+
$this->git = $git;
72+
$this->makeComposerInstallationReflector = $makeComposerInstallationReflector;
73+
$this->parseRevision = $parseRevision;
74+
$this->getVersions = $getVersions;
75+
$this->pickFromVersion = $pickFromVersion;
76+
$this->locateDependencies = $locateDependencies;
77+
$this->compareApi = $compareApi;
7978
}
8079

8180
/**
@@ -105,12 +104,6 @@ protected function configure() : void
105104
InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY,
106105
'Currently only supports "markdown"'
107106
)
108-
->addArgument(
109-
'sources-path',
110-
InputArgument::OPTIONAL,
111-
'Path to the sources, relative to the repository root',
112-
'src'
113-
)
114107
->addUsage(
115108
<<<'USAGE'
116109
@@ -126,7 +119,7 @@ protected function configure() : void
126119
127120
It will then install all required dependencies in both copies
128121
and compare the APIs, looking for breaking changes in the
129-
given `<sources-path>` ("src" by default).
122+
defined "autoload" paths in your `composer.json` definition.
130123
131124
Once completed, it will print out the results to `STDERR`
132125
and terminate with `3` if breaking changes were detected.
@@ -156,32 +149,25 @@ public function execute(InputInterface $input, OutputInterface $output) : int
156149
? $this->parseRevisionFromInput($input, $sourceRepo)
157150
: $this->determineFromRevisionFromRepository($sourceRepo, $stdErr);
158151

159-
$toRevision = $this->parseRevision->fromStringForRepository($input->getOption('to'), $sourceRepo);
160-
$sourcesPath = $input->getArgument('sources-path');
152+
$toRevision = $this->parseRevision->fromStringForRepository($input->getOption('to'), $sourceRepo);
161153

162154
$stdErr->writeln(sprintf('Comparing from %s to %s...', (string) $fromRevision, (string) $toRevision));
163155

164156
$fromPath = $this->git->checkout($sourceRepo, $fromRevision);
165157
$toPath = $this->git->checkout($sourceRepo, $toRevision);
166158

167159
try {
168-
$fromSources = $fromPath . '/' . $sourcesPath;
169-
$toSources = $toPath . '/' . $sourcesPath;
170-
171-
Assert::that($fromSources)->directory();
172-
Assert::that($toSources)->directory();
173-
174160
$changes = $this->compareApi->__invoke(
175-
$this->reflectorFactory->__invoke(
176-
$fromPath . '/' . $sourcesPath,
161+
$this->makeComposerInstallationReflector->__invoke(
162+
$fromPath->__toString(),
177163
new AggregateSourceLocator() // no dependencies
178164
),
179-
$this->reflectorFactory->__invoke(
180-
$fromPath . '/' . $sourcesPath,
165+
$this->makeComposerInstallationReflector->__invoke(
166+
$fromPath->__toString(),
181167
$this->locateDependencies->__invoke((string) $fromPath)
182168
),
183-
$this->reflectorFactory->__invoke(
184-
$toPath . '/' . $sourcesPath,
169+
$this->makeComposerInstallationReflector->__invoke(
170+
$toPath->__toString(),
185171
$this->locateDependencies->__invoke((string) $toPath)
186172
)
187173
);

test/unit/Command/AssertBackwardsCompatibleTest.php

+3-44
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Roave\BackwardCompatibility\Changes;
1313
use Roave\BackwardCompatibility\Command\AssertBackwardsCompatible;
1414
use Roave\BackwardCompatibility\CompareApi;
15+
use Roave\BackwardCompatibility\Factory\ComposerInstallationReflectorFactory;
1516
use Roave\BackwardCompatibility\Factory\DirectoryReflectorFactory;
1617
use Roave\BackwardCompatibility\Git\CheckedOutRepository;
1718
use Roave\BackwardCompatibility\Git\GetVersionCollection;
@@ -20,6 +21,7 @@
2021
use Roave\BackwardCompatibility\Git\PickVersionFromVersionCollection;
2122
use Roave\BackwardCompatibility\Git\Revision;
2223
use Roave\BackwardCompatibility\LocateDependencies\LocateDependencies;
24+
use Roave\BackwardCompatibility\LocateSources\LocateSourcesViaComposerJson;
2325
use Roave\BetterReflection\BetterReflection;
2426
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
2527
use Symfony\Component\Console\Input\InputInterface;
@@ -95,7 +97,7 @@ public function setUp() : void
9597
$this->compareApi = $this->createMock(CompareApi::class);
9698
$this->compare = new AssertBackwardsCompatible(
9799
$this->performCheckout,
98-
new DirectoryReflectorFactory((new BetterReflection())->astLocator()),
100+
new ComposerInstallationReflectorFactory(new LocateSourcesViaComposerJson((new BetterReflection())->astLocator())),
99101
$this->parseRevision,
100102
$this->getVersions,
101103
$this->pickVersion,
@@ -382,47 +384,4 @@ public function testExecuteWithDefaultRevisionsNotProvided() : void
382384

383385
self::assertSame(0, $this->compare->execute($this->input, $this->output));
384386
}
385-
386-
public function testExecuteFailsIfCheckedOutRepositoryDoesNotExist() : void
387-
{
388-
$fromSha = sha1('fromRevision', false);
389-
$toSha = sha1('toRevision', false);
390-
391-
$this->input->expects(self::any())->method('getOption')->willReturnMap([
392-
['from', $fromSha],
393-
['to', $toSha],
394-
]);
395-
$this->input->expects(self::any())->method('getArgument')->willReturnMap([
396-
['sources-path', uniqid('src', true)],
397-
]);
398-
399-
$this->performCheckout->expects(self::at(0))
400-
->method('checkout')
401-
->with($this->sourceRepository, $fromSha)
402-
->willReturn($this->sourceRepository);
403-
$this->performCheckout->expects(self::at(1))
404-
->method('checkout')
405-
->with($this->sourceRepository, $toSha)
406-
->willReturn($this->sourceRepository);
407-
$this->performCheckout->expects(self::at(2))
408-
->method('remove')
409-
->with($this->sourceRepository);
410-
$this->performCheckout->expects(self::at(3))
411-
->method('remove')
412-
->with($this->sourceRepository);
413-
414-
$this->parseRevision->expects(self::at(0))
415-
->method('fromStringForRepository')
416-
->with($fromSha)
417-
->willReturn(Revision::fromSha1($fromSha));
418-
$this->parseRevision->expects(self::at(1))
419-
->method('fromStringForRepository')
420-
->with($toSha)
421-
->willReturn(Revision::fromSha1($toSha));
422-
423-
$this->compareApi->expects(self::never())->method('__invoke');
424-
425-
$this->expectException(InvalidArgumentException::class);
426-
$this->compare->execute($this->input, $this->output);
427-
}
428387
}

0 commit comments

Comments
 (0)