]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/SystemTest.php
Fix mock test (remove "implicit" usage of previous Dice-setups)
[friendica.git] / tests / src / Core / SystemTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core;
4
5 use Dice\Dice;
6 use Friendica\App\BaseURL;
7 use Friendica\Core\System;
8 use Friendica\DI;
9 use PHPUnit\Framework\TestCase;
10
11 class SystemTest extends TestCase
12 {
13         protected function setUp()
14         {
15                 parent::setUp();
16
17                 $baseUrl = \Mockery::mock(BaseURL::class);
18                 $baseUrl->shouldReceive('getHostname')->andReturn('friendica.local')->once();
19                 $dice = \Mockery::mock(Dice::class);
20                 $dice->shouldReceive('create')->with(BaseURL::class, [])->andReturn($baseUrl);
21
22                 DI::init($dice);
23         }
24
25         private function assertGuid($guid, $length, $prefix = '')
26         {
27                 $length -= strlen($prefix);
28                 $this->assertRegExp("/^" . $prefix . "[a-z0-9]{" . $length . "}?$/", $guid);
29         }
30
31         function testGuidWithoutParameter()
32         {
33                 $guid = System::createGUID();
34                 $this->assertGuid($guid, 16);
35         }
36
37         function testGuidWithSize32() {
38                 $guid = System::createGUID(32);
39                 $this->assertGuid($guid, 32);
40         }
41
42         function testGuidWithSize64() {
43                 $guid = System::createGUID(64);
44                 $this->assertGuid($guid, 64);
45         }
46
47         function testGuidWithPrefix() {
48                 $guid = System::createGUID(23, 'test');
49                 $this->assertGuid($guid, 23, 'test');
50         }
51 }