summaryrefslogtreecommitdiff
path: root/tests/Unit
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-07-21 13:38:05 +0200
committerGitHub <noreply@github.com>2019-07-21 13:38:05 +0200
commit1e16f4c47ec15ffea41e1fa612d205b8db2a16d1 (patch)
tree0d436535bd7094a201e52036acd406f00bfc620f /tests/Unit
parent3d8476efd3709806d254b1c41e26e906080e0b39 (diff)
parent4582f808f05205e7a32ecd6ae42dee00295872f1 (diff)
Merge pull request #624 from MyIgel/version
Added version to credits and metrics page
Diffstat (limited to 'tests/Unit')
-rw-r--r--tests/Unit/Controllers/CreditsControllerTest.php16
-rw-r--r--tests/Unit/Controllers/Metrics/ControllerTest.php22
-rw-r--r--tests/Unit/Helpers/Stub/files/VERSION1
-rw-r--r--tests/Unit/Helpers/VersionServiceProviderTest.php25
-rw-r--r--tests/Unit/Helpers/VersionTest.php28
5 files changed, 80 insertions, 12 deletions
diff --git a/tests/Unit/Controllers/CreditsControllerTest.php b/tests/Unit/Controllers/CreditsControllerTest.php
index 42ea4ea1..303bf60e 100644
--- a/tests/Unit/Controllers/CreditsControllerTest.php
+++ b/tests/Unit/Controllers/CreditsControllerTest.php
@@ -4,9 +4,10 @@ namespace Engelsystem\Test\Unit\Controllers;
use Engelsystem\Config\Config;
use Engelsystem\Controllers\CreditsController;
+use Engelsystem\Helpers\Version;
use Engelsystem\Http\Response;
+use Engelsystem\Test\Unit\TestCase;
use PHPUnit\Framework\MockObject\MockObject;
-use PHPUnit\Framework\TestCase;
class CreditsControllerTest extends TestCase
{
@@ -19,12 +20,17 @@ class CreditsControllerTest extends TestCase
/** @var Response|MockObject $response */
$response = $this->createMock(Response::class);
$config = new Config(['foo' => 'bar', 'credits' => ['lor' => 'em']]);
+ /** @var Version|MockObject $version */
+ $version = $this->createMock(Version::class);
- $response->expects($this->once())
- ->method('withView')
- ->with('pages/credits.twig', ['credits' => ['lor' => 'em']]);
+ $this->setExpects(
+ $response,
+ 'withView',
+ ['pages/credits.twig', ['credits' => ['lor' => 'em'], 'version' => '42.1.0-test']]
+ );
+ $this->setExpects($version, 'getVersion', [], '42.1.0-test');
- $controller = new CreditsController($response, $config);
+ $controller = new CreditsController($response, $config, $version);
$controller->index();
}
}
diff --git a/tests/Unit/Controllers/Metrics/ControllerTest.php b/tests/Unit/Controllers/Metrics/ControllerTest.php
index 18daa96a..f203200c 100644
--- a/tests/Unit/Controllers/Metrics/ControllerTest.php
+++ b/tests/Unit/Controllers/Metrics/ControllerTest.php
@@ -6,6 +6,7 @@ use Engelsystem\Config\Config;
use Engelsystem\Controllers\Metrics\Controller;
use Engelsystem\Controllers\Metrics\MetricsEngine;
use Engelsystem\Controllers\Metrics\Stats;
+use Engelsystem\Helpers\Version;
use Engelsystem\Http\Exceptions\HttpForbidden;
use Engelsystem\Http\Request;
use Engelsystem\Http\Response;
@@ -28,7 +29,8 @@ class ControllerTest extends TestCase
/** @var MetricsEngine|MockObject $engine */
/** @var Stats|MockObject $stats */
/** @var Config $config */
- list($response, $request, $engine, $stats, $config) = $this->getMocks();
+ /** @var Version|MockObject $version */
+ list($response, $request, $engine, $stats, $config, $version) = $this->getMocks();
$request->server = new ServerBag();
$request->server->set('REQUEST_TIME_FLOAT', 0.0123456789);
@@ -37,6 +39,7 @@ class ControllerTest extends TestCase
->method('get')
->willReturnCallback(function ($path, $data) use ($response) {
$this->assertEquals('/metrics', $path);
+ $this->assertArrayHasKey('info', $data);
$this->assertArrayHasKey('users', $data);
$this->assertArrayHasKey('licenses', $data);
$this->assertArrayHasKey('users_working', $data);
@@ -122,7 +125,9 @@ class ControllerTest extends TestCase
'XL' => 'X Large',
]);
- $controller = new Controller($response, $engine, $config, $request, $stats);
+ $this->setExpects($version, 'getVersion', [], '0.42.42');
+
+ $controller = new Controller($response, $engine, $config, $request, $stats, $version);
$controller->metrics();
}
@@ -137,7 +142,8 @@ class ControllerTest extends TestCase
/** @var MetricsEngine|MockObject $engine */
/** @var Stats|MockObject $stats */
/** @var Config $config */
- list($response, $request, $engine, $stats, $config) = $this->getMocks();
+ /** @var Version|MockObject $version */
+ list($response, $request, $engine, $stats, $config, $version) = $this->getMocks();
$response->expects($this->once())
->method('withHeader')
@@ -168,7 +174,7 @@ class ControllerTest extends TestCase
$this->setExpects($stats, 'arrivedUsers', null, 10, $this->exactly(2));
$this->setExpects($stats, 'currentlyWorkingUsers', null, 5);
- $controller = new Controller($response, $engine, $config, $request, $stats);
+ $controller = new Controller($response, $engine, $config, $request, $stats, $version);
$controller->stats();
}
@@ -182,7 +188,8 @@ class ControllerTest extends TestCase
/** @var MetricsEngine|MockObject $engine */
/** @var Stats|MockObject $stats */
/** @var Config $config */
- list($response, $request, $engine, $stats, $config) = $this->getMocks();
+ /** @var Version|MockObject $version */
+ list($response, $request, $engine, $stats, $config, $version) = $this->getMocks();
$request->expects($this->once())
->method('get')
@@ -191,7 +198,7 @@ class ControllerTest extends TestCase
$config->set('api_key', 'fooBar!');
- $controller = new Controller($response, $engine, $config, $request, $stats);
+ $controller = new Controller($response, $engine, $config, $request, $stats, $version);
$this->expectException(HttpForbidden::class);
$this->expectExceptionMessage(json_encode(['error' => 'The api_key is invalid']));
@@ -212,7 +219,8 @@ class ControllerTest extends TestCase
/** @var Stats|MockObject $stats */
$stats = $this->createMock(Stats::class);
$config = new Config();
+ $version = $this->createMock(Version::class);
- return [$response, $request, $engine, $stats, $config];
+ return [$response, $request, $engine, $stats, $config, $version];
}
}
diff --git a/tests/Unit/Helpers/Stub/files/VERSION b/tests/Unit/Helpers/Stub/files/VERSION
new file mode 100644
index 00000000..749a96f3
--- /dev/null
+++ b/tests/Unit/Helpers/Stub/files/VERSION
@@ -0,0 +1 @@
+0.42.0-testing
diff --git a/tests/Unit/Helpers/VersionServiceProviderTest.php b/tests/Unit/Helpers/VersionServiceProviderTest.php
new file mode 100644
index 00000000..609c649d
--- /dev/null
+++ b/tests/Unit/Helpers/VersionServiceProviderTest.php
@@ -0,0 +1,25 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers;
+
+use Engelsystem\Application;
+use Engelsystem\Helpers\Version;
+use Engelsystem\Helpers\VersionServiceProvider;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+
+class VersionServiceProviderTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Helpers\VersionServiceProvider::register
+ */
+ public function testRegister()
+ {
+ $app = new Application();
+ $app->instance('path.storage.app', '/tmp');
+
+ $serviceProvider = new VersionServiceProvider($app);
+ $serviceProvider->register();
+
+ $this->assertArrayHasKey(Version::class, $app->contextual);
+ }
+}
diff --git a/tests/Unit/Helpers/VersionTest.php b/tests/Unit/Helpers/VersionTest.php
new file mode 100644
index 00000000..40569abb
--- /dev/null
+++ b/tests/Unit/Helpers/VersionTest.php
@@ -0,0 +1,28 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Helpers;
+
+use Engelsystem\Config\Config;
+use Engelsystem\Helpers\Version;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+
+class VersionTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Helpers\Version::__construct
+ * @covers \Engelsystem\Helpers\Version::getVersion
+ */
+ public function testGetVersion()
+ {
+ $config = new Config();
+ $version = new Version(__DIR__ . '/Stub', $config);
+
+ $this->assertEquals('n/a', $version->getVersion());
+
+ $version = new Version(__DIR__ . '/Stub/files', $config);
+ $this->assertEquals('0.42.0-testing', $version->getVersion());
+
+ $config->set('version', '1.2.3-dev');
+ $this->assertEquals('1.2.3-dev', $version->getVersion());
+ }
+}