3 namespace Friendica\Test\src\Model;
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;
14 class ProcessTest extends DatabaseTest
18 /** @var StaticDatabase */
21 protected function setUp(): void
27 $logger = new NullLogger();
29 $profiler = \Mockery::mock(Profiler::class);
30 $profiler->shouldReceive('startRecording');
31 $profiler->shouldReceive('stopRecording');
32 $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
34 // load real config to avoid mocking every config-entry which is related to the Database class
35 $configFactory = new ConfigFactory();
36 $loader = new ConfigFileLoader($this->root->url(), []);
37 $configCache = $configFactory->createCache($loader);
39 $this->dba = new StaticDatabase($configCache, $profiler, $logger);
42 public function testInsertDelete()
44 $process = new Process($this->dba);
46 self::assertEquals(0, $this->dba->count('process'));
47 $process->insert('test', 1);
48 $process->insert('test2', 2);
49 $process->insert('test3', 3);
51 self::assertEquals(3, $this->dba->count('process'));
55 ], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
57 $process->deleteByPid(1);
59 self::assertEmpty($this->dba->selectToArray('process', ['command'], ['pid' => 1]));
61 self::assertEquals(2, $this->dba->count('process'));
64 public function testDoubleInsert()
66 $process = new Process($this->dba);
68 $process->insert('test', 1);
70 // double insert doesn't work
71 $process->insert('test23', 1);
73 self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
77 * @doesNotPerformAssertions
79 public function testWrongDelete()
81 $process = new Process($this->dba);
83 // Just ignore wrong deletes, no execution is thrown
84 $process->deleteByPid(-1);