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()
27 $logger = new NullLogger();
29 $profiler = \Mockery::mock(Profiler::class);
30 $profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
32 // load real config to avoid mocking every config-entry which is related to the Database class
33 $configFactory = new ConfigFactory();
34 $loader = new ConfigFileLoader($this->root->url());
35 $configCache = $configFactory->createCache($loader);
37 $this->dba = new StaticDatabase($configCache, $profiler, $logger);
40 public function testInsertDelete()
42 $process = new Process($this->dba);
44 self::assertEquals(0, $this->dba->count('process'));
45 $process->insert('test', 1);
46 $process->insert('test2', 2);
47 $process->insert('test3', 3);
49 self::assertEquals(3, $this->dba->count('process'));
53 ], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
55 $process->deleteByPid(1);
57 self::assertEmpty($this->dba->selectToArray('process', ['command'], ['pid' => 1]));
59 self::assertEquals(2, $this->dba->count('process'));
62 public function testDoubleInsert()
64 $process = new Process($this->dba);
66 $process->insert('test', 1);
68 // double insert doesn't work
69 $process->insert('test23', 1);
71 self::assertEquals([['command' => 'test']], $this->dba->selectToArray('process', ['command'], ['pid' => 1]));
74 public function testWrongDelete()
76 $process = new Process($this->dba);
78 // Just ignore wrong deletes, no execution is thrown
79 $process->deleteByPid(-1);