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

Bugfix/20002 superfluous query on head request in serializer #20060

Closed
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
1 change: 1 addition & 0 deletions framework/rest/Serializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
protected function serializeDataProvider($dataProvider)
{
if (($pagination = $dataProvider->getPagination()) !== false) {
$pagination->totalCount = $dataProvider->getTotalCount();

Check warning on line 192 in framework/rest/Serializer.php

View check run for this annotation

Codecov / codecov/patch

framework/rest/Serializer.php#L192

Added line #L192 was not covered by tests
$this->addPaginationHeaders($pagination);
}
if ($this->request->getIsHead()) {
Expand Down
24 changes: 24 additions & 0 deletions tests/framework/rest/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,30 @@ public function testHeadSerializeDataProvider($dataProvider, $expectedResult, $s
]);
$serializer->preserveKeys = $saveKeys;
$this->assertEmpty($serializer->serialize($dataProvider));
$this->assertNotEmpty($serializer->response->getHeaders()->get($serializer->totalCountHeader));

$arrayDataProviderMock = $this->getMockBuilder(ArrayDataProvider::className())
->disableOriginalConstructor()
->getMock();

// stub getModels to prevent empty
$arrayDataProviderMock
->method('getModels')
->willReturn($expectedResult);

// stub getPagination for header
$arrayDataProviderMock
->method('getPagination')
->willReturn($dataProvider->getPagination());

// assert normal HEAD is empty response
$this->assertEmpty($serializer->serialize($arrayDataProviderMock));

// Test #20002: Set up the expectation for the getModels method
$arrayDataProviderMock->expects($this->never())
->method('getModels');

// reset Method
unset($_POST[$request->methodParam], $_SERVER['REQUEST_METHOD']);
}

Expand Down
Loading