Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F12239159
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/tests/Config/Reporting/IntegrationTest.php b/tests/Config/Reporting/IntegrationTest.php
new file mode 100644
index 0000000..5001221
--- /dev/null
+++ b/tests/Config/Reporting/IntegrationTest.php
@@ -0,0 +1,32 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Config\Reporting;
+
+use Nasqueron\Notifications\Tests\TestCase;
+
+class IntegrationTest extends TestCase {
+
+ public function setUp () {
+ parent::setUp();
+
+ $this->mockServices()
+ ->shouldReceive('get')
+ ->once()
+ ->andReturn([]); // No service
+ }
+
+ /**
+ * Config works.
+ */
+ public function testConfig() {
+ $json = $this->get('/config')
+ ->response
+ ->getContent();
+
+ $this->assertJsonStringEqualsJsonFile(
+ __DIR__ . "/../../data/config.json",
+ $json
+ );
+ }
+
+}
diff --git a/tests/Console/Commands/TestCase.php b/tests/Console/Commands/TestCase.php
index 0775ca2..22e2a32 100644
--- a/tests/Console/Commands/TestCase.php
+++ b/tests/Console/Commands/TestCase.php
@@ -1,82 +1,61 @@
<?php
namespace Nasqueron\Notifications\Tests\Console\Commands;
use Symfony\Component\Console\Tester\CommandTester;
use Nasqueron\Notifications\Config\Services\Service;
use Nasqueron\Notifications\Tests\TestCase as BaseTestCase;
use Artisan;
use Mockery;
class TestCase extends BaseTestCase {
///
/// Commands test environment
///
/**
* @var Symfony\Component\Console\Command
*/
protected $command;
/**
* @var Symfony\Component\Console\Tester\CommandTester;
*/
protected $tester;
public function setUp () {
parent::setUp();
$this->command = $this->findCommand($this->class);
$this->tester = new CommandTester($this->command);
}
///
/// Helper methods to manipulate command arrays
///
/**
* Finds the first instance of the expected type in the specified array.
*
* @param mixed $expectedType The type to find among the array elements
* @param array $haystack The array where to find
* @return mixed|null If not found, null. Otherwise, the found item.
*/
protected static function findInstanceOf ($expectedType, $haystack) {
foreach ($haystack as $item) {
if ($item instanceof $expectedType) {
return $item;
}
}
return null;
}
protected function findCommand ($expectedType) {
return self::findInstanceOf($expectedType, Artisan::all());
}
- ///
- /// Helper methods to mock services
- ///
-
- protected function mockServices () {
- // Inject into our container a mock of Services
- $mock = Mockery::mock('Nasqueron\Notifications\Config\Services\Services');
- $this->app->instance('services', $mock);
-
- return $mock;
- }
-
- protected function mockService ($gate = 'Storm') {
- $service = new Service;
- $service->gate = $gate;
- $service->door = 'Acme';
- $service->instance = "http://www.perdu.com";
-
- return $service;
- }
-
}
diff --git a/tests/TestCase.php b/tests/TestCase.php
index cf6a72c..0dd2c1d 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -1,143 +1,166 @@
<?php
namespace Nasqueron\Notifications\Tests;
+use Nasqueron\Notifications\Config\Services\Service;
+
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\Contracts\Events\Dispatcher');
$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\Broker\Broker');
$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\Notifications\Phabricator\PhabricatorAPIFactory');
$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);
}
+ ///
+ /// Helper methods to mock services
+ ///
+
+ protected function mockServices () {
+ // Inject into our container a mock of Services
+ $mock = Mockery::mock('Nasqueron\Notifications\Config\Services\Services');
+ $this->app->instance('services', $mock);
+
+ return $mock;
+ }
+
+ protected function mockService ($gate = 'Storm') {
+ $service = new Service;
+ $service->gate = $gate;
+ $service->door = 'Acme';
+ $service->instance = "http://www.perdu.com";
+
+ return $service;
+ }
+
///
/// 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;
}
}
diff --git a/tests/data/config.json b/tests/data/config.json
new file mode 100644
index 0000000..7b65e1f
--- /dev/null
+++ b/tests/data/config.json
@@ -0,0 +1,23 @@
+{
+ "gates": [
+ "DockerHub",
+ "GitHub",
+ "Jenkins",
+ "Phabricator"
+ ],
+ "features": [
+ {
+ "name": "Gate",
+ "enabled": true
+ },
+ {
+ "name": "GetConfig",
+ "enabled": true
+ },
+ {
+ "name": "ActionsReport",
+ "enabled": true
+ }
+ ],
+ "services": []
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Oct 11, 20:32 (4 h, 33 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3062005
Default Alt Text
(8 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment