Skip to content

Commit

Permalink
CacheWarmer: call all available methods for caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Slamdunk authored and sebastianbergmann committed Aug 10, 2020
1 parent 9871cf4 commit 8673460
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/StaticAnalysis/CacheWarmer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
39 changes: 39 additions & 0 deletions tests/tests/StaticAnalysis/CacheWarmerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <[email protected]>
*
* 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);
}
}

0 comments on commit 8673460

Please sign in to comment.