Skip to content

Commit

Permalink
Merge pull request #1037 from frankdekker/Result-cache-does-not-work-…
Browse files Browse the repository at this point in the history
…without-baseline-file

The result cache should still work if there are no composer or baseline files.
  • Loading branch information
kylekatarnls committed Sep 28, 2023
2 parents 247f84e + 91e3022 commit bb29fe8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/main/php/PHPMD/Cache/ResultCacheStateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ public function fromFile($filePath)
*/
private function createCacheKey(array $data)
{
if (isset(
$data['strict'],
$data['baselineHash'],
$data['rules'],
$data['composer'],
$data['phpVersion']
) === false
if (array_key_exists('strict', $data) === false ||
array_key_exists('baselineHash', $data) === false ||
array_key_exists('rules', $data) === false ||
array_key_exists('composer', $data) === false ||
array_key_exists('phpVersion', $data) === false
) {
return null;
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/php/PHPMD/Cache/ResultCacheStateFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,25 @@ public function testFromFileFullCache()
static::assertTrue($state->isFileModified('file2', 'file1-hash'));
static::assertSame(array('violations'), $state->getViolations('file2'));
}

/**
* @covers ::fromFile
* @covers ::createCacheKey
*/
public function testFromFileWithCacheWithoutBaselineOrComposer()
{
$state = $this->factory->fromFile(static::createResourceUriForTest('.minimal-cache.php'));
static::assertNotNull($state);

// assert cache key
$expectedKey = new ResultCacheKey(
false,
null,
array('rule' => 'hash'),
array(),
70000
);
$cacheKey = $state->getCacheKey();
static::assertEquals($expectedKey, $cacheKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

return array(
'key' =>
array(
'strict' => false,
'baselineHash' => null,
'rules' =>
array(
'rule' => 'hash',
),
'composer' => array(),
'phpVersion' => 70000,
),
'state' =>
array(
),
);

0 comments on commit bb29fe8

Please sign in to comment.