Skip to content

Commit 0a6fc18

Browse files
committed
style: enhance getTestedVersion
1 parent 289d855 commit 0a6fc18

File tree

3 files changed

+33
-40
lines changed

3 files changed

+33
-40
lines changed

tests/Common/IntegrationTestCase.php

+33-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,24 @@ protected static function getTestedVersion($testedLibrary)
143143
$version = trim($output[0]);
144144
}
145145
}
146-
} else {
146+
} elseif (($workingDir = static::getAppIndexScript()) || ($workingDir = static::getConsoleScript())) {
147+
do {
148+
$workingDir = dirname($workingDir);
149+
$composer = $workingDir . '/composer.json';
150+
} while (!file_exists($composer) && basename($workingDir) !== 'tests'); // there is no reason to go further up
151+
152+
if (!file_exists($composer)) {
153+
return null;
154+
}
155+
156+
$output = [];
157+
$command = "composer show $testedLibrary --working-dir=$workingDir | sed -n '/versions/s/^[^0-9]\+\([^,]\+\).*$/\\1/p'";
158+
exec($command, $output, $returnVar);
159+
160+
if ($returnVar === 0) {
161+
$version = trim($output[0]);
162+
}
163+
} elseif (\Composer\InstalledVersions::isInstalled($testedLibrary)) {
147164
$version = \Composer\InstalledVersions::getVersion($testedLibrary);
148165
$version = preg_replace('/^(\d+\.\d+\.\d+).*/', '$1', $version);
149166
}
@@ -187,4 +204,19 @@ public function assertOneSpan($traces, SpanAssertion $expectedSpan)
187204
{
188205
$this->assertOneExpectedSpan($traces, $expectedSpan);
189206
}
207+
208+
public static function getConsoleScript()
209+
{
210+
return null;
211+
}
212+
213+
/**
214+
* Returns the application index.php file full path.
215+
*
216+
* @return string|null
217+
*/
218+
public static function getAppIndexScript()
219+
{
220+
return null;
221+
}
190222
}

tests/Common/WebFrameworkTestCase.php

-34
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,6 @@ protected function ddTearDown()
7676
parent::ddTearDown();
7777
}
7878

79-
/**
80-
* Returns the application index.php file full path.
81-
*
82-
* @return string|null
83-
*/
84-
public static function getAppIndexScript()
85-
{
86-
return null;
87-
}
88-
8979
protected static function getRoadrunnerVersion()
9080
{
9181
return null;
@@ -292,28 +282,4 @@ protected function sendRequest($method, $url, $headers = [], $body = [], $change
292282

293283
return $response;
294284
}
295-
296-
protected static function getTestedVersion($testedLibrary)
297-
{
298-
$workingDir = static::getAppIndexScript();
299-
do {
300-
$workingDir = dirname($workingDir);
301-
$composer = $workingDir . '/composer.json';
302-
} while (!file_exists($composer) && basename($workingDir) !== 'tests'); // there is no reason to go further up
303-
304-
if (!file_exists($composer)) {
305-
return null;
306-
}
307-
308-
$output = [];
309-
$returnVar = 0;
310-
$command = "composer show $testedLibrary --working-dir=$workingDir | sed -n '/versions/s/^[^0-9]\+\([^,]\+\).*$/\\1/p'";
311-
exec($command, $output, $returnVar);
312-
313-
if ($returnVar !== 0) {
314-
return null;
315-
}
316-
317-
return trim($output[0]);
318-
}
319285
}

tests/Integrations/Logs/BaseLogsTest.php

-5
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@
88

99
class BaseLogsTest extends \DDTrace\Tests\Common\IntegrationTestCase
1010
{
11-
public static function getTestedLibrary()
12-
{
13-
return 'monolog/monolog';
14-
}
15-
1611
protected static function logFile()
1712
{
1813
return "/tmp/test-" . substr(static::class, strrpos(static::class, '\\') + 1) . '.log';

0 commit comments

Comments
 (0)