Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The result cache should still work if there are no composer or baseline files. #1037

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(
),
);