diff --git a/composer.json b/composer.json
index bf198dd4..4342feb3 100644
--- a/composer.json
+++ b/composer.json
@@ -22,9 +22,10 @@
"doctrine/coding-standard": "^6.0",
"monolog/monolog": "^1.25",
"phpunit/phpunit": "^7.5.20",
+ "psalm/plugin-phpunit": "^0.15.0",
"psr/log": "^1.1",
"roave/doctrine-simplecache": "^2.2",
- "vimeo/psalm": "^3.12.2"
+ "vimeo/psalm": "^4.3.1"
},
"suggest": {
"ext-scoutapm": "Recommended for additional recording capability of IO-bound PHP internal functions"
diff --git a/composer.lock b/composer.lock
index 7638a183..2ce6412e 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "1a1ce23af38e3b17fa14572688dc3b79",
+ "content-hash": "856717139c8a3516b707ae846e84609e",
"packages": [
{
"name": "composer/package-versions-deprecated",
@@ -2310,6 +2310,66 @@
},
"time": "2020-01-08T08:45:45+00:00"
},
+ {
+ "name": "psalm/plugin-phpunit",
+ "version": "0.15.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/psalm/psalm-plugin-phpunit.git",
+ "reference": "a7c00148dda987252c7957dcce7914dac91a2b03"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/psalm/psalm-plugin-phpunit/zipball/a7c00148dda987252c7957dcce7914dac91a2b03",
+ "reference": "a7c00148dda987252c7957dcce7914dac91a2b03",
+ "shasum": ""
+ },
+ "require": {
+ "composer/package-versions-deprecated": "^1.10",
+ "composer/semver": "^1.4 || ^2.0 || ^3.0",
+ "ext-simplexml": "*",
+ "php": "^7.1 || ^8.0",
+ "vimeo/psalm": "dev-master || dev-4.x || ^4.0"
+ },
+ "conflict": {
+ "phpunit/phpunit": "<7.5"
+ },
+ "require-dev": {
+ "codeception/codeception": "^4.0.3",
+ "php": "^7.3 || ^8.0",
+ "phpunit/phpunit": "^7.5 || ^8.0 || ^9.0",
+ "squizlabs/php_codesniffer": "^3.3.1",
+ "weirdan/codeception-psalm-module": "^0.11.0",
+ "weirdan/prophecy-shim": "^1.0 || ^2.0"
+ },
+ "type": "psalm-plugin",
+ "extra": {
+ "psalm": {
+ "pluginClass": "Psalm\\PhpUnitPlugin\\Plugin"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Psalm\\PhpUnitPlugin\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Matt Brown",
+ "email": "github@muglug.com"
+ }
+ ],
+ "description": "Psalm plugin for PHPUnit",
+ "support": {
+ "issues": "https://github.com/psalm/psalm-plugin-phpunit/issues",
+ "source": "https://github.com/psalm/psalm-plugin-phpunit/tree/0.15.0"
+ },
+ "time": "2020-12-10T22:51:05+00:00"
+ },
{
"name": "psr/container",
"version": "1.0.0",
@@ -3584,16 +3644,16 @@
},
{
"name": "vimeo/psalm",
- "version": "3.18.2",
+ "version": "4.3.1",
"source": {
"type": "git",
"url": "https://github.com/vimeo/psalm.git",
- "reference": "19aa905f7c3c7350569999a93c40ae91ae4e1626"
+ "reference": "2feba22a005a18bf31d4c7b9bdb9252c73897476"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/vimeo/psalm/zipball/19aa905f7c3c7350569999a93c40ae91ae4e1626",
- "reference": "19aa905f7c3c7350569999a93c40ae91ae4e1626",
+ "url": "https://api.github.com/repos/vimeo/psalm/zipball/2feba22a005a18bf31d4c7b9bdb9252c73897476",
+ "reference": "2feba22a005a18bf31d4c7b9bdb9252c73897476",
"shasum": ""
},
"require": {
@@ -3612,12 +3672,11 @@
"felixfbecker/advanced-json-rpc": "^3.0.3",
"felixfbecker/language-server-protocol": "^1.4",
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0",
- "nikic/php-parser": "4.3.* || 4.4.* || 4.5.* || 4.6.* || ^4.8",
+ "nikic/php-parser": "^4.10.1",
"openlss/lib-array2xml": "^1.0",
- "php": "^7.1.3|^8",
+ "php": "^7.1|^8",
"sebastian/diff": "^3.0 || ^4.0",
"symfony/console": "^3.4.17 || ^4.1.6 || ^5.0",
- "webmozart/glob": "^4.1",
"webmozart/path-util": "^2.3"
},
"provide": {
@@ -3628,11 +3687,12 @@
"bamarni/composer-bin-plugin": "^1.2",
"brianium/paratest": "^4.0.0",
"ext-curl": "*",
- "phpdocumentor/reflection-docblock": "^4.3.4 || ^5",
+ "php": "^7.3|^8",
+ "phpdocumentor/reflection-docblock": "^5",
"phpmyadmin/sql-parser": "5.1.0",
"phpspec/prophecy": ">=1.9.0",
- "phpunit/phpunit": "^7.5.16 || ^8.5 || ^9.0",
- "psalm/plugin-phpunit": "^0.11",
+ "phpunit/phpunit": "^9.0",
+ "psalm/plugin-phpunit": "^0.13",
"slevomat/coding-standard": "^5.0",
"squizlabs/php_codesniffer": "^3.5",
"symfony/process": "^4.3",
@@ -3651,7 +3711,8 @@
"type": "library",
"extra": {
"branch-alias": {
- "dev-master": "3.x-dev",
+ "dev-master": "4.x-dev",
+ "dev-3.x": "3.x-dev",
"dev-2.x": "2.x-dev",
"dev-1.x": "1.x-dev"
}
@@ -3682,60 +3743,9 @@
],
"support": {
"issues": "https://github.com/vimeo/psalm/issues",
- "source": "https://github.com/vimeo/psalm/tree/3.18.2"
- },
- "time": "2020-10-20T13:48:22+00:00"
- },
- {
- "name": "webmozart/glob",
- "version": "4.1.0",
- "source": {
- "type": "git",
- "url": "https://github.com/webmozart/glob.git",
- "reference": "3cbf63d4973cf9d780b93d2da8eec7e4a9e63bbe"
- },
- "dist": {
- "type": "zip",
- "url": "https://api.github.com/repos/webmozart/glob/zipball/3cbf63d4973cf9d780b93d2da8eec7e4a9e63bbe",
- "reference": "3cbf63d4973cf9d780b93d2da8eec7e4a9e63bbe",
- "shasum": ""
- },
- "require": {
- "php": "^5.3.3|^7.0",
- "webmozart/path-util": "^2.2"
- },
- "require-dev": {
- "phpunit/phpunit": "^4.6",
- "sebastian/version": "^1.0.1",
- "symfony/filesystem": "^2.5"
- },
- "type": "library",
- "extra": {
- "branch-alias": {
- "dev-master": "4.1-dev"
- }
- },
- "autoload": {
- "psr-4": {
- "Webmozart\\Glob\\": "src/"
- }
- },
- "notification-url": "https://packagist.org/downloads/",
- "license": [
- "MIT"
- ],
- "authors": [
- {
- "name": "Bernhard Schussek",
- "email": "bschussek@gmail.com"
- }
- ],
- "description": "A PHP implementation of Ant's glob.",
- "support": {
- "issues": "https://github.com/webmozart/glob/issues",
- "source": "https://github.com/webmozart/glob/tree/master"
+ "source": "https://github.com/vimeo/psalm/tree/4.3.1"
},
- "time": "2015-12-29T11:14:33+00:00"
+ "time": "2020-12-03T16:44:10+00:00"
},
{
"name": "webmozart/path-util",
diff --git a/psalm.xml.dist b/psalm.xml.dist
index d574a6ac..596fd544 100644
--- a/psalm.xml.dist
+++ b/psalm.xml.dist
@@ -1,12 +1,12 @@
+
@@ -14,8 +14,24 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Connector/SocketConnector.php b/src/Connector/SocketConnector.php
index 08eb49a5..66a31aaa 100644
--- a/src/Connector/SocketConnector.php
+++ b/src/Connector/SocketConnector.php
@@ -153,6 +153,7 @@ public function sendCommand(Command $message) : string
throw Exception\FailedToSendCommand::fromEmptyResponseSize($message, $this->connectionAddress);
}
+ /** @var mixed[]|false $responseLengthUnpacked */
$responseLengthUnpacked = unpack('Nlen', $responseLengthPacked);
if (! is_array($responseLengthUnpacked) || ! array_key_exists('len', $responseLengthUnpacked)) {
diff --git a/src/Events/Request/Request.php b/src/Events/Request/Request.php
index a1ddafce..5dc154be 100644
--- a/src/Events/Request/Request.php
+++ b/src/Events/Request/Request.php
@@ -236,6 +236,26 @@ public function tag(string $tagName, $value) : void
* turn this object into a list of commands to send to the CoreAgent
*
* @return array>>>
+ *
+ * @todo document more of the command structures better:
+ * @psalm-suppress InvalidReturnType
+ * @psalm-return array{
+ * BatchCommand: array{
+ * commands: list<
+ * array{
+ * StartRequest: array{
+ * request_id: string,
+ * timestamp: string|null,
+ * }
+ * }|array{
+ * FinishRequest: array{
+ * request_id: string,
+ * timestamp: string|null,
+ * }
+ * }
+ * >
+ * }
+ * }
*/
public function jsonSerialize() : array
{
@@ -260,6 +280,7 @@ public function jsonSerialize() : array
],
];
+ /** @psalm-suppress InvalidReturnStatement */
return [
'BatchCommand' => ['commands' => $commands],
];
diff --git a/src/Events/Tag/TagRequest.php b/src/Events/Tag/TagRequest.php
index 5339b3bf..3486330b 100644
--- a/src/Events/Tag/TagRequest.php
+++ b/src/Events/Tag/TagRequest.php
@@ -17,7 +17,20 @@
*/
class TagRequest extends Tag
{
- /** @return array> */
+ /**
+ * @return string[][][]|array[][][]|bool[][][]|null[][][]
+ *
+ * @psalm-return list<
+ * array{
+ * TagRequest: array{
+ * request_id: string,
+ * tag: string,
+ * value: mixed,
+ * timestamp: string
+ * }
+ * }
+ * >
+ */
public function jsonSerialize() : array
{
// Format the timestamp
diff --git a/src/Events/Tag/TagSpan.php b/src/Events/Tag/TagSpan.php
index f84a7f92..ffc6be0a 100644
--- a/src/Events/Tag/TagSpan.php
+++ b/src/Events/Tag/TagSpan.php
@@ -30,7 +30,19 @@ public function __construct(string $tag, $value, RequestId $requestId, SpanId $s
}
/**
- * @return array>
+ * @return string[][][]|array[][][]|bool[][][]|null[][][]
+ *
+ * @psalm-return list<
+ * array{
+ * TagSpan: array{
+ * request_id: string,
+ * span_id: string,
+ * tag: string,
+ * value: mixed,
+ * timestamp: string
+ * }
+ * }
+ * >
*/
public function jsonSerialize() : array
{
diff --git a/src/Extension/PotentiallyAvailableExtensionCapabilities.php b/src/Extension/PotentiallyAvailableExtensionCapabilities.php
index 36e41ef1..e05039a2 100644
--- a/src/Extension/PotentiallyAvailableExtensionCapabilities.php
+++ b/src/Extension/PotentiallyAvailableExtensionCapabilities.php
@@ -13,7 +13,11 @@
final class PotentiallyAvailableExtensionCapabilities implements ExtentionCapabilities
{
- /** @return RecordedCall[]|array */
+ /**
+ * @return RecordedCall[]
+ *
+ * @psalm-return list
+ */
public function getCalls() : array
{
if (! $this->extensionIsAvailable()) {
diff --git a/src/Extension/RecordedCall.php b/src/Extension/RecordedCall.php
index b27b0480..1e360a27 100644
--- a/src/Extension/RecordedCall.php
+++ b/src/Extension/RecordedCall.php
@@ -54,10 +54,10 @@ public static function fromExtensionLoggedCallArray(array $extensionCall) : self
Assert::keyExists($extensionCall, 'argv');
return new self(
- (string) $extensionCall['function'],
- (float) $extensionCall['time_taken'],
- (float) $extensionCall['entered'],
- (float) $extensionCall['exited'],
+ $extensionCall['function'],
+ $extensionCall['time_taken'],
+ $extensionCall['entered'],
+ $extensionCall['exited'],
$extensionCall['argv']
);
}
diff --git a/src/Helper/RecursivelyCountSpans.php b/src/Helper/RecursivelyCountSpans.php
index 1658a62d..4e760e03 100644
--- a/src/Helper/RecursivelyCountSpans.php
+++ b/src/Helper/RecursivelyCountSpans.php
@@ -13,7 +13,7 @@ abstract class RecursivelyCountSpans
/** @param Command[] $commands */
public static function forCommands(array $commands) : int
{
- return (int) array_reduce(
+ return array_reduce(
$commands,
static function (int $carry, Command $item) : int {
if (! $item instanceof Span) {
diff --git a/tests/Integration/AgentTest.php b/tests/Integration/AgentTest.php
index b092c3e6..baf4f05e 100644
--- a/tests/Integration/AgentTest.php
+++ b/tests/Integration/AgentTest.php
@@ -14,6 +14,7 @@
use Scoutapm\Connector\SocketConnector;
use Scoutapm\Events\Span\SpanReference;
use Scoutapm\Extension\PotentiallyAvailableExtensionCapabilities;
+use function assert;
use function file_get_contents;
use function fopen;
use function function_exists;
@@ -47,13 +48,15 @@ public function setUp() : void
parent::setUp();
// Note, env var name is intentionally inconsistent (i.e. not `SCOUT_KEY`) as we only want to affect this test
- $this->scoutApmKey = getenv('SCOUT_APM_KEY');
+ $scoutApmKey = getenv('SCOUT_APM_KEY');
- if ($this->scoutApmKey === false || $this->scoutApmKey === '') {
+ if ($scoutApmKey === false || $scoutApmKey === '') {
self::markTestSkipped('Set the environment variable SCOUT_APM_KEY to enable this test.');
return;
}
+
+ $this->scoutApmKey = $scoutApmKey;
}
public function tearDown() : void
@@ -65,7 +68,9 @@ public function tearDown() : void
private function cleanUpTestAssets() : void
{
+ /** @psalm-suppress ForbiddenCode */
shell_exec('killall -q core-agent || true');
+ /** @psalm-suppress ForbiddenCode */
shell_exec('rm -Rf /tmp/scout_apm_core');
}
@@ -118,6 +123,8 @@ public function testForMemoryLeaksWhenHandlingJobQueues() : void
$i
));
+ assert($span !== null);
+
$span->tag('something', str_repeat('a', $tagSize));
$this->agent->stopSpan();
diff --git a/tests/Integration/MessageCapturingConnectorDelegator.php b/tests/Integration/MessageCapturingConnectorDelegator.php
index 03bd2af0..77b66a76 100644
--- a/tests/Integration/MessageCapturingConnectorDelegator.php
+++ b/tests/Integration/MessageCapturingConnectorDelegator.php
@@ -11,7 +11,7 @@
final class MessageCapturingConnectorDelegator implements Connector
{
- /** @var Command[] */
+ /** @var array */
public $sentMessages = [];
/** @var Connector */
diff --git a/tests/Integration/TestHelper.php b/tests/Integration/TestHelper.php
index 8595436d..c24a1420 100644
--- a/tests/Integration/TestHelper.php
+++ b/tests/Integration/TestHelper.php
@@ -24,8 +24,8 @@ public static function scoutApmExtensionAvailable() : bool
}
/**
- * @param string[]|callable[]|array $keysAndValuesToExpect
- * @param mixed[][]|array> $actualCommand
+ * @param string[]|callable[]|array $keysAndValuesToExpect
+ * @param mixed[][]|array> $actualCommand
*/
public static function assertUnserializedCommandContainsPayload(
string $expectedCommand,
diff --git a/tests/Unit/AgentTest.php b/tests/Unit/AgentTest.php
index 1a9723af..70b8352d 100644
--- a/tests/Unit/AgentTest.php
+++ b/tests/Unit/AgentTest.php
@@ -16,6 +16,7 @@
use Scoutapm\Cache\DevNullCache;
use Scoutapm\Config;
use Scoutapm\Config\ConfigKey;
+use Scoutapm\Connector\Command;
use Scoutapm\Connector\Connector;
use Scoutapm\Connector\Exception\FailedToConnect;
use Scoutapm\Connector\Exception\FailedToSendCommand;
@@ -25,6 +26,7 @@
use Scoutapm\Events\Request\Request;
use Scoutapm\Events\Span\Span;
use Scoutapm\Events\Span\SpanReference;
+use Scoutapm\Events\Tag\Tag;
use Scoutapm\Events\Tag\TagRequest;
use Scoutapm\Extension\ExtentionCapabilities;
use Scoutapm\Extension\RecordedCall;
@@ -32,6 +34,7 @@
use Scoutapm\IntegrationTests\TestHelper;
use Scoutapm\ScoutApmAgent;
use function array_map;
+use function assert;
use function end;
use function json_encode;
use function microtime;
@@ -62,6 +65,22 @@ public function setUp() : void
$this->phpExtension = $this->createMock(ExtentionCapabilities::class);
}
+ private function requestFromAgent(ScoutApmAgent $agent) : ?Request
+ {
+ /** @psalm-suppress DeprecatedMethod */
+ return $agent->getRequest();
+ }
+
+ /** @return array */
+ private function eventsFromAgent(ScoutApmAgent $agent) : array
+ {
+ $request = $this->requestFromAgent($agent);
+ assert($request !== null);
+
+ /** @psalm-suppress DeprecatedMethod */
+ return $request->getEvents();
+ }
+
/** @param mixed[]|array $config */
private function agentFromConfigArray(array $config = []) : ScoutApmAgent
{
@@ -234,6 +253,8 @@ public function testFullAgentSequence() : void
// Start a Child Span
$span = $agent->startSpan('SQL/Query');
+ self::assertNotNull($span);
+
// Tag the span
$span->tag('sql.query', 'select * from foo');
@@ -252,7 +273,9 @@ public function testInstrumentNamesSpanAndReturnsValueFromClosureAndStopsSpan()
{
$agent = $this->agentFromConfigArray();
- $retval = $agent->instrument('Custom', 'Test', static function (SpanReference $span) {
+ $retval = $agent->instrument('Custom', 'Test', static function (?SpanReference $span) {
+ self::assertNotNull($span);
+
$span->tag('OMG', 'Thingy');
self::assertSame($span->getName(), 'Custom/Test');
@@ -264,18 +287,28 @@ public function testInstrumentNamesSpanAndReturnsValueFromClosureAndStopsSpan()
self::assertSame($retval, 'arbitrary return value');
// Check that the span was stopped and tagged
- $events = $agent->getRequest()->getEvents();
+ $events = $this->eventsFromAgent($agent);
$foundSpan = end($events);
self::assertInstanceOf(Span::class, $foundSpan);
self::assertNotNull($foundSpan->getStopTime());
- self::assertSame($foundSpan->getTags()[0]->getTag(), 'OMG');
- self::assertSame($foundSpan->getTags()[0]->getValue(), 'Thingy');
+
+ $firstTag = static function (Span $span) : Tag {
+ /** @psalm-suppress DeprecatedMethod */
+ $tags = $span->getTags();
+
+ return reset($tags);
+ };
+ $tag = $firstTag($foundSpan);
+ self::assertSame($tag->getTag(), 'OMG');
+ self::assertSame($tag->getValue(), 'Thingy');
}
public function testWebTransactionNamesSpanCorrectlyAndReturnsValueFromClosure() : void
{
self::assertSame(
- $this->agentFromConfigArray()->webTransaction('Test', static function (SpanReference $span) {
+ $this->agentFromConfigArray()->webTransaction('Test', static function (?SpanReference $span) {
+ self::assertNotNull($span);
+
// Check span name is prefixed with "Controller"
self::assertSame($span->getName(), 'Controller/Test');
@@ -288,7 +321,9 @@ public function testWebTransactionNamesSpanCorrectlyAndReturnsValueFromClosure()
public function testBackgroundTransactionNamesSpanCorrectlyAndReturnsValueFromClosure() : void
{
self::assertSame(
- $this->agentFromConfigArray()->backgroundTransaction('Test', static function (SpanReference $span) {
+ $this->agentFromConfigArray()->backgroundTransaction('Test', static function (?SpanReference $span) {
+ self::assertNotNull($span);
+
// Check span name is prefixed with "Job"
self::assertSame($span->getName(), 'Job/Test');
@@ -301,6 +336,7 @@ public function testBackgroundTransactionNamesSpanCorrectlyAndReturnsValueFromCl
public function testStartSpan() : void
{
$span = $this->agentFromConfigArray()->startSpan('foo/bar');
+ self::assertNotNull($span);
self::assertSame('foo/bar', $span->getName());
}
@@ -308,6 +344,7 @@ public function testStopSpan() : void
{
$agent = $this->agentFromConfigArray();
$span = $agent->startSpan('foo/bar');
+ self::assertNotNull($span);
self::assertNull($span->getStopTime());
$agent->stopSpan();
@@ -320,7 +357,7 @@ public function testTagRequest() : void
$agent = $this->agentFromConfigArray();
$agent->tagRequest('foo', 'bar');
- $events = $agent->getRequest()->getEvents();
+ $events = $this->eventsFromAgent($agent);
$tag = end($events);
@@ -478,14 +515,14 @@ public function testRequestIsResetAfterCallingSend() : void
ConfigKey::CORE_AGENT_LAUNCH_ENABLED => false,
]);
- $requestBeforeSend = $agent->getRequest();
+ $requestBeforeSend = $this->requestFromAgent($agent);
$this->connector->method('connected')->willReturn(true);
$this->connector->expects(self::exactly(3))->method('sendCommand');
self::assertTrue($agent->send());
- self::assertNotSame($requestBeforeSend, $agent->getRequest());
+ self::assertNotSame($requestBeforeSend, $this->requestFromAgent($agent));
}
public function testRegisterEventIsOnlySentOnceWhenSendingTwoRequestsWithSameAgent() : void
@@ -529,11 +566,11 @@ public function testRequestIsResetAfterStartingANewRequest() : void
ConfigKey::MONITORING_ENABLED => true,
]);
- $requestBeforeReset = $agent->getRequest();
+ $requestBeforeReset = $this->requestFromAgent($agent);
$agent->startNewRequest();
- self::assertNotSame($requestBeforeReset, $agent->getRequest());
+ self::assertNotSame($requestBeforeReset, $this->requestFromAgent($agent));
}
public function testAgentLogsWarningWhenFailingToConnectToSocket() : void
diff --git a/tests/Unit/Events/Request/RequestTest.php b/tests/Unit/Events/Request/RequestTest.php
index dc2ef82c..ef6fa8ae 100644
--- a/tests/Unit/Events/Request/RequestTest.php
+++ b/tests/Unit/Events/Request/RequestTest.php
@@ -25,12 +25,6 @@ final class RequestTest extends TestCase
{
private const FIXED_POINT_UNIX_EPOCH_SECONDS = 1000000000.0;
- public function testCanBeInitialized() : void
- {
- $request = new Request();
- self::assertNotNull($request);
- }
-
public function testExceptionThrownWhenSpanLimitReached() : void
{
$request = new Request();
@@ -144,7 +138,6 @@ public function testJsonSerializes() : void
$request->stop();
$serialized = $request->jsonSerialize();
- self::assertIsArray($serialized);
self::assertArrayHasKey('BatchCommand', $serialized);
self::assertArrayHasKey('commands', $serialized['BatchCommand']);
diff --git a/tests/Unit/Events/Span/SpanTest.php b/tests/Unit/Events/Span/SpanTest.php
index e92b4fdc..2d5083aa 100644
--- a/tests/Unit/Events/Span/SpanTest.php
+++ b/tests/Unit/Events/Span/SpanTest.php
@@ -29,7 +29,7 @@ public function setUp() : void
public function testCanBeInitialized() : void
{
$span = new Span($this->mockParent, 'name', RequestId::new());
- self::assertNotNull($span);
+ self::assertNull($span->getStopTime());
}
/** @throws Exception */
@@ -37,7 +37,7 @@ public function testCanBeStopped() : void
{
$span = new Span($this->mockParent, '', RequestId::new());
$span->stop();
- self::assertNotNull($span);
+ self::assertNotNull($span->getStopTime());
}
/** @throws Exception */
@@ -49,7 +49,6 @@ public function testJsonSerializes() : void
$serialized = $span->jsonSerialize();
- self::assertIsArray($serialized);
self::assertArrayHasKey('StartSpan', $serialized[0]);
self::assertArrayHasKey('TagSpan', $serialized[1]);
self::assertArrayHasKey('StopSpan', $serialized[2]);
@@ -76,38 +75,42 @@ public function testSpanNameOverride() : void
self::assertSame('fromRequest', $span->getName());
}
- /** @return int[][]|string[][] */
+ /**
+ * @return int[][]|string[][]
+ *
+ * @psalm-return list
+ */
public function spansForStackTraceProvider() : array
{
return [
[
'spanName' => 'Foo/Bar',
- 'startTime' => 1,
- 'endTime' => 1,
+ 'startTime' => 1.0,
+ 'endTime' => 1.0,
'expectedTagCount' => 0,
],
[
'spanName' => 'Foo/Bar',
- 'startTime' => 1,
- 'endTime' => 2,
+ 'startTime' => 1.0,
+ 'endTime' => 2.0,
'expectedTagCount' => 1,
],
[
'spanName' => 'Controller/Foo',
- 'startTime' => 1,
- 'endTime' => 2,
+ 'startTime' => 1.0,
+ 'endTime' => 2.0,
'expectedTagCount' => 0,
],
[
'spanName' => 'Middleware/Foo',
- 'startTime' => 1,
- 'endTime' => 2,
+ 'startTime' => 1.0,
+ 'endTime' => 2.0,
'expectedTagCount' => 0,
],
[
'spanName' => 'Job/Foo',
- 'startTime' => 1,
- 'endTime' => 2,
+ 'startTime' => 1.0,
+ 'endTime' => 2.0,
'expectedTagCount' => 0,
],
];
@@ -125,6 +128,7 @@ public function testStackTracesAreOnlyAddedForAppropriateSpans(string $spanName,
$span = new Span($request, $spanName, RequestId::new(), $startTime);
$span->stop($endTime);
+ /** @psalm-suppress DeprecatedMethod */
self::assertCount($expectedTagCount, $span->getTags());
}
}
diff --git a/tests/Unit/Events/Tag/TagRequestTest.php b/tests/Unit/Events/Tag/TagRequestTest.php
index 2505f268..9a7792f6 100644
--- a/tests/Unit/Events/Tag/TagRequestTest.php
+++ b/tests/Unit/Events/Tag/TagRequestTest.php
@@ -30,7 +30,6 @@ public function testJsonSerializes() : void
$requestId = RequestId::new();
$serialized = (new TagRequest('t', 'v', $requestId))->jsonSerialize();
- self::assertIsArray($serialized);
self::assertArrayHasKey('TagRequest', $serialized[0]);
$data = $serialized[0]['TagRequest'];
diff --git a/tests/Unit/Events/Tag/TagSpanTest.php b/tests/Unit/Events/Tag/TagSpanTest.php
index cd6afd5e..f41cf612 100644
--- a/tests/Unit/Events/Tag/TagSpanTest.php
+++ b/tests/Unit/Events/Tag/TagSpanTest.php
@@ -33,7 +33,6 @@ public function testJsonSerializes() : void
$serialized = (new TagSpan('t', 'v', $requestId, $spanId))->jsonSerialize();
- self::assertIsArray($serialized);
self::assertArrayHasKey('TagSpan', $serialized[0]);
$data = $serialized[0]['TagSpan'];
diff --git a/tests/Unit/Extension/PotentiallyAvailableExtensionCapabilitiesTest.php b/tests/Unit/Extension/PotentiallyAvailableExtensionCapabilitiesTest.php
index 9596ba7a..5dccb070 100644
--- a/tests/Unit/Extension/PotentiallyAvailableExtensionCapabilitiesTest.php
+++ b/tests/Unit/Extension/PotentiallyAvailableExtensionCapabilitiesTest.php
@@ -6,7 +6,6 @@
use PHPUnit\Framework\TestCase;
use Scoutapm\Extension\PotentiallyAvailableExtensionCapabilities;
-use Scoutapm\Extension\RecordedCall;
use function extension_loaded;
use function file_get_contents;
use function phpversion;
@@ -51,7 +50,6 @@ public function testGetCallsReturnsFileGetContentsCallWhenExtensionIsAvailable()
$calls = $this->capabilities->getCalls();
self::assertCount(1, $calls);
- self::assertContainsOnlyInstancesOf(RecordedCall::class, $calls);
$recordedCall = reset($calls);
diff --git a/tests/Unit/Extension/RecordedCallTest.php b/tests/Unit/Extension/RecordedCallTest.php
index a928d269..5db89cbe 100644
--- a/tests/Unit/Extension/RecordedCallTest.php
+++ b/tests/Unit/Extension/RecordedCallTest.php
@@ -38,7 +38,9 @@ public function testFromExtensionLoggedCallArray() : void
}
/**
- * @return string[][]|string[][][]|array)>>
+ * @return string[][]|string[][][]
+ *
+ * @psalm-return array}>
*/
public function filteredArgumentsDataProvider() : array
{
@@ -55,7 +57,7 @@ public function filteredArgumentsDataProvider() : array
}
/**
- * @param mixed[] $expectedFilteredArguments
+ * @param array $expectedFilteredArguments
*
* @throws Exception
*
diff --git a/tests/Unit/Helper/TimerTest.php b/tests/Unit/Helper/TimerTest.php
index 141c2b13..92d81ff9 100644
--- a/tests/Unit/Helper/TimerTest.php
+++ b/tests/Unit/Helper/TimerTest.php
@@ -43,8 +43,8 @@ public function testTimesAreFormatted() : void
$timer = new Timer();
$timer->stop();
- self::assertRegExp(self::DATE_FORMAT_VALIDATION_REGEX, $timer->getStart());
- self::assertRegExp(self::DATE_FORMAT_VALIDATION_REGEX, $timer->getStop());
+ self::assertRegExp(self::DATE_FORMAT_VALIDATION_REGEX, (string) $timer->getStart());
+ self::assertRegExp(self::DATE_FORMAT_VALIDATION_REGEX, (string) $timer->getStop());
}
public function testDurationIsNullIfNotStopped() : void
diff --git a/tests/isolated-memory-test.php b/tests/isolated-memory-test.php
index 405fe593..6667a27b 100644
--- a/tests/isolated-memory-test.php
+++ b/tests/isolated-memory-test.php
@@ -43,6 +43,8 @@
$i
));
+ assert($span !== null);
+
$span->tag('something', str_repeat('a', $tagSize));
$agent->stopSpan();