From b4f036a63d5c0a65a644b062ab9d0e564bcc5544 Mon Sep 17 00:00:00 2001 From: Alexey Kopytko Date: Mon, 1 Mar 2021 19:52:26 +0900 Subject: [PATCH] ProxyTrace should check for tests locations (#1494) Fixes #1480 --- src/TestFramework/Coverage/ProxyTrace.php | 4 ++++ tests/phpunit/TestFramework/Coverage/ProxyTraceTest.php | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/TestFramework/Coverage/ProxyTrace.php b/src/TestFramework/Coverage/ProxyTrace.php index c1597df0b..0a60b8d63 100644 --- a/src/TestFramework/Coverage/ProxyTrace.php +++ b/src/TestFramework/Coverage/ProxyTrace.php @@ -108,6 +108,10 @@ public function getTests(): ?TestLocations public function getAllTestsForMutation(NodeLineRangeData $lineRange, bool $isOnFunctionSignature): iterable { + if ($this->lazyTestLocations === null) { + return []; + } + return $this->getTestLocator()->getAllTestsForMutation($lineRange, $isOnFunctionSignature); } diff --git a/tests/phpunit/TestFramework/Coverage/ProxyTraceTest.php b/tests/phpunit/TestFramework/Coverage/ProxyTraceTest.php index ad6ca855f..234d30d0a 100644 --- a/tests/phpunit/TestFramework/Coverage/ProxyTraceTest.php +++ b/tests/phpunit/TestFramework/Coverage/ProxyTraceTest.php @@ -109,6 +109,15 @@ public function test_it_returns_null_for_no_tests(): void $this->assertNull($trace->getTests()); } + public function test_it_returns_empty_iterable_for_no_tests(): void + { + $fileInfoMock = $this->createMock(SplFileInfo::class); + + $trace = new ProxyTrace($fileInfoMock, null); + + $this->assertCount(0, $trace->getAllTestsForMutation(new NodeLineRangeData(1, 2), false)); + } + public function test_it_exposes_its_test_locations(): void { $fileInfoMock = $this->createMock(SplFileInfo::class);