Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Fix bug in Queries\Query::updateScope and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Elliot Levin committed Aug 30, 2014
1 parent b07ab2a commit cf6b7ad
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Source/Queries/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function updateScope(IScope $scope)
return $this;
}

$this->withScope($scope);
return $this->withScope($scope);
}

abstract protected function withScope(IScope $scope);
Expand Down
59 changes: 59 additions & 0 deletions Tests/Integration/Queries/MiscQueryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

namespace Pinq\Tests\Integration\Queries;

use Pinq\Expressions as O;
use Pinq\Parsing;
use Pinq\Providers;
use Pinq\Queries as Q;
use Pinq\Tests\PinqTestCase;

class MiscQueryTest extends PinqTestCase
{
protected function request()
{
return new Q\RequestQuery(new Q\Scope(new Q\SourceInfo(''), []), new Q\Requests\Values(Q\Requests\Values::AS_ARRAY));
}

protected function operation()
{
return new Q\OperationQuery(new Q\Scope(new Q\SourceInfo(''), []), new Q\Operations\Clear());
}

public function queries()
{
return [
[$this->request()],
[$this->operation()],
];
}

/**
* @dataProvider queries
*/
public function testUpdateScope(Q\IQuery $query)
{
$newScope = new Q\Scope(new Q\SourceInfo(''), []);

$this->assertSame($query->updateScope($query->getScope()), $query);
$this->assertSame($query->updateScope($newScope)->getScope(), $newScope);
}

public function testUpdateRequest()
{
$requestQuery = $this->request();
$newRequest = new Q\Requests\First();

$this->assertSame($requestQuery->updateRequest($requestQuery->getRequest()), $requestQuery);
$this->assertSame($requestQuery->updateRequest($newRequest)->getRequest(), $newRequest);
}

public function testUpdateOperation()
{
$operationQuery = $this->operation();
$newOperation = new Q\Operations\Clear();

$this->assertSame($operationQuery->updateOperation($operationQuery->getOperation()), $operationQuery);
$this->assertSame($operationQuery->updateOperation($newOperation)->getOperation(), $newOperation);
}
}

0 comments on commit cf6b7ad

Please sign in to comment.