diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 50a61b3e..5e04fee0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,6 +11,7 @@ jobs: name: "Unit tests" runs-on: ubuntu-latest strategy: + fail-fast: false matrix: dependencies: ["lowest", "highest"] extensions: [ diff --git a/CHANGELOG.md b/CHANGELOG.md index 236a9131..b00a8a62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. -## 6.3.0 - TBC +## 6.3.0 - 2021-06-17 ### Added @@ -10,7 +10,7 @@ All notable changes to this project will be documented in this file, in reverse ### Changed -- Nothing. +- [#226](https://github.com/scoutapp/scout-apm-php/pull/226) Increased recommended extension version to 1.4.0 ### Deprecated diff --git a/known-issues.xml b/known-issues.xml index ec59d3d2..26553147 100644 --- a/known-issues.xml +++ b/known-issues.xml @@ -138,17 +138,6 @@ $this->value - - - scoutapm_get_calls() - - - $call - - - list<RecordedCall> - - $composerContent['config'] diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 26d00837..6d4c1c1c 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -18,4 +18,7 @@ + + src/Extension/ExtensionCapabilities.php + diff --git a/src/Agent.php b/src/Agent.php index f0f16e6e..1c56e3e2 100644 --- a/src/Agent.php +++ b/src/Agent.php @@ -29,7 +29,7 @@ use Scoutapm\Events\Span\Span; use Scoutapm\Events\Span\SpanReference; use Scoutapm\Events\Tag\Tag; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Extension\PotentiallyAvailableExtensionCapabilities; use Scoutapm\Extension\Version; use Scoutapm\Helper\LocateFileOrFolder; @@ -51,7 +51,7 @@ final class Agent implements ScoutApmAgent private const METADATA_CACHE_TTL_SECONDS = 600; - private const WARN_WHEN_EXTENSION_IS_OLDER_THAN = '1.0.2'; + private const WARN_WHEN_EXTENSION_IS_OLDER_THAN = '1.4.0'; /** @var Config */ private $config; @@ -65,7 +65,7 @@ final class Agent implements ScoutApmAgent private $ignoredEndpoints; /** @var bool If this request was marked as ignored*/ private $isIgnored = false; - /** @var ExtentionCapabilities */ + /** @var ExtensionCapabilities */ private $phpExtension; /** @var CacheInterface */ private $cache; @@ -80,7 +80,7 @@ private function __construct( Config $configuration, Connector $connector, LoggerInterface $logger, - ExtentionCapabilities $phpExtension, + ExtensionCapabilities $phpExtension, CacheInterface $cache, LocateFileOrFolder $locateFileOrFolder ) { @@ -136,14 +136,14 @@ public static function fromConfig( LoggerInterface $logger, ?CacheInterface $cache = null, ?Connector $connector = null, - ?ExtentionCapabilities $extentionCapabilities = null, + ?ExtensionCapabilities $extensionCapabilities = null, ?LocateFileOrFolder $locateFileOrFolder = null ): self { return new self( $config, $connector ?? self::createConnectorFromConfig($config), $logger, - $extentionCapabilities ?? new PotentiallyAvailableExtensionCapabilities(), + $extensionCapabilities ?? new PotentiallyAvailableExtensionCapabilities(), $cache ?? new DevNullCache(), $locateFileOrFolder ?? new LocateFileOrFolder() ); diff --git a/src/Events/Metadata.php b/src/Events/Metadata.php index 00ba06c0..48f1096e 100644 --- a/src/Events/Metadata.php +++ b/src/Events/Metadata.php @@ -9,7 +9,7 @@ use Scoutapm\Config; use Scoutapm\Config\ConfigKey; use Scoutapm\Connector\Command; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Helper\LocateFileOrFolder; use Scoutapm\Helper\Timer; @@ -40,7 +40,7 @@ final class Metadata implements Command private $timer; /** @var Config */ private $config; - /** @var ExtentionCapabilities */ + /** @var ExtensionCapabilities */ private $phpExtension; /** @var LocateFileOrFolder */ private $locateFileOrFolder; @@ -48,7 +48,7 @@ final class Metadata implements Command public function __construct( DateTimeImmutable $now, Config $config, - ExtentionCapabilities $phpExtension, + ExtensionCapabilities $phpExtension, LocateFileOrFolder $locateFileOrFolder ) { // Construct and stop the timer to use its timestamp logic. This event diff --git a/src/Extension/ExtentionCapabilities.php b/src/Extension/ExtensionCapabilities.php similarity index 65% rename from src/Extension/ExtentionCapabilities.php rename to src/Extension/ExtensionCapabilities.php index 9af04235..a2d06d37 100644 --- a/src/Extension/ExtentionCapabilities.php +++ b/src/Extension/ExtensionCapabilities.php @@ -4,7 +4,9 @@ namespace Scoutapm\Extension; -interface ExtentionCapabilities +use function class_alias; + +interface ExtensionCapabilities { /** @return RecordedCall[]|array */ public function getCalls(): array; @@ -13,3 +15,5 @@ public function clearRecordedCalls(): void; public function version(): ?Version; } + +class_alias(ExtensionCapabilities::class, ExtentionCapabilities::class); diff --git a/src/Extension/PotentiallyAvailableExtensionCapabilities.php b/src/Extension/PotentiallyAvailableExtensionCapabilities.php index 8ab487ad..3dd051cd 100644 --- a/src/Extension/PotentiallyAvailableExtensionCapabilities.php +++ b/src/Extension/PotentiallyAvailableExtensionCapabilities.php @@ -12,8 +12,22 @@ use function phpversion; use function scoutapm_get_calls; -final class PotentiallyAvailableExtensionCapabilities implements ExtentionCapabilities +final class PotentiallyAvailableExtensionCapabilities implements ExtensionCapabilities { + public function __construct() + { + if (! $this->extensionIsAvailable()) { + return; + } + + // If the function doesn't exist, we're probably using an older `scoutapm` extension which doesn't need enabling + if (! function_exists('scoutapm_enable_instrumentation')) { + return; + } + + scoutapm_enable_instrumentation(true); + } + /** * @return RecordedCall[] * diff --git a/src/Extension/Version.php b/src/Extension/Version.php index f6514b25..dc910471 100644 --- a/src/Extension/Version.php +++ b/src/Extension/Version.php @@ -53,21 +53,8 @@ public static function fromString(string $versionString): self public function isOlderThan(self $otherVersion): bool { - if ($this->major > $otherVersion->major) { - return false; - } - - if ($this->minor > $otherVersion->minor) { - return false; - } - - if ($this->patch > $otherVersion->patch) { - return false; - } - - return $otherVersion->major > $this->major - || $otherVersion->minor > $this->minor - || $otherVersion->patch > $this->patch; + return (($this->major * 1000000) + ($this->minor * 1000) + $this->patch) + < (($otherVersion->major * 1000000) + ($otherVersion->minor * 1000) + $otherVersion->patch); } public function toString(): string diff --git a/src/ScoutApmBundle/ScoutApmAgentFactory.php b/src/ScoutApmBundle/ScoutApmAgentFactory.php index 19af93f9..919caede 100644 --- a/src/ScoutApmBundle/ScoutApmAgentFactory.php +++ b/src/ScoutApmBundle/ScoutApmAgentFactory.php @@ -9,7 +9,7 @@ use Scoutapm\Agent; use Scoutapm\Config; use Scoutapm\Connector\Connector; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\ScoutApmAgent; use Symfony\Component\HttpKernel\Kernel; @@ -25,7 +25,7 @@ public static function createAgent( LoggerInterface $logger, ?CacheInterface $cache, ?Connector $connector, - ?ExtentionCapabilities $extentionCapabilities, + ?ExtensionCapabilities $extensionCapabilities, array $agentConfiguration ): ScoutApmAgent { return Agent::fromConfig( @@ -39,7 +39,7 @@ public static function createAgent( $logger, $cache, $connector, - $extentionCapabilities + $extensionCapabilities ); } } diff --git a/tests/Unit/AgentTest.php b/tests/Unit/AgentTest.php index 3df1adfb..1046a4d5 100644 --- a/tests/Unit/AgentTest.php +++ b/tests/Unit/AgentTest.php @@ -28,7 +28,7 @@ use Scoutapm\Events\Span\SpanReference; use Scoutapm\Events\Tag\Tag; use Scoutapm\Events\Tag\TagRequest; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Extension\RecordedCall; use Scoutapm\Extension\Version; use Scoutapm\IntegrationTests\TestHelper; @@ -54,7 +54,7 @@ final class AgentTest extends TestCase /** @var Connector&MockObject */ private $connector; - /** @var ExtentionCapabilities&MockObject */ + /** @var ExtensionCapabilities&MockObject */ private $phpExtension; public function setUp(): void @@ -63,7 +63,7 @@ public function setUp(): void $this->logger = new TestLogger(); $this->connector = $this->createMock(Connector::class); - $this->phpExtension = $this->createMock(ExtentionCapabilities::class); + $this->phpExtension = $this->createMock(ExtensionCapabilities::class); } private function requestFromAgent(ScoutApmAgent $agent): ?Request diff --git a/tests/Unit/Events/MetadataTest.php b/tests/Unit/Events/MetadataTest.php index 51824da2..5f4c760b 100644 --- a/tests/Unit/Events/MetadataTest.php +++ b/tests/Unit/Events/MetadataTest.php @@ -13,7 +13,7 @@ use Scoutapm\Config; use Scoutapm\Config\ConfigKey; use Scoutapm\Events\Metadata; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\Extension\Version; use Scoutapm\Helper\LocateFileOrFolder; use Scoutapm\Helper\Timer; @@ -33,7 +33,7 @@ */ final class MetadataTest extends TestCase { - /** @var ExtentionCapabilities&MockObject */ + /** @var ExtensionCapabilities&MockObject */ private $phpExtension; /** @var LocateFileOrFolder&MockObject */ private $locateFileOrFolder; @@ -44,7 +44,7 @@ public function setUp(): void { parent::setUp(); - $this->phpExtension = $this->createMock(ExtentionCapabilities::class); + $this->phpExtension = $this->createMock(ExtensionCapabilities::class); $this->locateFileOrFolder = $this->createMock(LocateFileOrFolder::class); $this->time = new DateTimeImmutable('now', new DateTimeZone('UTC')); diff --git a/tests/Unit/Extension/VersionTest.php b/tests/Unit/Extension/VersionTest.php index 5ec884a1..2e46d134 100644 --- a/tests/Unit/Extension/VersionTest.php +++ b/tests/Unit/Extension/VersionTest.php @@ -27,6 +27,7 @@ public function olderThanVersionProvider(): array ['testVersion' => '1.0.0', 'isOlderThan' => '1.0.0', 'expectedResult' => false], ['testVersion' => '1.1.0', 'isOlderThan' => '1.1.0', 'expectedResult' => false], ['testVersion' => '1.1.1', 'isOlderThan' => '1.1.1', 'expectedResult' => false], + ['testVersion' => '1.3.0', 'isOlderThan' => '0.0.1', 'expectedResult' => false], ['testVersion' => '2.0.0', 'isOlderThan' => '1.0.2', 'expectedResult' => false], ['testVersion' => '2.0.0', 'isOlderThan' => '1.2.0', 'expectedResult' => false], ]; diff --git a/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php b/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php index ce6e9dc8..c3e7ffe3 100644 --- a/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php +++ b/tests/Unit/ScoutApmBundle/ScoutApmAgentFactoryTest.php @@ -10,7 +10,7 @@ use Scoutapm\Config\ConfigKey; use Scoutapm\Connector\Connector; use Scoutapm\Events\Metadata; -use Scoutapm\Extension\ExtentionCapabilities; +use Scoutapm\Extension\ExtensionCapabilities; use Scoutapm\ScoutApmBundle\ScoutApmAgentFactory; use function json_decode; @@ -24,7 +24,7 @@ public function testFactoryConfiguresFrameworkNameAndVersion(): void $logger = $this->createMock(LoggerInterface::class); $cache = $this->createMock(CacheInterface::class); $connector = $this->createMock(Connector::class); - $phpExtension = $this->createMock(ExtentionCapabilities::class); + $phpExtension = $this->createMock(ExtensionCapabilities::class); $connector->expects(self::at(3)) ->method('sendCommand') diff --git a/tests/psalm-stubs.php b/tests/psalm-stubs.php index dadadaf3..317bdbaf 100644 --- a/tests/psalm-stubs.php +++ b/tests/psalm-stubs.php @@ -3,6 +3,22 @@ /** @noinspection PhpIllegalPsrClassPathInspection */ declare(strict_types=1); +namespace { + function scoutapm_enable_instrumentation(bool $enabled): void + { + } + + /** @psalm-return list */ + function scoutapm_get_calls(): array + { + } + + /** @return list */ + function scoutapm_list_instrumented_functions(): array + { + } +} + namespace Composer { class InstalledVersions { /**