Completed
Push — master ( 4eb33b...9d87b5 )
by Marco
11s queued 10s
created

AssertBackwardsCompatibleTest::testDefinition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 17
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\Command;
6
7
use Assert\AssertionFailedException;
8
use PHPUnit\Framework\MockObject\MockObject;
9
use PHPUnit\Framework\TestCase;
10
use Roave\BackwardCompatibility\Change;
11
use Roave\BackwardCompatibility\Changes;
12
use Roave\BackwardCompatibility\Command\AssertBackwardsCompatible;
13
use Roave\BackwardCompatibility\CompareApi;
14
use Roave\BackwardCompatibility\Factory\ComposerInstallationReflectorFactory;
15
use Roave\BackwardCompatibility\Git\CheckedOutRepository;
16
use Roave\BackwardCompatibility\Git\GetVersionCollection;
17
use Roave\BackwardCompatibility\Git\ParseRevision;
18
use Roave\BackwardCompatibility\Git\PerformCheckoutOfRevision;
19
use Roave\BackwardCompatibility\Git\PickVersionFromVersionCollection;
20
use Roave\BackwardCompatibility\Git\Revision;
21
use Roave\BackwardCompatibility\LocateDependencies\LocateDependencies;
22
use Roave\BackwardCompatibility\LocateSources\LocateSourcesViaComposerJson;
23
use Roave\BetterReflection\BetterReflection;
24
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
25
use Symfony\Component\Console\Input\InputInterface;
26
use Symfony\Component\Console\Output\ConsoleOutputInterface;
27
use Symfony\Component\Console\Output\OutputInterface;
28
use Version\Version;
29
use Version\VersionsCollection;
30
use function Safe\chdir;
31
use function Safe\realpath;
32
use function sha1;
33
use function uniqid;
34
35
/**
36
 * @covers \Roave\BackwardCompatibility\Command\AssertBackwardsCompatible
37
 */
