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
13 changes: 8 additions & 5 deletions src/Datasource/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\Datasource\QueryInterface;
use Cake\Datasource\QueryTrait;
use Cake\Datasource\ResultSetInterface;
use Cake\Utility\Hash;
use InvalidArgumentException;
use IteratorAggregate;
Expand Down Expand Up @@ -535,17 +536,19 @@ public function triggerBeforeFind()
*/
public function execute()
{
return $this->_execute();
if ($this->clause('action') === self::ACTION_READ) {
return $this->_execute();
}

return $this->__resultSet = $this->_webservice->execute($this);
}

/**
* Executes this query and returns a traversable object containing the results
*
* @return bool|int|\Cake\Datasource\ResultSetInterface
* @psalm-suppress TraitMethodSignatureMismatch
* @psalm-suppress ImplementedReturnTypeMismatch
* @return \Cake\Datasource\ResultSetInterface
*/
protected function _execute()
protected function _execute(): ResultSetInterface
{
$this->triggerBeforeFind();
if ($this->__resultSet) {
Expand Down
8 changes: 6 additions & 2 deletions tests/TestCase/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,11 @@ public function testExecuteTwice()
{
$mockWebservice = $this
->getMockBuilder('\TestApp\Webservice\StaticWebservice')
->setMethods([
->onlyMethods([
'execute',
])
->getMock();

$mockWebservice->expects($this->once())
->method('execute')
->will($this->returnValue(new ResultSet([
Expand All @@ -187,7 +188,10 @@ public function testExecuteTwice()
'title' => 'Webservices',
]),
], 3)));
$this->query->setWebservice($mockWebservice);

$this->query
->setWebservice($mockWebservice)
->action(Query::ACTION_READ);

$this->query->execute();

Expand Down