Skip to content

Conversation

@inxilpro
Copy link
Contributor

This is a copy of #21095 for the master branch.

The current TestCase:: setUpTraits method has a hard-coded list of method calls. This uses class_uses_recursive similarly to the way Model::bootTraits behaves, calling setUp<TraitName> and tearDown<TraitName> if they're set.

This means that if you had a test case & trait like:

<?php

trait FooBar
{
    protected $foo;

    public function setUpFooBar()
    {
        $this->foo = 'bar';
    }
}

class MyTest extends TestCase
{
    use FooBar;

    public function testFooBar()
    {
        $this->assertEquals('bar', $this->foo);
    }
}

The $foo property would automatically set to "bar" before each test case.

@taylorotwell
Copy link
Member

No plans to add this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants