. */ declare(strict_types=1); namespace Tests\Unit\Factory; use FireflyIII\Factory\AccountMetaFactory; use Log; use Tests\TestCase; /** * * Class AccountMetaFactoryTest */ class AccountMetaFactoryTest extends TestCase { /** * */ public function setUp(): void { parent::setUp(); Log::info(sprintf('Now in %s.', \get_class($this))); } /** * @covers \FireflyIII\Factory\AccountMetaFactory */ public function testCreate(): void { $account = $this->user()->accounts()->inRandomOrder()->first(); $data = [ 'account_id' => $account->id, 'name' => 'Some name', 'data' => 'Some value', ]; $factory = new AccountMetaFactory; $result = $factory->create($data); $this->assertEquals($data['name'], $result->name); } /** * @covers \FireflyIII\Factory\AccountMetaFactory */ public function testCrudDelete(): void { $factory = new AccountMetaFactory; $account = $this->user()->accounts()->inRandomOrder()->first(); $data = [ 'account_id' => $account->id, 'name' => 'Some name ' . random_int(1, 100000), 'data' => 'Some value', ]; $factory->create($data); // update existing one $result = $factory->crud($account, $data['name'], ''); $this->assertNull($result); } /** * @covers \FireflyIII\Factory\AccountMetaFactory */ public function testCrudExisting(): void { $factory = new AccountMetaFactory; $account = $this->user()->accounts()->inRandomOrder()->first(); $data = [ 'account_id' => $account->id, 'name' => 'Some name ' . random_int(1, 100000), 'data' => 'Some value', ]; $existing = $factory->create($data); // update existing one $result = $factory->crud($account, $data['name'], 'Some NEW value'); $this->assertNotNull($result); $this->assertEquals($result->account_id, $account->id); $this->assertEquals($existing->name, $result->name); $this->assertEquals('Some NEW value', $result->data); } /** * @covers \FireflyIII\Factory\AccountMetaFactory */ public function testCrudNew(): void { $account = $this->user()->accounts()->inRandomOrder()->first(); $factory = new AccountMetaFactory; $result = $factory->crud($account, 'random name ' . random_int(1, 100000), 'Some value'); $this->assertNotNull($result); $this->assertEquals($result->account_id, $account->id); } }