Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
['ubuntu-latest']
php: >-
['8.3']
min-covered-msi: 100
min-msi: 100
threads: 1
secrets:
STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
},
"scripts": {
"cs-fix": "php-cs-fixer fix",
"mutation": "roave-infection-static-analysis-plugin --min-msi=100",
"rector": "rector",
"test": "phpunit",
"test-watch": "phpunit-watcher watch"
Expand Down
10 changes: 10 additions & 0 deletions infection.json.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@
"ignoreSourceCodeByRegex": [
"\\$this->invalidateScriptCache.*"
]
},
"DecrementInteger": {
"ignoreSourceCodeByRegex": [
"mkdir\\(.*permissions: 0775.*"
]
},
"IncrementInteger": {
"ignoreSourceCodeByRegex": [
"mkdir\\(.*permissions: 0775.*"
]
}
}
}
15 changes: 15 additions & 0 deletions tests/AssignmentsStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ public function testGetFileUpdatedAtException(): void
);
}

public function testRemoveNonExistingDoesNotSaveFile(): void
{
$filePath = $this->getAssignmentsStorageFilePath();
$storage = new AssignmentsStorage($filePath);

touch($filePath, time() - 100);
clearstatcache();
$modifiedTimeBefore = filemtime($filePath);

$storage->remove(itemName: 'Operator', userId: 'john');

clearstatcache();
$this->assertSame($modifiedTimeBefore, filemtime($filePath));
}

protected function createItemsStorage(): ItemsStorageInterface
{
return new ItemsStorage($this->getItemsStorageFilePath());
Expand Down
15 changes: 15 additions & 0 deletions tests/AssignmentsStorageWithConcurrencyHandledTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,21 @@ public function testRemoveByItemName(): void
$this->assertEmpty($innerTestStorage->getByItemNames(['Accountant']));
}

public function testNoReloadWhenTimestampIsUnchanged(): void
{
$filePath = $this->getAssignmentsStorageFilePath();
$innerStorage = new AssignmentsStorage($filePath, getFileUpdatedAt: static fn(): int => 12345);
$decorator = new ConcurrentAssignmentsStorageDecorator($innerStorage);

$decorator->add(new Assignment(userId: 'testUser', itemName: 'Researcher', createdAt: time()));

(new AssignmentsStorage($filePath))->add(
new Assignment(userId: 'testUser', itemName: 'Accountant', createdAt: time()),
);

$this->assertArrayNotHasKey('Accountant', $decorator->getByUserId('testUser'));
}

protected function createItemsStorage(): ItemsStorageInterface
{
return new ConcurrentItemsStorageDecorator(new ItemsStorage($this->getItemsStorageFilePath()));
Expand Down
30 changes: 30 additions & 0 deletions tests/ItemsStorage/ItemsStorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@ public function testLoadWithCustomGetFileUpdatedAt(): void
$this->assertSame($time, $storage->get('test')->getCreatedAt());
}

public function testRemoveChildNonExistingDoesNotSaveFile(): void
{
$filePath = $this->getItemsStorageFilePath();
$storage = new ItemsStorage($filePath);

touch($filePath, time() - 100);
clearstatcache();
$mtimeBefore = filemtime($filePath);

$storage->removeChild('posts.viewer', 'non-existing');

clearstatcache();
$this->assertSame($mtimeBefore, filemtime($filePath));
}

public function testRemoveChildrenNonExistingDoesNotSaveFile(): void
{
$filePath = $this->getItemsStorageFilePath();
$storage = new ItemsStorage($filePath);

touch($filePath, time() - 100);
clearstatcache();
$mtimeBefore = filemtime($filePath);

$storage->removeChildren('posts.view');

clearstatcache();
$this->assertSame($mtimeBefore, filemtime($filePath));
}

public function testGetFileUpdatedAtException(): void
{
$this->expectException(RuntimeException::class);
Expand Down
Loading