Start to build 'example data' for unit tests.
I wanted to look at building up ExampleData for a scenario to use in
a) unit tests and b) to be able to generate into a test database for manual testing
with 2 contacts, each having a recurring contribution.
I thought I might be able to use the new ExampleData api to start to define that and to that end I tried to switch the most commonly used ExampleData in our unit tests to be a defined ExampleData set.
However, the ExampleData api didn't work as I expected - ie it returned a list of available examples but not the data those examples offered - a getlist kinda function.
This is how I thought it would work - but it doesn't.
I'm going to put up my sample data for Anthony in a PR linked to this issue, although it won't be used yet
public function individualCreate(array $params = [], $seq = 0, $random = FALSE): int {
+ if ($seq === 0 && !$random) {
+ try {
+ $exampleData = ExampleData::get(FALSE)->addWhere(
+ 'name', '=', 'entity/Contact/Anthony')
+ ->execute()->first();
+ $contact = Contact::create(FALSE)->setValues($exampleData)
+ ->addChain('primary_email',
+ Email::create(FALSE)
+ ->setValues([
+ 'email' => $exampleData['primary_email.email'],
+ 'contact_id' => '$contact.id',
+ ])
+ )
+ ->execute()->first();
+ }
+ catch (\API_Exception $e) {
+ $this->fail('failed to create contact');
+ }
+ return $contact['id'];
+ }