38
final class AssertBackwardsCompatibleTest extends TestCase
39
{
40
    /** @var CheckedOutRepository */
41
    private $sourceRepository;
42
43
    /** @var InputInterface&MockObject */
44
    private $input;
45
46
    /** @var ConsoleOutputInterface&MockObject */
47
    private $output;
48
49
    /** @var OutputInterface&MockObject */
50
    private $stdErr;
51
52
    /** @var PerformCheckoutOfRevision&MockObject */
53
    private $performCheckout;
54
55
    /** @var ParseRevision&MockObject */
56
    private $parseRevision;
57
58
    /** @var GetVersionCollection&MockObject */
59
    private $getVersions;
60
61
    /** @var PickVersionFromVersionCollection&MockObject */
62
    private $pickVersion;
63
64
    /** @var LocateDependencies&MockObject */
65
    private $locateDependencies;
66
67
    /** @var CompareApi&MockObject */
68
    private $compareApi;
69
70
    /** @var AggregateSourceLocator */
71
    private $dependencies;
72
73
    /** @var AssertBackwardsCompatible */
74
    private $compare;
75
76
    public function setUp() : void
77
    {
78
        $repositoryPath = realpath(__DIR__ . '/../../../');
79
80
        $this->sourceRepository = CheckedOutRepository::fromPath($repositoryPath);
81
82
        chdir($this->sourceRepository->__toString());
83
84
        $this->input              = $this->createMock(InputInterface::class);
85
        $this->output             = $this->createMock(ConsoleOutputInterface::class);
86
        $this->stdErr             = $this->createMock(OutputInterface::class);
87
        $this->performCheckout    = $this->createMock(PerformCheckoutOfRevision::class);
88
        $this->parseRevision      = $this->createMock(ParseRevision::class);
89
        $this->getVersions        = $this->createMock(GetVersionCollection::class);
90
        $this->pickVersion        = $this->createMock(PickVersionFromVersionCollection::class);
91
        $this->locateDependencies = $this->createMock(LocateDependencies::class);
92
        $this->dependencies       = new AggregateSourceLocator();
93
        $this->compareApi         = $this->createMock(CompareApi::class);
94
        $this->compare            = new AssertBackwardsCompatible(
95
            $this->performCheckout,
96
            new ComposerInstallationReflectorFactory(new LocateSourcesViaComposerJson((new BetterReflection())->astLocator())),
97
            $this->parseRevision,
98
            $this->getVersions,
99
            $this->pickVersion,
100
            $this->locateDependencies,
101
            $this->compareApi
102
        );
103
104
        $this
105
            ->output
106
            ->expects(self::any())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on PHPUnit\Framework\MockObject\MockObject. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
            ->/** @scrutinizer ignore-call */ 
107
              expects(self::any())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method any() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

106
            ->expects(self::/** @scrutinizer ignore-call */ any())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
107
            ->method('getErrorOutput')
108
            ->willReturn($this->stdErr);
109
    }
110
111
    public function testDefinition() : void
112
    {
113
        $usages = $this->compare->getUsages();
114
115
        self::assertCount(1, $usages);
0 ignored issues
show
Bug introduced by
The method assertCount() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

115
        self::/** @scrutinizer ignore-call */ 
116
              assertCount(1, $usages);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
116
        self::assertStringStartsWith(
0 ignored issues
show
Bug introduced by
The method assertStringStartsWith() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

116
        self::/** @scrutinizer ignore-call */ 
117
              assertStringStartsWith(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
117
            'roave-backwards-compatibility-check:assert-backwards-compatible',
118
            $usages[0]
119
        );
120
        self::assertStringContainsString('Without arguments, this command will attempt to detect', $usages[0]);
0 ignored issues
show
Bug introduced by
The method assertStringContainsString() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

120
        self::/** @scrutinizer ignore-call */ 
121
              assertStringContainsString('Without arguments, this command will attempt to detect', $usages[0]);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121
        self::assertStringStartsWith('Verifies that the revision being', $this->compare->getDescription());
122
123
        self::assertSame(
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

123
        self::/** @scrutinizer ignore-call */ 
124
              assertSame(
Loading history...
124
            '[--from [FROM]] [--to TO] [--format [FORMAT]]',
0 ignored issues
show
Bug introduced by
'[--from [FROM]] [--to TO] [--format [FORMAT]]' of type string is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

124
            /** @scrutinizer ignore-type */ '[--from [FROM]] [--to TO] [--format [FORMAT]]',
Loading history...
125
            $this->compare
126
                ->getDefinition()
127
                ->getSynopsis()
128
        );
129
    }
130
131
    public function testExecuteWhenRevisionsAreProvidedAsOptions() : void
132
    {
133
        $fromSha = sha1('fromRevision', false);
134
        $toSha   = sha1('toRevision', false);
135
136
        $this->input->expects(self::any())->method('getOption')->willReturnMap([
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Symfony\Component\Console\Input\InputInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

136
        $this->input->/** @scrutinizer ignore-call */ 
137
                      expects(self::any())->method('getOption')->willReturnMap([

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
137
            ['from', $fromSha],
138
            ['to', $toSha],
139
        ]);
140
        $this->input->expects(self::any())->method('getArgument')->willReturnMap([
141
            ['sources-path', 'src'],
142
        ]);
143
144
        $this->performCheckout->expects(self::at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...rformCheckoutOfRevision. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

144
        $this->performCheckout->/** @scrutinizer ignore-call */ 
145
                                expects(self::at(0))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method at() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

144
        $this->performCheckout->expects(self::/** @scrutinizer ignore-call */ at(0))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
145
            ->method('checkout')
146
            ->with($this->sourceRepository, $fromSha)
147
            ->willReturn($this->sourceRepository);
148
        $this->performCheckout->expects(self::at(1))
149
            ->method('checkout')
150
            ->with($this->sourceRepository, $toSha)
151
            ->willReturn($this->sourceRepository);
152
        $this->performCheckout->expects(self::at(2))
153
            ->method('remove')
154
            ->with($this->sourceRepository);
155
        $this->performCheckout->expects(self::at(3))
156
            ->method('remove')
157
            ->with($this->sourceRepository);
158
159
        $this->parseRevision->expects(self::at(0))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibility\Git\ParseRevision. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

159
        $this->parseRevision->/** @scrutinizer ignore-call */ 
160
                              expects(self::at(0))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
160
            ->method('fromStringForRepository')
161
            ->with($fromSha)
162
            ->willReturn(Revision::fromSha1($fromSha));
163
        $this->parseRevision->expects(self::at(1))
164
            ->method('fromStringForRepository')
165
            ->with($toSha)
166
            ->willReturn(Revision::fromSha1($toSha));
167
168
        $this
169
            ->locateDependencies
170
            ->expects(self::any())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...cies\LocateDependencies. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

170
            ->/** @scrutinizer ignore-call */ 
171
              expects(self::any())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
171
            ->method('__invoke')
172
            ->with((string) $this->sourceRepository)
173
            ->willReturn($this->dependencies);
174
175
        $this->compareApi->expects(self::once())->method('__invoke')->willReturn(Changes::empty());
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibility\CompareApi. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

175
        $this->compareApi->/** @scrutinizer ignore-call */ 
176
                           expects(self::once())->method('__invoke')->willReturn(Changes::empty());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method once() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

175
        $this->compareApi->expects(self::/** @scrutinizer ignore-call */ once())->method('__invoke')->willReturn(Changes::empty());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
176
177
        self::assertSame(0, $this->compare->execute($this->input, $this->output));
0 ignored issues
show
Bug introduced by
0 of type integer is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

177
        self::assertSame(/** @scrutinizer ignore-type */ 0, $this->compare->execute($this->input, $this->output));
Loading history...
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

177
        self::/** @scrutinizer ignore-call */ 
178
              assertSame(0, $this->compare->execute($this->input, $this->output));
Loading history...
178
    }
179
180
    public function testExecuteReturnsNonZeroExitCodeWhenChangesAreDetected() : void
181
    {
182
        $fromSha = sha1('fromRevision', false);
183
        $toSha   = sha1('toRevision', false);
184
185
        $this->input->expects(self::any())->method('getOption')->willReturnMap([
186
            ['from', $fromSha],
187
            ['to', $toSha],
188
        ]);
189
        $this->input->expects(self::any())->method('getArgument')->willReturnMap([
190
            ['sources-path', 'src'],
191
        ]);
192
193
        $this->performCheckout->expects(self::at(0))
194
            ->method('checkout')
195
            ->with($this->sourceRepository, $fromSha)
196
            ->willReturn($this->sourceRepository);
197
        $this->performCheckout->expects(self::at(1))
198
            ->method('checkout')
199
            ->with($this->sourceRepository, $toSha)
200
            ->willReturn($this->sourceRepository);
201
        $this->performCheckout->expects(self::at(2))
202
            ->method('remove')
203
            ->with($this->sourceRepository);
204
        $this->performCheckout->expects(self::at(3))
205
            ->method('remove')
206
            ->with($this->sourceRepository);
207
208
        $this->parseRevision->expects(self::at(0))
209
            ->method('fromStringForRepository')
210
            ->with($fromSha)
211
            ->willReturn(Revision::fromSha1($fromSha));
212
        $this->parseRevision->expects(self::at(1))
213
            ->method('fromStringForRepository')
214
            ->with($toSha)
215
            ->willReturn(Revision::fromSha1($toSha));
216
217
        $this
218
            ->locateDependencies
219
            ->expects(self::any())
220
            ->method('__invoke')
221
            ->with((string) $this->sourceRepository)
222
            ->willReturn($this->dependencies);
223
224
        $this->compareApi->expects(self::once())->method('__invoke')->willReturn(Changes::fromList(
225
            Change::added(uniqid('added', true), true)
226
        ));
227
228
        $this
229
            ->stdErr
230
            ->expects(self::exactly(3))
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Symfony\Component\Console\Output\OutputInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

230
            ->/** @scrutinizer ignore-call */ 
231
              expects(self::exactly(3))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method exactly() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

230
            ->expects(self::/** @scrutinizer ignore-call */ exactly(3))

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
231
            ->method('writeln')
232
            ->with(self::logicalOr(
0 ignored issues
show
Bug introduced by
The method logicalOr() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

232
            ->with(self::/** @scrutinizer ignore-call */ logicalOr(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
233
                self::matches('Comparing from %a to %a...'),
0 ignored issues
show
Bug introduced by
The method matches() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

233
                self::/** @scrutinizer ignore-call */ 
234
                      matches('Comparing from %a to %a...'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
234
                self::matches('[BC] ADDED: added%a'),
235
                self::matches('<error>1 backwards-incompatible changes detected</error>')
236
            ));
237
238
        self::assertSame(3, $this->compare->execute($this->input, $this->output));
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

238
        self::/** @scrutinizer ignore-call */ 
239
              assertSame(3, $this->compare->execute($this->input, $this->output));
Loading history...
Bug introduced by
3 of type integer is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

238
        self::assertSame(/** @scrutinizer ignore-type */ 3, $this->compare->execute($this->input, $this->output));
Loading history...
239
    }
240
241
    public function testProvidingMarkdownOptionWritesMarkdownOutput() : void
242
    {
243
        $fromSha = sha1('fromRevision', false);
244
        $toSha   = sha1('toRevision', false);
245
246
        $this->input->expects(self::any())->method('getOption')->willReturnMap([
247
            ['from', $fromSha],
248
            ['to', $toSha],
249
            ['format', ['markdown']],
250
        ]);
251
        $this->input->expects(self::any())->method('getArgument')->willReturnMap([
252
            ['sources-path', 'src'],
253
        ]);
254
255
        $this->performCheckout->expects(self::at(0))
256
            ->method('checkout')
257
            ->with($this->sourceRepository, $fromSha)
258
            ->willReturn($this->sourceRepository);
259
        $this->performCheckout->expects(self::at(1))
260
            ->method('checkout')
261
            ->with($this->sourceRepository, $toSha)
262
            ->willReturn($this->sourceRepository);
263
        $this->performCheckout->expects(self::at(2))
264
            ->method('remove')
265
            ->with($this->sourceRepository);
266
        $this->performCheckout->expects(self::at(3))
267
            ->method('remove')
268
            ->with($this->sourceRepository);
269
270
        $this->parseRevision->expects(self::at(0))
271
            ->method('fromStringForRepository')
272
            ->with($fromSha)
273
            ->willReturn(Revision::fromSha1($fromSha));
274
        $this->parseRevision->expects(self::at(1))
275
            ->method('fromStringForRepository')
276
            ->with($toSha)
277
            ->willReturn(Revision::fromSha1($toSha));
278
279
        $this
280
            ->locateDependencies
281
            ->method('__invoke')
282
            ->with((string) $this->sourceRepository)
283
            ->willReturn($this->dependencies);
0 ignored issues
show
Bug introduced by
The method willReturn() does not exist on PHPUnit\Framework\MockOb...uilder\InvocationMocker. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

283
            ->/** @scrutinizer ignore-call */ willReturn($this->dependencies);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
284
285
        $changeToExpect = uniqid('changeToExpect', true);
286
        $this->compareApi->expects(self::once())->method('__invoke')->willReturn(Changes::fromList(
287
            Change::removed($changeToExpect, true)
288
        ));
289
290
        $this->output
291
            ->expects(self::once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Symfony\Component\Consol...\ConsoleOutputInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

291
            ->/** @scrutinizer ignore-call */ 
292
              expects(self::once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
292
            ->method('writeln')
293
            ->willReturnCallback(static function (string $output) use ($changeToExpect) : void {
294
                self::assertStringContainsString(' [BC] ' . $changeToExpect, $output);
295
            });
296
297
        $this->compare->execute($this->input, $this->output);
298
    }
299
300
    public function testExecuteWithDefaultRevisionsNotProvidedAndNoDetectedTags() : void
301
    {
302
        $this->input->expects(self::any())->method('getOption')->willReturnMap([
303
            ['from', null],
304
            ['to', 'HEAD'],
305
        ]);
306
        $this->input->expects(self::any())->method('getArgument')->willReturnMap([
307
            ['sources-path', 'src'],
308
        ]);
309
310
        $this
311
            ->performCheckout
312
            ->expects(self::never())
0 ignored issues
show
Bug introduced by
The method never() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

312
            ->expects(self::/** @scrutinizer ignore-call */ never())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
313
            ->method('checkout');
314
        $this
315
            ->parseRevision
316
            ->expects(self::never())
317
            ->method('fromStringForRepository');
318
319
        $this
320
            ->getVersions
321
            ->expects(self::once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...it\GetVersionCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

321
            ->/** @scrutinizer ignore-call */ 
322
              expects(self::once())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
322
            ->method('fromRepository')
323
            ->willReturn(new VersionsCollection());
324
        $this
325
            ->pickVersion
326
            ->expects(self::never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...onFromVersionCollection. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

326
            ->/** @scrutinizer ignore-call */ 
327
              expects(self::never())

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
327
            ->method('forVersions');
328
        $this
329
            ->compareApi
330
            ->expects(self::never())
331
            ->method('__invoke');
332
333
        $this->expectException(AssertionFailedException::class);
334
335
        $this->compare->execute($this->input, $this->output);
336
    }
337
338
    /**
339
     * @dataProvider validVersionsCollections
340
     */
341
    public function testExecuteWithDefaultRevisionsNotProvided(VersionsCollection $versions) : void
342
    {
343
        $fromSha       = sha1('fromRevision', false);
344
        $toSha         = sha1('toRevision', false);
345
        $pickedVersion = Version::fromString('1.0.0');
346
347
        $this->input->expects(self::any())->method('getOption')->willReturnMap([
348
            ['from', null],
349
            ['to', 'HEAD'],
350
        ]);
351
        $this->input->expects(self::any())->method('getArgument')->willReturnMap([
352
            ['sources-path', 'src'],
353
        ]);
354
355
        $this->performCheckout->expects(self::at(0))
356
            ->method('checkout')
357
            ->with($this->sourceRepository, $fromSha)
358
            ->willReturn($this->sourceRepository);
359
        $this->performCheckout->expects(self::at(1))
360
            ->method('checkout')
361
            ->with($this->sourceRepository, $toSha)
362
            ->willReturn($this->sourceRepository);
363
        $this->performCheckout->expects(self::at(2))
364
            ->method('remove')
365
            ->with($this->sourceRepository);
366
        $this->performCheckout->expects(self::at(3))
367
            ->method('remove')
368
            ->with($this->sourceRepository);
369
370
        $this->parseRevision->expects(self::at(0))
371
            ->method('fromStringForRepository')
372
            ->with((string) $pickedVersion)
373
            ->willReturn(Revision::fromSha1($fromSha));
374
        $this->parseRevision->expects(self::at(1))
375
            ->method('fromStringForRepository')
376
            ->with('HEAD')
377
            ->willReturn(Revision::fromSha1($toSha));
378
379
        $this->getVersions->expects(self::once())
380
            ->method('fromRepository')
381
            ->with(self::callback(function (CheckedOutRepository $checkedOutRepository) : bool {
0 ignored issues
show
Bug introduced by
The method callback() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

381
            ->with(self::/** @scrutinizer ignore-call */ callback(function (CheckedOutRepository $checkedOutRepository) : bool {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
382
                self::assertEquals($this->sourceRepository, $checkedOutRepository);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not exist on RoaveTest\BackwardCompat...BackwardsCompatibleTest. Did you maybe mean assertFalse()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

382
                self::/** @scrutinizer ignore-call */ 
383
                      assertEquals($this->sourceRepository, $checkedOutRepository);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
383
384
                return true;
385
            }))
386
            ->willReturn($versions);
387
        $this->pickVersion->expects(self::once())
388
            ->method('forVersions')
389
            ->with($versions)
390
            ->willReturn($pickedVersion);
391
392
        $this
393
            ->stdErr
394
            ->expects(self::exactly(3))
395
            ->method('writeln')
396
            ->with(self::logicalOr(
397
                'Detected last minor version: 1.0.0',
398
                self::matches('Comparing from %a to %a...'),
399
                self::matches('<info>No backwards-incompatible changes detected</info>')
400
            ));
401
402
        $this->compareApi->expects(self::once())->method('__invoke')->willReturn(Changes::empty());
403
404
        self::assertSame(0, $this->compare->execute($this->input, $this->output));
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\Assert::assertSame() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

404
        self::/** @scrutinizer ignore-call */ 
405
              assertSame(0, $this->compare->execute($this->input, $this->output));
Loading history...
Bug introduced by
0 of type integer is incompatible with the type PHPUnit\Framework\T expected by parameter $expected of PHPUnit\Framework\Assert::assertSame(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

404
        self::assertSame(/** @scrutinizer ignore-type */ 0, $this->compare->execute($this->input, $this->output));
Loading history...
405
    }
406
407
    /** @return VersionsCollection[][] */
408
    public function validVersionsCollections() : array
409
    {
410
        return [
411
            [new VersionsCollection(
412
                Version::fromString('1.0.0'),
413
                Version::fromString('1.0.1'),
414
                Version::fromString('1.0.2')
415
            ),
416
            ],
417
            [new VersionsCollection(
418
                Version::fromString('1.0.0'),
419
                Version::fromString('1.0.1')
420
            ),
421
            ],
422
            [new VersionsCollection(Version::fromString('1.0.0'))],
423
        ];
424
    }
425
}
426