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