diff options
| author | André Noack <noack@data-quest.de> | 2024-12-12 14:52:00 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2024-12-12 14:52:00 +0000 |
| commit | 940d2aaa8638b4e0c764579cb3977e7be527c81f (patch) | |
| tree | 79bd2d7f02359e1bb24931b33513e082f8404a91 /tests/unit | |
| parent | 3a2a88172ccbe97aaecf4ea32b97cd07b92dcb11 (diff) | |
StEP 1552 closes #1552
Closes #1552
Merge request studip/studip!1137
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/_bootstrap.php | 46 | ||||
| -rw-r--r-- | tests/unit/lib/classes/AvatarClassTest.php | 2 | ||||
| -rw-r--r-- | tests/unit/lib/classes/MarkupClassTest.php | 6 | ||||
| -rw-r--r-- | tests/unit/lib/classes/MigrationTest.php | 5 |
4 files changed, 54 insertions, 5 deletions
diff --git a/tests/unit/_bootstrap.php b/tests/unit/_bootstrap.php index 0cf0f7e..9bc68f5 100644 --- a/tests/unit/_bootstrap.php +++ b/tests/unit/_bootstrap.php @@ -51,7 +51,6 @@ require __DIR__ . '/../../composer/autoload.php'; global $STUDIP_BASE_PATH; $STUDIP_BASE_PATH = realpath(dirname(__DIR__) . '/..'); -require 'lib/helpers.php'; require 'lib/functions.php'; require 'lib/visual.inc.php'; @@ -125,3 +124,48 @@ if (!class_exists('StudipTestHelper')) { } } } + +//fake DI +class StudipFakeDIContainer +{ + private $storage; + private static $instance; + + public static function getInstance() + { + if (is_null(self::$instance)) { + self::$instance = new self(); + } + return self::$instance; + } + + public function get($name) + { + return $this->storage[$name] ?? null; + } + + public function set($name, $object) + { + $this->storage[$name] = $object; + } + + public function make($name, $parameters) + { + return $this->get($name); + } +} + +function app($entryId = null, $parameters = []) +{ + $container = StudipFakeDIContainer::getInstance(); + if (is_null($entryId)) { + return $container; + } + + return $container->make($entryId, $parameters); +} + +function sess() +{ + return app()->get('Studip\Session\Manager'); +} diff --git a/tests/unit/lib/classes/AvatarClassTest.php b/tests/unit/lib/classes/AvatarClassTest.php index e09a3c2..51bfab8 100644 --- a/tests/unit/lib/classes/AvatarClassTest.php +++ b/tests/unit/lib/classes/AvatarClassTest.php @@ -9,7 +9,7 @@ * the License, or (at your option) any later version. */ -require_once 'lib/phplib/Seminar_Perm.php'; +require_once 'lib/classes/Seminar_Perm.php'; abstract class AvatarTest extends \Codeception\Test\Unit { diff --git a/tests/unit/lib/classes/MarkupClassTest.php b/tests/unit/lib/classes/MarkupClassTest.php index 8dad6e9..7342a4a 100644 --- a/tests/unit/lib/classes/MarkupClassTest.php +++ b/tests/unit/lib/classes/MarkupClassTest.php @@ -33,9 +33,9 @@ require_once 'lib/classes/Markup.php'; # completely unneeded for testing the Markup class. # Instead, create a fake class. # => But note, this will fail if another test case does the same thing! -class Seminar_Session +class StudipSessionManager { - public static function is_current_session_authenticated() + public static function isCurrentSessionAuthenticated() { return true; } @@ -77,7 +77,7 @@ class MarkupClassTest extends \Codeception\Test\Unit })); Config::set($configStub); - + app()->set('Studip\Session\Manager', new StudipSessionManager()); # exceptions $namespace = 'Studip\MarkupPrivate\MediaProxy\\'; $invalidInternalLink = $namespace . 'InvalidInternalLinkException'; diff --git a/tests/unit/lib/classes/MigrationTest.php b/tests/unit/lib/classes/MigrationTest.php index 12df120..2e9db08 100644 --- a/tests/unit/lib/classes/MigrationTest.php +++ b/tests/unit/lib/classes/MigrationTest.php @@ -19,6 +19,11 @@ class MigrationTest extends \Codeception\Test\Unit require_once 'lib/migrations/Migration.php'; require_once 'lib/migrations/Migrator.php'; require_once 'lib/migrations/SchemaVersion.php'; + + $testconfig = new Config([ + 'LOG_ENABLE' => false, + ]); + Config::set($testconfig); } public function tearDown(): void |
