Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4792514
TestCase.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
TestCase.php
View Options
<?php
namespace
Nasqueron\Notifications\Tests
;
use
Illuminate\Contracts\Console\Kernel
;
use
Keruald\Broker\BlackholeBroker
;
use
Keruald\Broker\Broker
;
use
Mockery
;
class
TestCase
extends
\Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected
$baseUrl
=
'http://localhost'
;
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public
function
createApplication
()
{
$app
=
require
__DIR__
.
'/../bootstrap/app.php'
;
$app
->
make
(
Kernel
::
class
)->
bootstrap
();
return
$app
;
}
///
/// Helpers to mock application services
///
/**
* Mocks the events dispatcher
*/
public
function
disableEvents
()
{
// Disables events
// This allows to test a single component and not all the application
$mock
=
Mockery
::
mock
(
'Illuminate
\C
ontracts
\E
vents
\D
ispatcher'
);
$mock
->
shouldReceive
(
'fire'
);
$mock
->
shouldReceive
(
'listen'
);
$this
->
app
->
instance
(
'events'
,
$mock
);
}
/**
* Mocks the broker
*/
public
function
disableBroker
()
{
$broker
=
new
BlackholeBroker
();
$broker
->
acceptAllMethodCalls
();
// allows to be used as a mock
$this
->
app
->
instance
(
'broker'
,
$broker
);
}
/**
* Mocks the broker, throwing an exception when sendMessage is called.
*/
public
function
mockNotOperationalBroker
()
{
$mock
=
Mockery
::
mock
(
'Keruald
\B
roker
\B
roker'
);
$mock
->
shouldReceive
(
'connect'
);
$mock
->
shouldReceive
(
'setExchangeTarget->routeTo->sendMessage'
)
->
andThrow
(
new
\RuntimeException
);
$this
->
app
->
instance
(
'broker'
,
$mock
);
}
/**
* Mocks the Phabricator API
*
* @return \Nasqueron\Notifications\Phabricator\PhabricatorAPIFactory The mock
*/
protected
function
mockPhabricatorAPI
()
{
// Inject into our container a mock of PhabricatorAPI
$mock
=
Mockery
::
mock
(
'Nasqueron
\N
otifications
\P
habricator
\P
habricatorAPIFactory'
);
$this
->
app
->
instance
(
'phabricator-api'
,
$mock
);
return
$mock
;
}
private
function
mockPhabricatorAPIProjectsQueryReply
()
{
$json
=
file_get_contents
(
'tests/data/PhabricatorProjetsQueryReply.json'
);
return
json_decode
(
$json
);
}
/**
* Mocks the Phabricator API
*/
protected
function
mockPhabricatorAPIForProjectsMap
()
{
$mock
=
$this
->
mockPhabricatorAPI
();
$reply
=
$this
->
mockPhabricatorAPIProjectsQueryReply
();
$mock
->
shouldReceive
(
'getForProject->call'
)->
andReturn
(
$reply
);
}
///
/// Helpers to post data to gates
///
/**
* Visits the given URI with a JSON request.
*
* @param string $uri
* @param mixed $data
* @param string $method
* @param array $headers
* @return $this
*/
public
function
sendJsonPayload
(
$uri
,
$data
,
$method
=
'POST'
,
array
$headers
=
[])
{
$content
=
json_encode
(
$data
);
$headers
=
array_merge
([
'CONTENT_TYPE'
=>
'application/json'
,
'Accept'
=>
'application/json'
,
],
$headers
);
return
$this
->
sendPayload
(
$uri
,
$content
,
$method
,
$headers
);
}
/**
* Visits the given URI with a raw request.
*
* @param string $uri
* @param string $content
* @param string $method
* @param array $headers
* @return $this
*/
public
function
sendPayload
(
$uri
,
$content
,
$method
=
'POST'
,
array
$headers
=
[])
{
$headers
=
array_merge
([
'CONTENT_LENGTH'
=>
mb_strlen
(
$content
,
'8bit'
),
],
$headers
);
$this
->
call
(
$method
,
$uri
,
[],
[],
[],
$this
->
transformHeadersToServerVars
(
$headers
),
$content
);
return
$this
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 20:13 (9 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2438033
Default Alt Text
TestCase.php (3 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment