3 namespace Friendica\Test\src\Model;
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;
13 class ProcessTest extends DatabaseTest
17 /** @var StaticDatabase */
20 protected function setUp(): void
26 $logger = new NullLogger();
28 $profiler = \Mockery::mock(Profiler::class);
29 $profiler->shouldReceive('startRecording');
30 $profiler->shouldReceive('stopRecording');
31 $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
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);
38 $this->dba = new StaticDatabase($configCache, $profiler, $logger);
41 public function testInsertDelete()
43 $process = new Process($this->dba);
45 self::assertEquals(0, $this->dba->count('process'));
46 $process->insert('test', 1);
47 $process->insert('test2', 2);
48 $process->insert('test3', 3);
50 self::assertEquals(3, $this->dba->count('process'));
54 ], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
56 $process->deleteByPid(1);
58 self::assertEmpty($this->dba->selectToArray('process', ['command'], ['pid' => 1]));
60 self::assertEquals(2, $this->dba->count('process'));
63 public function testDoubleInsert()
65 $process = new Process($this->dba);
67 $process->insert('test', 1);
69 // double insert doesn't work
70 $process->insert('test23', 1);
72 self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
76 * @doesNotPerformAssertions
78 public function testWrongDelete()
80 $process = new Process($this->dba);
82 // Just ignore wrong deletes, no execution is thrown
83 $process->deleteByPid(-1);