Page MenuHomeDevCentral

D2589.id6532.diff
No OneTemporary

D2589.id6532.diff

diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -6,6 +6,10 @@
"phpunit/phpunit": "^9.5",
"ext-yaml": "*"
},
+ "require-dev": {
+ "nasqueron/codestyle": "^0.0.1",
+ "squizlabs/php_codesniffer": "^3.6"
+ },
"license": "BSD-2-Clause",
"authors": [
{
diff --git a/lib/Infrastructure/DockerContainer.php b/lib/Infrastructure/DockerContainer.php
--- a/lib/Infrastructure/DockerContainer.php
+++ b/lib/Infrastructure/DockerContainer.php
@@ -3,50 +3,50 @@
namespace Nasqueron\Infrastructure;
class DockerContainer {
- private $host;
- private $container;
+ private $host;
+ private $container;
- /**
- * Initializes a new instance of the DockerContainer class
- *
- * @param string $host hostname
- * @param string $container container name
- */
- public function __construct ($host, $container) {
- if (!self::isValidHostname($host)) {
- throw new ArgumentException("Invalid hostname.");
- }
- if (!self::isValidContainerName($container)) {
- throw new ArgumentException("Invalid container name.");
- }
+ /**
+ * Initializes a new instance of the DockerContainer class
+ *
+ * @param string $host hostname
+ * @param string $container container name
+ */
+ public function __construct ($host, $container) {
+ if (!self::isValidHostname($host)) {
+ throw new ArgumentException("Invalid hostname.");
+ }
+ if (!self::isValidContainerName($container)) {
+ throw new ArgumentException("Invalid container name.");
+ }
- $this->host = $host;
- $this->container = $container;
- }
+ $this->host = $host;
+ $this->container = $container;
+ }
- /**
- * Determines if a hostname is valid
- */
- public static function isValidHostname ($host) : bool {
- return (bool)preg_match('/^[A-Za-z0-9\-\.]+$/', $host);
- }
+ /**
+ * Determines if a hostname is valid
+ */
+ public static function isValidHostname ($host) : bool {
+ return (bool)preg_match('/^[A-Za-z0-9\-\.]+$/', $host);
+ }
- /**
- * Determines if a container name is valid
- */
- public static function isValidContainerName ($name) : bool {
- //Source: https://github.com/ajhager/docker/commit/f63cdf0260cf6287d28a589a79d3f947def6a569
- return (bool)preg_match('@^/?[a-zA-Z0-9_-]+$@', $name);
- }
+ /**
+ * Determines if a container name is valid
+ */
+ public static function isValidContainerName ($name) : bool {
+ //Source: https://github.com/ajhager/docker/commit/f63cdf0260cf6287d28a589a79d3f947def6a569
+ return (bool)preg_match('@^/?[a-zA-Z0-9_-]+$@', $name);
+ }
- /**
- * Executes the specified command in the container
- *
- * @param string $command the command to run
- * @return string the command output
- */
- public function exec ($command) : string {
- $output = `ssh $this->host sudo docker exec $this->container $command`;
- return trim($output);
- }
+ /**
+ * Executes the specified command in the container
+ *
+ * @param string $command the command to run
+ * @return string the command output
+ */
+ public function exec ($command) : string {
+ $output = `ssh $this->host sudo docker exec $this->container $command`;
+ return trim($output);
+ }
}
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<ruleset name="Nasqueron">
+ <rule ref="vendor/nasqueron/codestyle/CodeSniffer/ruleset.xml" />
+
+ <!-- Tests contain verbose explanations describing
+ what happens or how to fix the issue. -->
+ <rule ref="Generic.Files.LineLength">
+ <exclude-pattern>Test.php$</exclude-pattern>
+ </rule>
+
+ <file>tests</file>
+ <file>lib</file>
+</ruleset>
diff --git a/tests/DevCentralDockerTest.php b/tests/DevCentralDockerTest.php
--- a/tests/DevCentralDockerTest.php
+++ b/tests/DevCentralDockerTest.php
@@ -7,52 +7,52 @@
use Nasqueron\Infrastructure\DockerContainer;
class DevCentralDockerTest extends TestCase {
- private $container;
-
- const DOCKER_CONTAINER = 'devcentral';
-
- public function setUp () : void {
- if (!getenv('DOCKER_ACCESS')) {
- $this->markTestSkipped("No access to Docker engine.");
- }
-
- $this->container = new DockerContainer(getenv('DOCKER_HOST'), self::DOCKER_CONTAINER);
- }
-
- public function testInitialized () {
- $file = $this->container->exec("ls /opt/phabricator/.initialized");
-
- $this->assertSame(
- "/opt/phabricator/.initialized", $file,
- ".initialized file is missing: that could mean the whole /usr/local/bin/setup-phabricator didn't run."
- );
- }
-
- public function testProcesses () {
- $processes = $this->container->exec("ps auxw");
-
- $expectedProcesses = [
- 'nginx: master process',
- 'nginx: worker process',
- 'php-fpm: master process',
- 'phd-daemon',
- ];
-
- foreach ($expectedProcesses as $expectedProcess) {
- $this->assertStringContainsString($expectedProcess, $processes, "The process $expectedProcess isn't currently launched.");
- }
- }
-
- public function testPhabricatorDaemons () {
- $daemons = $this->container->exec("/opt/phabricator/bin/phd status");
-
- $expectedDaemons = [
- 'PhabricatorRepositoryPullLocalDaemon',
- 'PhabricatorTaskmasterDaemon',
- ];
-
- foreach ($expectedDaemons as $expectedDaemon) {
- $this->assertStringContainsString($expectedDaemon, $daemons, "The daemon $expectedDaemon isn't currently launched.");
- }
- }
+ private $container;
+
+ const DOCKER_CONTAINER = 'devcentral';
+
+ public function setUp () : void {
+ if (!getenv('DOCKER_ACCESS')) {
+ $this->markTestSkipped("No access to Docker engine.");
+ }
+
+ $this->container = new DockerContainer(getenv('DOCKER_HOST'), self::DOCKER_CONTAINER);
+ }
+
+ public function testInitialized () {
+ $file = $this->container->exec("ls /opt/phabricator/.initialized");
+
+ $this->assertSame(
+ "/opt/phabricator/.initialized", $file,
+ ".initialized file is missing: that could mean the whole /usr/local/bin/setup-phabricator didn't run."
+ );
+ }
+
+ public function testProcesses () {
+ $processes = $this->container->exec("ps auxw");
+
+ $expectedProcesses = [
+ 'nginx: master process',
+ 'nginx: worker process',
+ 'php-fpm: master process',
+ 'phd-daemon',
+ ];
+
+ foreach ($expectedProcesses as $expectedProcess) {
+ $this->assertStringContainsString($expectedProcess, $processes, "The process $expectedProcess isn't currently launched.");
+ }
+ }
+
+ public function testPhabricatorDaemons () {
+ $daemons = $this->container->exec("/opt/phabricator/bin/phd status");
+
+ $expectedDaemons = [
+ 'PhabricatorRepositoryPullLocalDaemon',
+ 'PhabricatorTaskmasterDaemon',
+ ];
+
+ foreach ($expectedDaemons as $expectedDaemon) {
+ $this->assertStringContainsString($expectedDaemon, $daemons, "The daemon $expectedDaemon isn't currently launched.");
+ }
+ }
}
diff --git a/tests/DevCentralTest.php b/tests/DevCentralTest.php
--- a/tests/DevCentralTest.php
+++ b/tests/DevCentralTest.php
@@ -5,18 +5,18 @@
use PHPUnit\Framework\TestCase;
class DevCentralTest extends TestCase {
- use WithAssertHttp;
+ use WithAssertHttp;
- public function testWebsiteIsUp () {
- $this->assertHttpResponseCode(200, 'https://devcentral.nasqueron.org', "DevCentral HTTPS issue.");
- $this->assertHttpResponseCode(500, 'https://phabricator-files-for-devcentral-nasqueron.spacetechnology.net', "DevCentral alternative domain should return a 500 error code for homepage. Check phabricator.base-uri isn't empty.");
- }
+ public function testWebsiteIsUp () {
+ $this->assertHttpResponseCode(200, 'https://devcentral.nasqueron.org', "DevCentral HTTPS issue.");
+ $this->assertHttpResponseCode(500, 'https://phabricator-files-for-devcentral-nasqueron.spacetechnology.net', "DevCentral alternative domain should return a 500 error code for homepage. Check phabricator.base-uri isn't empty.");
+ }
public function testNginxRedirectsHttpToHttps () {
- $this->assertHttpResponseCode(301, 'http://devcentral.nasqueron.org', 'Nginx should redirect http to https with a 301 code.');
+ $this->assertHttpResponseCode(301, 'http://devcentral.nasqueron.org', 'Nginx should redirect http to https with a 301 code.');
}
- public function testAphlictIsUp () {
- $this->assertHttpResponseCode(405, 'http://equatower.nasqueron.org:22281/', 'Aphlict server seems down. Check if the aphlict container is launched on the Docker engine.');
- }
+ public function testAphlictIsUp () {
+ $this->assertHttpResponseCode(405, 'http://equatower.nasqueron.org:22281/', 'Aphlict server seems down. Check if the aphlict container is launched on the Docker engine.');
+ }
}
diff --git a/tests/EtherpadTest.php b/tests/EtherpadTest.php
--- a/tests/EtherpadTest.php
+++ b/tests/EtherpadTest.php
@@ -5,24 +5,24 @@
use PHPUnit\Framework\TestCase;
class EtherpadTest extends TestCase {
- use WithAssertHttp;
+ use WithAssertHttp;
- public function testEtherpadIsLive () {
- $this->assertHttpResponseCode(301, 'http://pad.nasqueron.org/', "Etherpad isn't redirected on HTTP.");
- $this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/', "Etherpad looks down.");
- $this->assertHttpResponseCode(200, 'https://pad.wolfplex.be', "Etherpad doesn't reply to pad.wolfplex.be vhost.");
- $this->assertHttpResponseCode(404, 'https://pad.nasqueron.org/notexisting', 'A 404 code were expected for a not existing Etherpad page.');
- $this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/metrics', "ep_ether-o-meter plugin doesn't seem installed.");
- }
+ public function testEtherpadIsLive () {
+ $this->assertHttpResponseCode(301, 'http://pad.nasqueron.org/', "Etherpad isn't redirected on HTTP.");
+ $this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/', "Etherpad looks down.");
+ $this->assertHttpResponseCode(200, 'https://pad.wolfplex.be', "Etherpad doesn't reply to pad.wolfplex.be vhost.");
+ $this->assertHttpResponseCode(404, 'https://pad.nasqueron.org/notexisting', 'A 404 code were expected for a not existing Etherpad page.');
+ $this->assertHttpResponseCode(200, 'https://pad.nasqueron.org/metrics', "ep_ether-o-meter plugin doesn't seem installed.");
+ }
- public function testWolfplexApiWorks () {
- //Reported by philectro - 09:42 < philectro> hey tous les pad ont disparu :o
+ public function testWolfplexApiWorks () {
+ //Reported by philectro - 09:42 < philectro> hey tous les pad ont disparu :o
- $url = "https://api.wolfplex.org/pads/";
- $this->assertHttpResponseCode(200, $url);
+ $url = "https://api.wolfplex.org/pads/";
+ $this->assertHttpResponseCode(200, $url);
- $stringOnlyAvailableWhenApiWorks = '","'; // pads titles separator
- $currentContent = file_get_contents($url);
- $this->assertStringContainsString($stringOnlyAvailableWhenApiWorks, $currentContent, "On Ysul, /home/wolfplex.org/logs/api.log could help. But more probably, you reinstalled the Etherpad container without restoring the API key. Move the former APIKEY.txt file to /opt/etherpad-lite or, if lost, update Wolfplex API credentials with the new API key.");
- }
+ $stringOnlyAvailableWhenApiWorks = '","'; // pads titles separator
+ $currentContent = file_get_contents($url);
+ $this->assertStringContainsString($stringOnlyAvailableWhenApiWorks, $currentContent, "On Ysul, /home/wolfplex.org/logs/api.log could help. But more probably, you reinstalled the Etherpad container without restoring the API key. Move the former APIKEY.txt file to /opt/etherpad-lite or, if lost, update Wolfplex API credentials with the new API key.");
+ }
}
diff --git a/tests/NotificationsTest.php b/tests/NotificationsTest.php
--- a/tests/NotificationsTest.php
+++ b/tests/NotificationsTest.php
@@ -5,43 +5,43 @@
use PHPUnit\Framework\TestCase;
class NotificationsTest extends TestCase {
- use WithAssertHttp;
-
- ///
- /// Alive tests
- ///
-
- public function testIsLive () {
- $this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org', 'Notifications center looks down.');
- $this->assertHttpResponseCode(404, 'http://notifications.nasqueron.org/notexisting', 'A 404 code were expected for a not existing page.');
- }
-
- public function testSSL () {
- $this->assertHttpResponseCode(200, 'https://notifications.nasqueron.org/', "Notifications center HTTPS issue.");
- }
-
- public function testAlive () {
- $url = 'http://notifications.nasqueron.org/status';
- $this->assertHttpResponseCode(200, $url);
- $this->assertSame('ALIVE', file_get_contents($url));
- }
-
- ///
- /// Config tests
- ///
-
- public function testGates () {
- $this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org/gate/GitHub', 'Gate missing: check GitHub is declared');
- $this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org/gate/Phabricator/Nasqueron', 'Gate missing: check DevCentral is declared in credentials.json');
- }
-
- public function testConfig () {
- $url = 'https://notifications.nasqueron.org/config';
- $this->assertHttpResponseCode(200, $url);
- $this->assertJsonStringEqualsJsonFile(
- __DIR__ . "/data/notifications.config.json",
- file_get_contents($url),
- "The Notifications Center configuration doesn't match the expected configuration hardcoded in this repository."
- );
- }
+ use WithAssertHttp;
+
+ ///
+ /// Alive tests
+ ///
+
+ public function testIsLive () {
+ $this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org', 'Notifications center looks down.');
+ $this->assertHttpResponseCode(404, 'http://notifications.nasqueron.org/notexisting', 'A 404 code were expected for a not existing page.');
+ }
+
+ public function testSSL () {
+ $this->assertHttpResponseCode(200, 'https://notifications.nasqueron.org/', "Notifications center HTTPS issue.");
+ }
+
+ public function testAlive () {
+ $url = 'http://notifications.nasqueron.org/status';
+ $this->assertHttpResponseCode(200, $url);
+ $this->assertSame('ALIVE', file_get_contents($url));
+ }
+
+ ///
+ /// Config tests
+ ///
+
+ public function testGates () {
+ $this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org/gate/GitHub', 'Gate missing: check GitHub is declared');
+ $this->assertHttpResponseCode(200, 'http://notifications.nasqueron.org/gate/Phabricator/Nasqueron', 'Gate missing: check DevCentral is declared in credentials.json');
+ }
+
+ public function testConfig () {
+ $url = 'https://notifications.nasqueron.org/config';
+ $this->assertHttpResponseCode(200, $url);
+ $this->assertJsonStringEqualsJsonFile(
+ __DIR__ . "/data/notifications.config.json",
+ file_get_contents($url),
+ "The Notifications Center configuration doesn't match the expected configuration hardcoded in this repository."
+ );
+ }
}
diff --git a/tests/WithAssertHttp.php b/tests/WithAssertHttp.php
--- a/tests/WithAssertHttp.php
+++ b/tests/WithAssertHttp.php
@@ -5,24 +5,24 @@
use PHPUnit\Framework\TestCase;
trait WithAssertHttp {
- /**
- * Asserts the HTTP response code of an URL matches the expected code
- */
- private function assertHttpResponseCode (int $expectedCode, string $url, string $comment = '') : void {
- $actualCode = $this->getHttpResponseCode($url);
- $this->assertEquals($expectedCode, $actualCode, $comment);
- }
+ /**
+ * Asserts the HTTP response code of an URL matches the expected code
+ */
+ private function assertHttpResponseCode (int $expectedCode, string $url, string $comment = '') : void {
+ $actualCode = $this->getHttpResponseCode($url);
+ $this->assertEquals($expectedCode, $actualCode, $comment);
+ }
- /**
- * Gets the HTTP response code of the specified URL
- */
- private function getHttpResponseCode (string $url) : int {
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_USERAGENT, "Nasqueron-Ops-Tests");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_exec($ch);
- $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- return $code;
- }
+ /**
+ * Gets the HTTP response code of the specified URL
+ */
+ private function getHttpResponseCode (string $url) : int {
+ $ch = curl_init($url);
+ curl_setopt($ch, CURLOPT_USERAGENT, "Nasqueron-Ops-Tests");
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+ curl_exec($ch);
+ $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+ curl_close($ch);
+ return $code;
+ }
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 07:15 (17 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2259529
Default Alt Text
D2589.id6532.diff (16 KB)

Event Timeline