Auto-Inject into Test\Unit #4070

Merged
merged 3 commits into from Mar 25, 2017

Conversation

Projects
None yet
1 participant
@DavertMik
Member

DavertMik commented Mar 21, 2017

This is the new recommended approach to use actor classes inside unit tests:

function _inject(UnitTester $I)
{
    $this->i = $I;
}

function testRobotUserIsInsideDatabase()
{
    $this->i->seeInDatabase('users', ['id' => 1, 'name' => 'robot']);
}

$this->tester injection into Test\Unit classes happen in a very mysterious way. While this injection still happens it should be done explicitly, using _inject method we already have. This will allow to specify and name properties in predictable names. This will also allow to use classes based on Actor, like PageObjects, or StepObjects.

This new recommended way will be added to docs, while old one will be removed. However, property-based old-style injection will be kept till 3.0 and probably even after it.

DavertMik added some commits Mar 21, 2017

allow to inject actor classes and other objects from DI into the Test…
…\Unit via inject

deprecates using  $this->tester in favor of common _inject()

@DavertMik DavertMik merged commit eb1d3d7 into 2.2 Mar 25, 2017

6 checks passed

continuous-integration/appveyor/branch AppVeyor build succeeded
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
semaphoreci The build passed on Semaphore.
Details
wercker/build Wercker pipeline passed
Details

@DavertMik DavertMik deleted the tests-inject branch Mar 25, 2017

chris1312 added a commit to chris1312/Codeception that referenced this pull request Jun 16, 2017

Auto-Inject into Test\Unit (#4070)
* allow to inject actor classes and other objects from DI into the Test\Unit via inject
deprecates using  $this->tester in favor of common _inject()

* fixed creating actor object via di
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment