Skip to content

Commit

Permalink
Fix memcached and hashtrait bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Lasse Mammen <[email protected]>
  • Loading branch information
lkm committed Jan 25, 2019
1 parent f435ff9 commit ad5f389
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/Cache/HashTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function hash($url, $id, array $headers)
$headerString = "";
foreach ($headers as $key => $value) {
if ($key != Headers::HEADER_XFF) {
$headerString = $key.$value;
$headerString .= $key.$value;
}
}

Expand All @@ -39,11 +39,7 @@ public function hash($url, $id, array $headers)
*/
public function isCachable($url, $httpMethod)
{
if ($httpMethod === Client::HTTP_GET && $this->isInitialized()) {
return true;
}

return false;
return $httpMethod === Client::HTTP_GET && $this->isInitialized();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/MemcachedCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,6 @@ public function delete($key)
*/
public function isInitialized()
{
return $this->cache == null;
return $this->cache != null;
}
}
11 changes: 11 additions & 0 deletions tests/Cache/HashTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public function testHashHeader()
$this->assertNotEquals($hash1, $hash2);
}

/** @group tttt */
public function testHashLanguageHeader()
{
$mock = $this->getMockForTrait('\Bookboon\Api\Cache\HashTrait');

$hash1 = $mock->hash('/test', "WHATEVSID", array(Headers::HEADER_LANGUAGE => 'en, de', Headers::HEADER_BRANDING => 'branding-test'));
$hash2 = $mock->hash('/test', "WHATEVSID", array(Headers::HEADER_LANGUAGE => 'de, en', Headers::HEADER_BRANDING => 'branding-test'));

$this->assertNotEquals($hash1, $hash2);
}

public function testRequestIsCacheable()
{
$mock = $this->getMockForTrait('\Bookboon\Api\Cache\HashTrait');
Expand Down

0 comments on commit ad5f389

Please sign in to comment.