tests: Add missing test based on review's feedback.

This commit is contained in:
Pol Dellaiera 2021-04-01 12:04:35 +02:00 committed by Julien Fastré
parent c73e497d94
commit 55d963641e

View File

@ -172,7 +172,7 @@ class PersonTest extends \PHPUnit\Framework\TestCase
$p = new Person($date);
// Make sure that there is no last address.
$this->assertNull($p->getLastAddress());
$this::assertNull($p->getLastAddress());
// Take an arbitrary date before the $date in parameter.
$addressDate = $date->sub(new DateInterval('PT180M'));
@ -181,21 +181,29 @@ class PersonTest extends \PHPUnit\Framework\TestCase
$address1 = (new Address())->setValidFrom($addressDate);
$p->addAddress($address1);
$this->assertCount(1, $p->getAddresses());
$this->assertSame($address1, $p->getLastAddress());
$this::assertCount(1, $p->getAddresses());
$this::assertSame($address1, $p->getLastAddress());
// 2. Add an older address, which should not be the last address.
$address2 = (new Address())->setValidFrom($addressDate->sub(new DateInterval('PT30M')));
$addressDate2 = $addressDate->sub(new DateInterval('PT30M'));
$address2 = (new Address())->setValidFrom($addressDate2);
$p->addAddress($address2);
$this->assertCount(2, $p->getAddresses());
$this->assertSame($address1, $p->getLastAddress());
$this::assertCount(2, $p->getAddresses());
$this::assertSame($address1, $p->getLastAddress());
// 3. Add a newer address, which should be the last address.
$address3 = (new Address())->setValidFrom($addressDate->add(new DateInterval('PT30M')));
$addressDate3 = $addressDate->add(new DateInterval('PT30M'));
$address3 = (new Address())->setValidFrom($addressDate3);
$p->addAddress($address3);
$this->assertCount(3, $p->getAddresses());
$this->assertSame($address3, $p->getLastAddress());
$this::assertCount(3, $p->getAddresses());
$this::assertSame($address3, $p->getLastAddress());
// 4. Get the last address from a specific date.
$this::assertSame($address1, $p->getLastAddress($addressDate));
$this::assertSame($address2, $p->getLastAddress($addressDate2));
$this::assertSame($address3, $p->getLastAddress($addressDate3));
}
}