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

LocateDependenciesViaComposerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 60
dl 0
loc 104
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testWillNotLocateDependenciesForANonExistingPath() 0 12 1
A tearDown() 0 5 1
A setUp() 0 14 1
A testWillLocateDependencies() 0 47 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\LocateDependencies;
6
7
use Assert\AssertionFailedException;
8
use Composer\Installer;
9
use PHPUnit\Framework\MockObject\MockObject;
10
use PHPUnit\Framework\TestCase;
11
use ReflectionProperty;
12
use Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer;
13
use Roave\BetterReflection\BetterReflection;
14
use Roave\BetterReflection\SourceLocator\Ast\Locator;
15
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
16
use Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
17
use function Safe\getcwd;
18
use function Safe\realpath;
19
20
/**
21
 * @covers \Roave\BackwardCompatibility\LocateDependencies\LocateDependenciesViaComposer
22
 */
23
final class LocateDependenciesViaComposerTest extends TestCase
24
{
25
    /** @var string */
26
    private $originalCwd;
27
28
    /** @var callable */
29
    private $makeInstaller;
30
31
    /** @var Installer&MockObject */
32
    private $composerInstaller;
33
34
    /** @var string|null */
35
    private $expectedInstallatonPath;
36
37
    /** @var Locator */
38
    private $astLocator;
39
40
    /** @var LocateDependenciesViaComposer */
41
    private $locateDependencies;
42
43
    protected function setUp() : void
44
    {
45
        parent::setUp();
0 ignored issues
show
Bug introduced by
The method setUp() does not exist on PHPUnit\Framework\TestCase. It seems like you code against a sub-type of PHPUnit\Framework\TestCase such as Symfony\Component\Yaml\Tests\InlineTest or SebastianBergmann\Diff\ParserTest or PHP_Token_FunctionTest or SebastianBergmann\Compar...ockObjectComparatorTest or PharIo\Manifest\BundlesElementTest or SebastianBergmann\Diff\O...tBuilderIntegrationTest or PharIo\Manifest\LicenseElementTest or RoaveTest\BackwardCompat...ed\OpenClassChangedTest or ExceptionInSetUpTest or PharIo\Manifest\ManifestTest or SebastianBergmann\GlobalState\BlacklistTest or PHPUnit\Runner\DefaultTestResultCacheTest or RoaveTest\BackwardCompat...tectedMethodChangedTest or PHPUnit\Util\ConfigurationTest or PHPUnit\Framework\TestListenerTest or SebastianBergmann\Diff\U...ertTraitIntegrationTest or BankAccountWithCustomExtensionTest or RoaveTest\BackwardCompat...ipMethodBasedErrorsTest or PHP_Token_IncludeTest or RoaveTest\BackwardCompat...essibleMethodChangeTest or SebastianBergmann\Comparator\DoubleComparatorTest or SebastianBergmann\Compar...\DateTimeComparatorTest or PharIo\Manifest\RequiresElementTest or RoaveTest\BackwardCompat...PropertyBasedErrorsTest or RoaveTest\BackwardCompat...nterfaceBasedErrorsTest or Symfony\Component\Consol...s\Question\QuestionTest or SebastianBergmann\Comparator\ScalarComparatorTest or SebastianBergmann\Comparator\ObjectComparatorTest or Symfony\Component\Consol...\Helper\ProgressBarTest or PHP_Token_ClassTest or PharIo\Manifest\CopyrightElementTest or Symfony\Component\Filesy...ests\FilesystemTestCase or RoaveTest\BackwardCompat...kipTraitBasedErrorsTest or Symfony\Component\Console\Tests\ApplicationTest or PHP_CodeSniffer\Tests\St...s\AbstractSniffUnitTest or PHP_CodeSniffer\Tests\Co...ndExtendedClassNameTest or PHP_CodeSniffer\Tests\Co...GetMethodParametersTest or SebastianBergmann\CodeUnitReverseLookup\WizardTest or PharIo\Manifest\BundledComponentCollectionTest or PHP_CodeSniffer\Tests\Co...entedInterfaceNamesTest or TheSeer\Tokenizer\XMLSerializerTest or PHPUnit\Runner\PhptTestCaseTest or SebastianBergmann\Environment\ConsoleTest or RoaveTest\BackwardCompat...ctedPropertyChangedTest or SebastianBergmann\Type\ObjectTypeTest or RoaveTest\BackwardCompat...lassConstantChangedTest or ExceptionInAssertPreConditionsTest or ExceptionInTearDownTest or RoaveTest\BackwardCompat...d\FinalClassChangedTest or ExceptionInAssertPostConditionsTest or PHPUnit\Framework\TestSuiteTest or TheSeer\Tokenizer\TokenCollectionTest or SebastianBergmann\Object...tor\ObjectReflectorTest or RoaveTest\BackwardCompat...blicPropertyChangedTest or SebastianBergmann\RecursionContext\ContextTest or PHPUnit\SelfTest\Basic\SetUpTest or Symfony\Component\Consol...\Style\SymfonyStyleTest or PharIo\Manifest\ComponentElementTest or Symfony\Component\Consol...ester\CommandTesterTest or PHPUnit\Util\PHP\AbstractPhpProcessTest or SebastianBergmann\Type\IterableTypeTest or SebastianBergmann\Environment\OperatingSystemTest or PharIo\Manifest\LicenseTest or SebastianBergmann\Comparator\TypeComparatorTest or PharIo\Manifest\ExtensionTest or PHPUnit\SelfTest\Basic\SetUpBeforeClassTest or RoaveTest\BackwardCompatibility\CompareClassesTest or SebastianBergmann\CodeCoverage\FilterTest or RoaveTest\BackwardCompat...iblePropertyChangedTest or Humbug\Test\FunctionTest or Symfony\Component\Consol...Output\StreamOutputTest or PharIo\Manifest\ExtElementTest or Symfony\Component\Consol...onsoleSectionOutputTest or SebastianBergmann\Compar...\ResourceComparatorTest or GeneratorTest or ExceptionInTest or RoaveTest\BackwardCompat...FunctionBasedErrorsTest or TemplateMethodsTest or RoaveTest\BackwardCompat...onFromGitRepositoryTest or PharIo\Manifest\AuthorCollectionTest or SebastianBergmann\Comparator\DOMNodeComparatorTest or RoaveTest\BackwardCompat...onDefinitionChangedTest or SebastianBergmann\Exporter\ExporterTest or PharIo\Manifest\RequirementCollectionTest or RoaveTest\BackwardCompat...BackwardsCompatibleTest or PharIo\Manifest\AuthorElementTest or Symfony\Component\Consol...r\ApplicationTesterTest or PHP_CodeSniffer\Tests\Co...GetMemberPropertiesTest or RoaveTest\BackwardCompat...assMapSourceLocatorTest or SebastianBergmann\FileIterator\FactoryTest or PharIo\Manifest\BundledComponentTest or SebastianBergmann\Diff\O...tBuilderIntegrationTest or PharIo\Manifest\AuthorTest or RoaveTest\BackwardCompat...kipClassBasedErrorsTest or PharIo\Manifest\PhpVersionRequirementTest or RoaveE2ETest\BackwardCom...BackwardsCompatibleTest or PHP_CodeSniffer\Tests\Co...GetMethodPropertiesTest or SebastianBergmann\GlobalState\SnapshotTest or Symfony\Component\Console\Tests\TerminalTest or PHP_CodeSniffer\Tests\Co...\FindEndOfStatementTest or PHP_CodeSniffer\Tests\Core\File\IsReferenceTest or PHPUnit\Runner\ResultCacheExtensionTest or TheSeer\Tokenizer\TokenTest or PHPUnit\Util\TestDox\NamePrettifierTest or SebastianBergmann\Comparator\NumericComparatorTest or PHPUnit\Util\TestDox\CliTestDoxPrinterColorTest or PHP_Token_ClosureTest or SebastianBergmann\Diff\LineTest or Symfony\Component\Yaml\Tests\DumperTest or SebastianBergmann\Compar...ctStorageComparatorTest or PharIo\Manifest\LibraryTest or SebastianBergmann\Diff\DifferTest or RoaveTest\BackwardCompat...ConstantBasedErrorsTest or SebastianBergmann\Comparator\ArrayComparatorTest or PhpParser\Builder\InterfaceTest or PharIo\Manifest\CopyrightInformationTest or Symfony\Component\Yaml\T...Command\LintCommandTest or PHPUnit\Util\TestDox\CliTestDoxPrinterTest or SebastianBergmann\Environment\RuntimeTest or RoaveTest\BackwardCompat...rcesViaComposerJsonTest or SebastianBergmann\ObjectEnumerator\EnumeratorTest or SebastianBergmann\Diff\L...stCommonSubsequenceTest or PharIo\Manifest\ContainsElementTest or Issue1374Test or PharIo\Manifest\ApplicationTest or PharIo\Manifest\ExtensionElementTest or BankAccountTest or SebastianBergmann\Type\CallableTypeTest or PharIo\Manifest\PhpElementTest or RoaveTest\BackwardCompat...ndenciesViaComposerTest or SebastianBergmann\Type\NullTypeTest or SebastianBergmann\Type\UnknownTypeTest or PHP_Token_InterfaceTest or RoaveTest\BackwardCompat...lassConstantChangedTest or SebastianBergmann\Compar...ExceptionComparatorTest or SebastianBergmann\Diff\ChunkTest or RoaveTest\BackwardCompat...PublicMethodChangedTest or SebastianBergmann\CodeCoverage\CodeCoverageTest or SebastianBergmann\CodeCoverage\Report\BuilderTest. ( Ignorable by Annotation )

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

45
        parent::/** @scrutinizer ignore-call */ 
46
                setUp();
Loading history...
46
47
        $this->originalCwd       = getcwd();
48
        $this->composerInstaller = $this->createMock(Installer::class);
49
        $this->astLocator        = (new BetterReflection())->astLocator();
50
        $this->makeInstaller     = function (string $installationPath) : Installer {
51
            self::assertSame($this->expectedInstallatonPath, $installationPath);
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

51
            self::/** @scrutinizer ignore-call */ 
52
                  assertSame($this->expectedInstallatonPath, $installationPath);
Loading history...
Bug introduced by
It seems like $this->expectedInstallatonPath can also be of type string; however, parameter $expected of PHPUnit\Framework\Assert::assertSame() does only seem to accept PHPUnit\Framework\T, maybe add an additional type check? ( Ignorable by Annotation )

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

51
            self::assertSame(/** @scrutinizer ignore-type */ $this->expectedInstallatonPath, $installationPath);
Loading history...
52
53
            return $this->composerInstaller;
54
        };
55
56
        $this->locateDependencies = new LocateDependenciesViaComposer($this->makeInstaller, $this->astLocator);
57
    }
58
59
    protected function tearDown() : void
60
    {
61
        self::assertSame($this->originalCwd, getcwd());
0 ignored issues
show
Bug introduced by
$this->originalCwd 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

61
        self::assertSame(/** @scrutinizer ignore-type */ $this->originalCwd, getcwd());
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

61
        self::/** @scrutinizer ignore-call */ 
62
              assertSame($this->originalCwd, getcwd());
Loading history...
62
63
        parent::tearDown();
0 ignored issues
show
Bug introduced by
The method tearDown() does not exist on PHPUnit\Framework\TestCase. It seems like you code against a sub-type of PHPUnit\Framework\TestCase such as SebastianBergmann\Diff\O...tBuilderIntegrationTest or ExceptionInSetUpTest or SebastianBergmann\Diff\U...ertTraitIntegrationTest or Symfony\Component\Process\Tests\ProcessTest or Symfony\Component\Consol...\Helper\ProgressBarTest or Symfony\Component\Filesy...ests\FilesystemTestCase or Symfony\Component\Console\Tests\ApplicationTest or ExceptionInTestDetectedInTeardown or PHP_CodeSniffer\Tests\Co...ndExtendedClassNameTest or PHP_CodeSniffer\Tests\Co...GetMethodParametersTest or Symfony\Component\Proces...ts\ExecutableFinderTest or PHP_CodeSniffer\Tests\Co...entedInterfaceNamesTest or PHPUnit\Runner\PhptTestCaseTest or ExceptionInAssertPreConditionsTest or ExceptionInTearDownTest or ExceptionInAssertPostConditionsTest or PHPUnit\Framework\TestSuiteTest or Symfony\Component\Consol...\Style\SymfonyStyleTest or Symfony\Component\Consol...ester\CommandTesterTest or PHPUnit\Util\PHP\AbstractPhpProcessTest or Humbug\Test\FunctionTest or Symfony\Component\Consol...Output\StreamOutputTest or Symfony\Component\Consol...onsoleSectionOutputTest or ExceptionInTest or TemplateMethodsTest or RoaveTest\BackwardCompat...onFromGitRepositoryTest or Symfony\Component\Consol...r\ApplicationTesterTest or PHP_CodeSniffer\Tests\Co...GetMemberPropertiesTest or SebastianBergmann\Diff\O...tBuilderIntegrationTest or RoaveE2ETest\BackwardCom...BackwardsCompatibleTest or PHP_CodeSniffer\Tests\Co...GetMethodPropertiesTest or Symfony\Component\Console\Tests\TerminalTest or PHP_CodeSniffer\Tests\Co...\FindEndOfStatementTest or PHP_CodeSniffer\Tests\Core\File\IsReferenceTest or PHPUnit\Util\TestDox\NamePrettifierTest or PHPUnit\Util\TestDox\CliTestDoxPrinterColorTest or Symfony\Component\Yaml\Tests\DumperTest or Symfony\Component\Yaml\T...Command\LintCommandTest or PHPUnit\Util\TestDox\CliTestDoxPrinterTest or SebastianBergmann\Diff\L...stCommonSubsequenceTest or Issue1374Test or RoaveTest\BackwardCompat...ndenciesViaComposerTest or PHP_CodeSniffer\Standard...ts\Debug\ESLintUnitTest or SebastianBergmann\CodeCo...ge\Report\Html\HTMLTest or SebastianBergmann\CodeCoverage\Report\Xml\XmlTest. ( Ignorable by Annotation )

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

63
        parent::/** @scrutinizer ignore-call */ 
64
                tearDown();
Loading history...
64
    }
65
66
    public function testWillNotLocateDependenciesForANonExistingPath() : void
67
    {
68
        $this
69
            ->composerInstaller
70
            ->expects(self::never())
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

70
            ->/** @scrutinizer ignore-call */ 
71
              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...
Bug introduced by
The method expects() does not exist on Composer\Installer. ( Ignorable by Annotation )

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

70
            ->/** @scrutinizer ignore-call */ 
71
              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...
Bug introduced by
The method never() does not exist on RoaveTest\BackwardCompat...ndenciesViaComposerTest. ( Ignorable by Annotation )

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

70
            ->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...
71
            ->method('run');
72
73
        $this->expectException(AssertionFailedException::class);
74
75
        $this
76
            ->locateDependencies
77
            ->__invoke(__DIR__ . '/non-existing');
78
    }
79
80
    public function testWillLocateDependencies() : void
81
    {
82
        $this->expectedInstallatonPath = realpath(__DIR__ . '/../../asset/composer-installation-structure');
83
84
        $this
85
            ->composerInstaller
86
            ->expects(self::atLeastOnce())
0 ignored issues
show
Bug introduced by
The method atLeastOnce() does not exist on RoaveTest\BackwardCompat...ndenciesViaComposerTest. ( Ignorable by Annotation )

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

86
            ->expects(self::/** @scrutinizer ignore-call */ atLeastOnce())

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...
87
            ->method('setDevMode')
88
            ->with(false);
89
        $this
90
            ->composerInstaller
91
            ->expects(self::atLeastOnce())
92
            ->method('setDumpAutoloader')
93
            ->with(false);
94
        $this
95
            ->composerInstaller
96
            ->expects(self::atLeastOnce())
97
            ->method('setRunScripts')
98
            ->with(false);
99
        $this
100
            ->composerInstaller
101
            ->expects(self::atLeastOnce())
102
            ->method('setIgnorePlatformRequirements')
103
            ->with(true);
104
105
        $this
106
            ->composerInstaller
107
            ->expects(self::once())
0 ignored issues
show
Bug introduced by
The method once() does not exist on RoaveTest\BackwardCompat...ndenciesViaComposerTest. ( Ignorable by Annotation )

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

107
            ->expects(self::/** @scrutinizer ignore-call */ 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...
108
            ->method('run')
109
            ->willReturnCallback(function () : void {
110
                self::assertSame($this->expectedInstallatonPath, getcwd());
0 ignored issues
show
Bug introduced by
It seems like $this->expectedInstallatonPath can also be of type string; however, parameter $expected of PHPUnit\Framework\Assert::assertSame() does only seem to accept PHPUnit\Framework\T, maybe add an additional type check? ( Ignorable by Annotation )

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

110
                self::assertSame(/** @scrutinizer ignore-type */ $this->expectedInstallatonPath, getcwd());
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

110
                self::/** @scrutinizer ignore-call */ 
111
                      assertSame($this->expectedInstallatonPath, getcwd());
Loading history...
111
            });
112
113
        $locator = $this
114
            ->locateDependencies
115
            ->__invoke($this->expectedInstallatonPath);
116
117
        self::assertInstanceOf(AggregateSourceLocator::class, $locator);
118
119
        $reflectionLocators = new ReflectionProperty(AggregateSourceLocator::class, 'sourceLocators');
120
121
        $reflectionLocators->setAccessible(true);
122
123
        $locators = $reflectionLocators->getValue($locator);
124
125
        self::assertCount(2, $locators);
0 ignored issues
show
Bug introduced by
The method assertCount() does not exist on RoaveTest\BackwardCompat...ndenciesViaComposerTest. ( Ignorable by Annotation )

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

125
        self::/** @scrutinizer ignore-call */ 
126
              assertCount(2, $locators);

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...
126
        self::assertInstanceOf(PhpInternalSourceLocator::class, $locators[1]);
127
    }
128
}
129