-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathtest_compatibility.php
More file actions
58 lines (46 loc) · 1.87 KB
/
test_compatibility.php
File metadata and controls
58 lines (46 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/**
* Test script to verify Composer 2.x compatibility.
*/
require_once __DIR__ . '/vendor/autoload.php';
use Composer\Composer;
use Composer\IO\NullIO;
use Composer\Factory;
use Netresearch\Composer\Patches\Downloader\Composer as ComposerDownloader;
echo "Testing Composer 2.x compatibility...\n";
$io = new NullIO();
$composer = Factory::create($io);
echo 'Composer version: ' . Composer::getVersion() . "\n";
try {
// Test downloader instantiation
$downloader = new ComposerDownloader($io, $composer);
echo "✓ Downloader instantiated successfully\n";
// Test if HttpDownloader is available (Composer 2.x)
if (class_exists('Composer\Util\HttpDownloader')) {
echo "✓ HttpDownloader class available (Composer 2.x detected)\n";
} else {
echo "✓ RemoteFilesystem fallback (Composer 1.x detected)\n";
}
// Check which downloader is actually being used internally
$reflection = new ReflectionClass($downloader);
$property = $reflection->getProperty('downloader');
$property->setAccessible(true);
$internalDownloader = $property->getValue($downloader);
echo '✓ Internal downloader type: ' . get_class($internalDownloader) . "\n";
// Test local file access
$tempFile = tempnam(sys_get_temp_dir(), 'composer_test');
file_put_contents($tempFile, '{"test": "data"}');
try {
$content = $downloader->getContents($tempFile);
echo '✓ getContents() works: ' . trim($content) . "\n";
$jsonData = $downloader->getJson($tempFile);
echo '✓ getJson() works: ' . json_encode($jsonData) . "\n";
} finally {
unlink($tempFile);
}
echo "\n✅ All tests passed! The plugin should work with this Composer version.\n";
} catch (Exception $e) {
echo "\n❌ Error: " . $e->getMessage() . "\n";
echo "Stack trace:\n" . $e->getTraceAsString() . "\n";
exit(1);
}