line(125.50, 1); $expense = $this->line(25.25, -1); $booking = new Booking; $booking->setRelation('subBookings', new Collection([$income, $expense])); $this->assertEquals(125.50, $income->signedAmount()); $this->assertEquals(-25.25, $expense->signedAmount()); $this->assertEquals(150.75, $booking->amount()); $this->assertEquals(100.25, $booking->signedAmount()); $this->assertFalse($booking->isSimple()); $this->assertNull($booking->accountType()); $this->assertNull($booking->project()); $this->assertNull($booking->personTarget()); } protected function line($amount, $factor) { $io = (new IOType)->forceFill(['factor' => $factor]); $class = (new AccountClass)->setRelation('ioType', $io); $account = (new AccountType)->setRelation('accountClass', $class); return (new SubBooking)->forceFill(['amount' => $amount])->setRelation('accountType', $account); } }