From 4e7ad5adf9c73694599c1b80f88d3dc489b2f38c Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Mon, 10 Aug 2020 09:12:12 +0200 Subject: [PATCH] CacheWarmer: call all available methods for caching --- src/StaticAnalysis/CacheWarmer.php | 8 ++++ .../tests/StaticAnalysis/CacheWarmerTest.php | 39 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 tests/tests/StaticAnalysis/CacheWarmerTest.php diff --git a/src/StaticAnalysis/CacheWarmer.php b/src/StaticAnalysis/CacheWarmer.php index af3f9044e..df965af3a 100644 --- a/src/StaticAnalysis/CacheWarmer.php +++ b/src/StaticAnalysis/CacheWarmer.php @@ -29,8 +29,16 @@ public function warmCache(string $cacheDirectory, bool $useAnnotationsForIgnorin ); foreach ($filter->files() as $file) { + /* @noinspection UnusedFunctionResultInspection */ + $coveredFileAnalyser->classesIn($file); + /* @noinspection UnusedFunctionResultInspection */ + $coveredFileAnalyser->traitsIn($file); + /* @noinspection UnusedFunctionResultInspection */ + $coveredFileAnalyser->functionsIn($file); /* @noinspection UnusedFunctionResultInspection */ $coveredFileAnalyser->linesOfCodeFor($file); + /* @noinspection UnusedFunctionResultInspection */ + $coveredFileAnalyser->ignoredLinesFor($file); /* @noinspection UnusedFunctionResultInspection */ $uncoveredFileAnalyser->executableLinesIn($file); diff --git a/tests/tests/StaticAnalysis/CacheWarmerTest.php b/tests/tests/StaticAnalysis/CacheWarmerTest.php new file mode 100644 index 000000000..a918326fb --- /dev/null +++ b/tests/tests/StaticAnalysis/CacheWarmerTest.php @@ -0,0 +1,39 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ +namespace SebastianBergmann\CodeCoverage\StaticAnalysis; + +use SebastianBergmann\CodeCoverage\Filter; +use SebastianBergmann\CodeCoverage\TestCase; + +/** + * @covers \SebastianBergmann\CodeCoverage\StaticAnalysis\CacheWarmer + */ +final class CacheWarmerTest extends TestCase +{ + protected function tearDown(): void + { + parent::tearDown(); + + $this->removeTemporaryFiles(); + } + + public function testEveryCachebleMethodIsCalled(): void + { + $filter = new Filter(); + $filter->includeFiles([TEST_FILES_PATH . 'BankAccount.php']); + + (new CacheWarmer())->warmCache(self::$TEST_TMP_PATH, false, false, $filter); + + $expectedWarmedCacheFiles = count(get_class_methods(CoveredFileAnalyser::class)) + count(get_class_methods(UncoveredFileAnalyser::class)); + $actualWarmedCacheFiles = count(glob(self::$TEST_TMP_PATH . DIRECTORY_SEPARATOR . '*')); + + $this->assertSame($actualWarmedCacheFiles, $expectedWarmedCacheFiles); + } +}