Skip to content

Commit a7e981b

Browse files
committed
improve integration tests
Make mock of Composer more realistic: - ./vendor/autoload.php actually requires ./composer/autoload_real.php - \Composer\InstalledVersions actually depends on installed.php - installed.php contents is closer to real life
1 parent ef227b4 commit a7e981b

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

tests/integration/autoloader/autoload-with-composer/vendor/autoload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
The agent verifies its presence to determine if PSR-4 Autoloader is used.
1010
*/
1111

12-
echo "";
12+
require_once __DIR__ . '/composer/autoload_real.php';

tests/integration/autoloader/autoload-with-composer/vendor/composer/InstalledVersions.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,34 @@
1212
namespace Composer;
1313
class InstalledVersions
1414
{
15-
// Mocked data: installed packages and their versions
16-
private static $installed = [
17-
'vendor1/package1' => '1.1.3',
18-
'vendor2/package2' => '2.1.5'
19-
];
20-
2115
// This Composer's runtime API method is used by the agent to get the installed version of a package:
2216
public static function getVersion(string $packageName)
2317
{
24-
return self::$installed[$packageName];
18+
$installed = self::getAllRawData();
19+
return $installed[0]['versions'][$packageName]['version'];
2520
}
2621

2722
// This Composer's runtime API method is used by the agent to get the list of installed packages:
2823
public static function getInstalledPackages()
2924
{
3025
// Return the package names
31-
return array_keys(self::$installed);
26+
$installed = self::getAllRawData();
27+
return array_keys($installed[0]['versions']);
28+
}
29+
30+
// This Composer's runtime API method is used by the agent to get the list of installed packages:
31+
public static function getAllRawData()
32+
{
33+
$installed = require __DIR__ . '/installed.php';
34+
// This mock only returns a single dataset; in real life, there could be more
35+
return array($installed);
3236
}
3337

3438
// Mock of 'composer show' used by integration tests to generate list of packages:
3539
public static function show() {
36-
foreach (self::$installed as $package => $version) {
40+
$installed = self::getAllRawData();
41+
foreach ($installed[0]['versions'] as $package => $info) {
42+
$version = ltrim($info['pretty_version'], 'v');
3743
echo "$package => $version\n";
3844
}
3945
}

tests/integration/autoloader/autoload-with-composer/vendor/composer/installed.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,26 @@
66

77
/*DESCRIPTION
88
This file is needed by real Composer's runtime API, and agent verifies its presence to determine if Composer is used.
9-
Therefore, even though mocked version of Composer's runtime API does not use this file but (and that's why its empty),
10-
it still needs to be present.
9+
This file contains phpized version of composer.json for the project and its dependencies.
1110
*/
11+
return array(
12+
// Mocked data: root package
13+
'root' => array(
14+
'pretty_version' => 'v1.0.0',
15+
'version' => '1.0.0.0',
16+
'type' => 'project'
17+
),
18+
// Mocked data: installed packages and their versions
19+
'versions' => array(
20+
'vendor1/package1' => array(
21+
'pretty_version' => 'v1.1.3',
22+
'version' => '1.1.3.0',
23+
'type' => 'library'
24+
),
25+
'vendor2/package2' => array(
26+
'pretty_version' => '2.1.5',
27+
'version' => '2.1.5.0',
28+
'type' => 'library'
29+
)
30+
)
31+
);

0 commit comments

Comments
 (0)