Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
solarium
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
solarium
Commits
8b18fcb6
Commit
8b18fcb6
authored
Jan 05, 2016
by
Stéphane Goetz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call setDispatcher only if it exists (if it doesn't exist, it isnt needed)
parent
fc453b87
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
30 deletions
+61
-30
tests/Solarium/Tests/Core/Client/ClientTest.php
tests/Solarium/Tests/Core/Client/ClientTest.php
+61
-30
No files found.
tests/Solarium/Tests/Core/Client/ClientTest.php
View file @
8b18fcb6
...
...
@@ -570,8 +570,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
{
$query
=
new
SelectQuery
();
$expectedEvent
=
new
PreCreateRequestEvent
(
$query
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_REQUEST
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_REQUEST
);
}
$observer
=
$this
->
getMock
(
'Solarium\Core\Plugin\AbstractPlugin'
,
array
(
'preCreateRequest'
));
$observer
->
expects
(
$this
->
once
())
...
...
@@ -592,8 +594,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query
=
new
SelectQuery
();
$request
=
$this
->
client
->
createRequest
(
$query
);
$expectedEvent
=
new
PostCreateRequestEvent
(
$query
,
$request
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_CREATE_REQUEST
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_CREATE_REQUEST
);
}
$observer
=
$this
->
getMock
(
'Solarium\Core\Plugin\AbstractPlugin'
,
array
(
'postCreateRequest'
));
$observer
->
expects
(
$this
->
once
())
...
...
@@ -616,8 +620,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query
=
new
SelectQuery
();
$expectedEvent
=
new
PreCreateRequestEvent
(
$query
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_REQUEST
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_REQUEST
);
}
$test
=
$this
;
$this
->
client
->
getEventDispatcher
()
->
addListener
(
...
...
@@ -653,8 +659,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query
=
new
SelectQuery
();
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$expectedEvent
=
new
PreCreateResultEvent
(
$query
,
$response
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_RESULT
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_RESULT
);
}
$observer
=
$this
->
getMock
(
'Solarium\Core\Plugin\AbstractPlugin'
,
array
(
'preCreateResult'
));
$observer
->
expects
(
$this
->
once
())
...
...
@@ -676,8 +684,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
$this
->
client
->
createResult
(
$query
,
$response
);
$expectedEvent
=
new
PostCreateResultEvent
(
$query
,
$response
,
$result
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_CREATE_RESULT
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_CREATE_RESULT
);
}
$observer
=
$this
->
getMock
(
'Solarium\Core\Plugin\AbstractPlugin'
,
array
(
'postCreateResult'
));
$observer
->
expects
(
$this
->
once
())
...
...
@@ -698,8 +708,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$query
=
new
SelectQuery
();
$response
=
new
Response
(
'test 1234'
,
array
(
'HTTP 1.0 200 OK'
));
$expectedEvent
=
new
PreCreateResultEvent
(
$query
,
$response
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_RESULT
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_RESULT
);
}
$expectedResult
=
new
Result
(
$this
->
client
,
$query
,
$response
);
$test
=
$this
;
...
...
@@ -768,7 +780,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
new
Result
(
$this
->
client
,
$query
,
$response
);
$expectedEvent
=
new
PreExecuteEvent
(
$query
);
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE
);
$mock
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'createRequest'
,
'executeRequest'
,
'createResult'
));
...
...
@@ -791,7 +803,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$mock
->
getEventDispatcher
()
->
addListener
(
Events
::
PRE_EXECUTE
,
array
(
$observer
,
'preExecute'
));
$expectedEvent
->
setDispatcher
(
$mock
->
getEventDispatcher
());
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE
);
$expectedEvent
->
setDispatcher
(
$mock
->
getEventDispatcher
());
}
$mock
->
execute
(
$query
);
}
...
...
@@ -802,7 +817,6 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$result
=
new
Result
(
$this
->
client
,
$query
,
$response
);
$expectedEvent
=
new
PostExecuteEvent
(
$query
,
$result
);
$expectedEvent
->
setName
(
Events
::
POST_EXECUTE
);
$mock
=
$this
->
getMock
(
'Solarium\Core\Client\Client'
,
array
(
'createRequest'
,
'executeRequest'
,
'createResult'
));
...
...
@@ -825,7 +839,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$mock
->
getEventDispatcher
()
->
addListener
(
Events
::
POST_EXECUTE
,
array
(
$observer
,
'postExecute'
));
$expectedEvent
->
setDispatcher
(
$mock
->
getEventDispatcher
());
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setName
(
Events
::
POST_EXECUTE
);
$expectedEvent
->
setDispatcher
(
$mock
->
getEventDispatcher
());
}
$mock
->
execute
(
$query
);
}
...
...
@@ -836,8 +853,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$expectedResult
=
new
Result
(
$this
->
client
,
$query
,
$response
);
$expectedEvent
=
new
PreExecuteEvent
(
$query
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE
);
}
$test
=
$this
;
$this
->
client
->
getEventDispatcher
()
->
addListener
(
...
...
@@ -882,8 +901,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$endpoint
=
$this
->
client
->
createEndpoint
(
's1'
);
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$expectedEvent
=
new
PreExecuteRequestEvent
(
$request
,
$endpoint
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE_REQUEST
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE_REQUEST
);
}
$mockAdapter
=
$this
->
getMock
(
'Solarium\Core\Client\Adapter\Http'
,
array
(
'execute'
));
$mockAdapter
->
expects
(
$this
->
once
())
...
...
@@ -910,8 +931,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$endpoint
=
$this
->
client
->
createEndpoint
(
's1'
);
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$expectedEvent
=
new
PostExecuteRequestEvent
(
$request
,
$endpoint
,
$response
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_EXECUTE_REQUEST
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_EXECUTE_REQUEST
);
}
$mockAdapter
=
$this
->
getMock
(
'Solarium\Core\Client\Adapter\Http'
,
array
(
'execute'
));
$mockAdapter
->
expects
(
$this
->
any
())
...
...
@@ -938,8 +961,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$response
=
new
Response
(
''
,
array
(
'HTTP 1.0 200 OK'
));
$endpoint
=
$this
->
client
->
createEndpoint
(
's1'
);
$expectedEvent
=
new
PreExecuteRequestEvent
(
$request
,
$endpoint
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE_REQUEST
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_EXECUTE_REQUEST
);
}
$test
=
$this
;
$this
->
client
->
getEventDispatcher
()
->
addListener
(
...
...
@@ -1088,8 +1113,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$type
=
Client
::
QUERY_SELECT
;
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
$expectedEvent
=
new
PreCreateQueryEvent
(
$type
,
$options
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_QUERY
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_QUERY
);
}
$observer
=
$this
->
getMock
(
'Solarium\Core\Plugin\AbstractPlugin'
,
array
(
'preCreateQuery'
));
$observer
->
expects
(
$this
->
once
())
...
...
@@ -1107,8 +1134,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$expectedQuery
=
new
SelectQuery
();
$expectedQuery
->
setQuery
(
'test789'
);
$expectedEvent
=
new
PreCreateQueryEvent
(
$type
,
$options
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_QUERY
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
PRE_CREATE_QUERY
);
}
$test
=
$this
;
$this
->
client
->
getEventDispatcher
()
->
addListener
(
...
...
@@ -1133,8 +1162,10 @@ class ClientTest extends \PHPUnit_Framework_TestCase
$options
=
array
(
'optionA'
=>
1
,
'optionB'
=>
2
);
$query
=
$this
->
client
->
createQuery
(
$type
,
$options
);
$expectedEvent
=
new
PostCreateQueryEvent
(
$type
,
$options
,
$query
);
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_CREATE_QUERY
);
if
(
method_exists
(
$expectedEvent
,
'setDispatcher'
))
{
$expectedEvent
->
setDispatcher
(
$this
->
client
->
getEventDispatcher
());
$expectedEvent
->
setName
(
Events
::
POST_CREATE_QUERY
);
}
$observer
=
$this
->
getMock
(
'Solarium\Core\Plugin\AbstractPlugin'
,
array
(
'postCreateQuery'
));
$observer
->
expects
(
$this
->
once
())
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment