There are multiple options
Keeping them in the same test file
One way to get around this is using annotation to separate your test methods from your other methods. Aditionally, you can make the helper protected or private. class MyTest extends TestCase {
protected function myHelperFunction($arg) {
return $arg + some actions;
}
/** @test */
public function put_a_descriptive_method_name_here() {
$arg = "my_arg_here";
$this->assertNotNull($this->myHelperFunction($arg));
}
... //other tests that involve my helper function
}
Put the helpers in the TestCase class
You can put the methods on the base TestCase class if you'd likeabstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp()
{
parent::setUp();
//....
}
protected function myHelperFunction($arg)
{
return $arg + some actions;
}
}
Extract them to (e.g.) a helpers.php file
A different option is to put them in a helpers.php file in your tests directory, which you autoload using composer.In composer.json:
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
},
"files": [
"tests/helpers.php"
]
},
Don't forget to dump the autoload using
composer dump-autoload