Fix creating plan and member in WooCommerceMembership data factory

Membership commands return a string message, so we need to parse ID from a sentence.
[MAILPOET-4095]
This commit is contained in:
Jan Lysý
2022-01-31 16:52:05 +01:00
committed by Pavel Dohnal
parent 69cbe75f16
commit 6ed1bdeaa1

View File

@ -16,16 +16,18 @@ class WooCommerceMembership {
$createCommand = ['wc', 'memberships', 'plan', 'create']; $createCommand = ['wc', 'memberships', 'plan', 'create'];
$createCommand[] = "--name='{$name}'"; $createCommand[] = "--name='{$name}'";
$createOutput = $this->tester->cliToString($createCommand); $createOutput = $this->tester->cliToString($createCommand);
$planOut = $this->tester->cliToString(['wc', 'membership_plan', 'get', $createOutput, '--format=json']); preg_match('!\d+!', $createOutput, $matches);
$planOut = $this->tester->cliToString(['wc', 'membership_plan', 'get', reset($matches), '--format=json', '--user=admin']);
return json_decode($planOut, true); return json_decode($planOut, true);
} }
public function createMember(int $userId, int $planId) { public function createMember(int $userId, int $planId) {
$createCommand = ['wc', 'user_membership', 'create']; $createCommand = ['wc', 'user_membership', 'create', '--user=admin'];
$createCommand[] = "--customer_id='{$userId}'"; $createCommand[] = "--customer_id='{$userId}'";
$createCommand[] = "--plan_id='{$userId}'"; $createCommand[] = "--plan_id='{$planId}'";
$createOutput = $this->tester->cliToString($createCommand); $createOutput = $this->tester->cliToString($createCommand);
$membershipOut = $this->tester->cliToString(['wc', 'user_membership', 'get', $createOutput, '--format=json']); preg_match('!\d+!', $createOutput, $matches);
$membershipOut = $this->tester->cliToString(['wc', 'user_membership', 'get', reset($matches), '--format=json', '--user=admin']);
return json_decode($membershipOut, true); return json_decode($membershipOut, true);
} }
} }