-
Notifications
You must be signed in to change notification settings - Fork 53
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
fix: add tests for observing purged tags + fix edge cases #5249
Changes from 4 commits
6bd7409
221b3a3
f315baf
e5e6a39
0d7296c
7ad51e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
use App\Util\ArrayDeepSort; | ||
use Doctrine\Bundle\DoctrineBundle\DataCollector\DoctrineDataCollector; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use FOS\HttpCacheBundle\CacheManager; | ||
use Hautelook\AliceBundle\PhpUnit\FixtureStore; | ||
use Hautelook\AliceBundle\PhpUnit\RefreshDatabaseTrait; | ||
use Spatie\Snapshots\MatchesSnapshots; | ||
|
@@ -360,6 +361,27 @@ protected function assertMatchesResponseSnapshot(ResponseInterface $response): v | |
$this->assertMatchesJsonSnapshot($sortedResponseArray); | ||
} | ||
|
||
/** | ||
* mocks CacheManager and keeps track of purged cache tags. | ||
*/ | ||
protected function &getPurgedCacheTags(): array { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to improve this further we could use a class which implements the cacheManager, but allows to get the purged cache tags, instead of sharing a reference to an array There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, good idea. I can give it a try. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed with 0d7296c |
||
$container = static::getContainer(); | ||
$cacheManager = $this->createMock(CacheManager::class); | ||
|
||
$purgedCacheTags = []; | ||
$cacheManager | ||
->method('invalidateTags') | ||
->willReturnCallback(function ($tags) use (&$purgedCacheTags, $cacheManager) { | ||
$purgedCacheTags = array_unique(array_merge($purgedCacheTags, $tags)); | ||
|
||
return $cacheManager; | ||
}) | ||
; | ||
$container->set(CacheManager::class, $cacheManager); | ||
|
||
return $purgedCacheTags; | ||
} | ||
|
||
private static function escapeValues(mixed &$object): void { | ||
if (!is_array($object)) { | ||
$object = 'escaped_value'; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't know the & (dereference) operator, it is difficult to know why this array would be mutated with the $client->request method.
And that it does not work anymore when you call the method a second time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 0d7296c