Skip to content

[5.6] Dynamically compose template methods (setUp/tearDown) from TestCase traits #21126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from

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