Open elliotchance opened 8 years ago
Theres lots of ways this can be done, but in its most basic form you want to to run methods once, like:
public function testGetAllAttendance() { $this->setUpOnce([$this, 'data']); ... } public function setUpOnce(callable $function) { static $setUp = []; $key = get_class($function[0]) . '::' . $function[1]; if (!array_key_exists($key, $setUp)) { $function(); $setUp[$key] = get_object_vars($this); } else { foreach ($setUp[$key] as $k => $v) { $this->$k = $v; } } } public function data() { $this->company = $this->createCompany(); ... }
Theres lots of ways this can be done, but in its most basic form you want to to run methods once, like: