1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Asparagus\Tests; |
4
|
|
|
|
5
|
|
|
use Asparagus\QueryBuilder; |
6
|
|
|
use Asparagus\QueryExecuter; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers Asparagus\QueryExecuter |
10
|
|
|
* |
11
|
|
|
* @license GNU GPL v2+ |
12
|
|
|
* @author Bene* < [email protected] > |
13
|
|
|
*/ |
14
|
|
|
class QueryExecuterTest extends \PHPUnit_Framework_TestCase { |
15
|
|
|
|
16
|
|
|
private function getHttpMock( $params ) { |
17
|
|
|
$http = $this->getMockBuilder( 'Asparagus\Http' ) |
18
|
|
|
->disableOriginalConstructor() |
19
|
|
|
->getMock(); |
20
|
|
|
|
21
|
|
|
$http->expects( $this->once() ) |
22
|
|
|
->method( 'request' ) |
23
|
|
|
->with( |
24
|
|
|
$this->equalTo( 'test.example.com' ), |
25
|
|
|
$this->equalTo( $params ) |
26
|
|
|
) |
27
|
|
|
->will( $this->returnValue( '{"results":"~=[,,_,,]:3"}' ) ); |
28
|
|
|
|
29
|
|
|
return $http; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testExecute() { |
33
|
|
|
$http = $this->getHttpMock( array( |
34
|
|
|
'query' => 'FooBar', |
35
|
|
|
'format' => 'json' |
36
|
|
|
) ); |
37
|
|
|
|
38
|
|
|
$queryExecuter = new QueryExecuter( 'test.example.com', array(), $http ); |
39
|
|
|
$result = $queryExecuter->execute( 'FooBar' ); |
40
|
|
|
|
41
|
|
|
$this->assertEquals( '~=[,,_,,]:3', $result ); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testExecuteCustomParams() { |
45
|
|
|
$http = $this->getHttpMock( array( |
46
|
|
|
'fancy-query' => 'FooBar', |
47
|
|
|
'format-nyan' => 'json' |
48
|
|
|
) ); |
49
|
|
|
|
50
|
|
|
$queryExecuter = new QueryExecuter( 'test.example.com', array( |
51
|
|
|
'queryParam' => 'fancy-query', |
52
|
|
|
'formatParam' => 'format-nyan' |
53
|
|
|
), $http ); |
54
|
|
|
|
55
|
|
|
$result = $queryExecuter->execute( 'FooBar' ); |
56
|
|
|
|
57
|
|
|
$this->assertEquals( '~=[,,_,,]:3', $result ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testExecuteQueryBuilder() { |
61
|
|
|
$http = $this->getHttpMock( array( |
62
|
|
|
'query' => 'SELECT * WHERE { }', |
63
|
|
|
'format' => 'json' |
64
|
|
|
) ); |
65
|
|
|
|
66
|
|
|
$queryExecuter = new QueryExecuter( 'test.example.com', array(), $http ); |
67
|
|
|
$result = $queryExecuter->execute( new QueryBuilder() ); |
68
|
|
|
|
69
|
|
|
$this->assertEquals( '~=[,,_,,]:3', $result ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testExecuteInvalidArgument() { |
73
|
|
|
$queryExecuter = new QueryExecuter( 'test.example.com' ); |
74
|
|
|
$this->setExpectedException( 'InvalidArgumentException' ); |
75
|
|
|
|
76
|
|
|
$queryExecuter->execute( null ); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
} |
80
|
|
|
|