elliotchance / elliotchance/concise

SetUp() and tearDown() once fixtures

Open
#305 0 comments 0 reactions 0 assignees View on GitHub
Component: Core Size: 1 (Small) Type: Feature
Dominant language
PHP
Stars
45
Forks
3
PR merge metrics
No merged PRs in 30d

Description

Theres lots of ways this can be done, but in its most basic form you want to to run methods once, like:

``` php
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();
...
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.