]> git.mxchange.org Git - friendica.git/blob - tests/src/Model/ProcessTest.php
Merge remote-tracking branch 'upstream/develop' into error-handling
[friendica.git] / tests / src / Model / ProcessTest.php
1 <?php
2
3 namespace Friendica\Test\src\Model;
4
5 use Friendica\Core\Config\Factory\Config;
6 use Friendica\Model\Process;
7 use Friendica\Test\DatabaseTest;
8 use Friendica\Test\Util\Database\StaticDatabase;
9 use Friendica\Test\Util\VFSTrait;
10 use Friendica\Util\Profiler;
11 use Psr\Log\NullLogger;
12
13 class ProcessTest extends DatabaseTest
14 {
15         use VFSTrait;
16
17         /** @var StaticDatabase */
18         private $dba;
19
20         protected function setUp(): void
21         {
22                 parent::setUp();
23
24                 $this->setUpVfsDir();
25
26                 $logger = new NullLogger();
27
28                 $profiler = \Mockery::mock(Profiler::class);
29                 $profiler->shouldReceive('startRecording');
30                 $profiler->shouldReceive('stopRecording');
31                 $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
32
33                 // load real config to avoid mocking every config-entry which is related to the Database class
34                 $configFactory = new Config();
35                 $loader        = (new Config())->createConfigFileLoader($this->root->url(), []);
36                 $configCache   = $configFactory->createCache($loader);
37
38                 $this->dba = new StaticDatabase($configCache, $profiler, $logger);
39         }
40
41         public function testInsertDelete()
42         {
43                 $process = new Process($this->dba);
44
45                 self::assertEquals(0, $this->dba->count('process'));
46                 $process->insert('test', 1);
47                 $process->insert('test2', 2);
48                 $process->insert('test3', 3);
49
50                 self::assertEquals(3, $this->dba->count('process'));
51
52                 self::assertEquals([
53                         ['command' => 'test']
54                 ], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
55
56                 $process->deleteByPid(1);
57
58                 self::assertEmpty($this->dba->selectToArray('process', ['command'], ['pid' => 1]));
59
60                 self::assertEquals(2, $this->dba->count('process'));
61         }
62
63         public function testDoubleInsert()
64         {
65                 $process = new Process($this->dba);
66
67                 $process->insert('test', 1);
68
69                 // double insert doesn't work
70                 $process->insert('test23', 1);
71
72                 self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
73         }
74
75         /**
76          * @doesNotPerformAssertions
77          */
78         public function testWrongDelete()
79         {
80                 $process = new Process($this->dba);
81
82                 // Just ignore wrong deletes, no execution is thrown
83                 $process->deleteByPid(-1);
84         }
85 }