|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Flex\Tests; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Flex\Cache; |
| 16 | + |
| 17 | +class CacheTest extends TestCase |
| 18 | +{ |
| 19 | + /** |
| 20 | + * @dataProvider provideRemoveLegacyTags |
| 21 | + */ |
| 22 | + public function testRemoveLegacyTags(array $expected, array $packages, string $symfonyRequire) |
| 23 | + { |
| 24 | + $cache = (new \ReflectionClass(Cache::class))->newInstanceWithoutConstructor(); |
| 25 | + $cache->setSymfonyRequire($symfonyRequire); |
| 26 | + |
| 27 | + $this->assertSame(['packages' => $expected], $cache->removeLegacyTags(['packages' => $packages])); |
| 28 | + } |
| 29 | + |
| 30 | + public function provideRemoveLegacyTags() |
| 31 | + { |
| 32 | + yield 'no-symfony/symfony' => [[123], [123], '~1']; |
| 33 | + |
| 34 | + $branchAlias = function ($versionAlias) { |
| 35 | + return [ |
| 36 | + 'extra' => [ |
| 37 | + 'branch-alias' => [ |
| 38 | + 'dev-master' => $versionAlias.'-dev', |
| 39 | + ], |
| 40 | + ], |
| 41 | + ]; |
| 42 | + }; |
| 43 | + |
| 44 | + $packages = [ |
| 45 | + 'foo/unrelated' => [ |
| 46 | + '1.0.0' => [], |
| 47 | + ], |
| 48 | + 'symfony/symfony' => [ |
| 49 | + '3.3.0' => [ |
| 50 | + 'version_normalized' => '3.3.0.0', |
| 51 | + 'replace' => ['symfony/foo' => 'self.version'], |
| 52 | + ], |
| 53 | + '3.4.0' => [ |
| 54 | + 'version_normalized' => '3.4.0.0', |
| 55 | + 'replace' => ['symfony/foo' => 'self.version'], |
| 56 | + ], |
| 57 | + 'dev-master' => $branchAlias('3.5') + [ |
| 58 | + 'replace' => ['symfony/foo' => 'self.version'], |
| 59 | + ], |
| 60 | + ], |
| 61 | + 'symfony/foo' => [ |
| 62 | + '3.3.0' => ['version_normalized' => '3.3.0.0'], |
| 63 | + '3.4.0' => ['version_normalized' => '3.4.0.0'], |
| 64 | + 'dev-master' => $branchAlias('3.5'), |
| 65 | + ], |
| 66 | + ]; |
| 67 | + |
| 68 | + yield 'empty-intersection-ignores' => [$packages, $packages, '~2.0']; |
| 69 | + yield 'empty-intersection-ignores' => [$packages, $packages, '~4.0']; |
| 70 | + |
| 71 | + $expected = $packages; |
| 72 | + unset($expected['symfony/symfony']['3.3.0']); |
| 73 | + unset($expected['symfony/foo']['3.3.0']); |
| 74 | + |
| 75 | + yield 'non-empty-intersection-filters' => [$expected, $packages, '~3.4']; |
| 76 | + |
| 77 | + unset($expected['symfony/symfony']['3.4.0']); |
| 78 | + unset($expected['symfony/foo']['3.4.0']); |
| 79 | + |
| 80 | + yield 'master-only' => [$expected, $packages, '~3.5']; |
| 81 | + |
| 82 | + $packages = [ |
| 83 | + 'symfony/symfony' => [ |
| 84 | + '2.8.0' => [ |
| 85 | + 'version_normalized' => '2.8.0.0', |
| 86 | + 'replace' => [ |
| 87 | + 'symfony/legacy' => 'self.version', |
| 88 | + 'symfony/foo' => 'self.version', |
| 89 | + ], |
| 90 | + ], |
| 91 | + ], |
| 92 | + 'symfony/legacy' => [ |
| 93 | + '2.8.0' => ['version_normalized' => '2.8.0.0'], |
| 94 | + 'dev-master' => $branchAlias('2.8'), |
| 95 | + ], |
| 96 | + ]; |
| 97 | + |
| 98 | + yield 'legacy-are-not-filtered' => [$packages, $packages, '~3.0']; |
| 99 | + |
| 100 | + $packages = [ |
| 101 | + 'symfony/symfony' => [ |
| 102 | + '2.8.0' => [ |
| 103 | + 'version_normalized' => '2.8.0.0', |
| 104 | + 'replace' => [ |
| 105 | + 'symfony/foo' => 'self.version', |
| 106 | + 'symfony/new' => 'self.version', |
| 107 | + ], |
| 108 | + ], |
| 109 | + 'dev-master' => $branchAlias('3.0') + [ |
| 110 | + 'replace' => [ |
| 111 | + 'symfony/foo' => 'self.version', |
| 112 | + 'symfony/new' => 'self.version', |
| 113 | + ], |
| 114 | + ], |
| 115 | + ], |
| 116 | + 'symfony/foo' => [ |
| 117 | + '2.8.0' => ['version_normalized' => '2.8.0.0'], |
| 118 | + 'dev-master' => $branchAlias('3.0'), |
| 119 | + ], |
| 120 | + 'symfony/new' => [ |
| 121 | + 'dev-master' => $branchAlias('3.0'), |
| 122 | + ], |
| 123 | + ]; |
| 124 | + |
| 125 | + $expected = $packages; |
| 126 | + unset($expected['symfony/symfony']['dev-master']); |
| 127 | + unset($expected['symfony/foo']['dev-master']); |
| 128 | + |
| 129 | + yield 'master-is-filtered-only-when-in-range' => [$expected, $packages, '~2.8']; |
| 130 | + } |
| 131 | +} |
0 commit comments