Skip to content

Commit 6724b2d

Browse files
author
Adam Benson
committed
Added AutoMockingTest::autoMock(string $className) to alias TestInjector::create for decreased verbosity in tests.
1 parent 25b23fc commit 6724b2d

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

composer.lock

Lines changed: 13 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AutoMockingTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ protected function setUp()
2424
$this->injector = new TestInjector();
2525
}
2626

27+
/**
28+
* Create an instance of $className and automatically mock all its constructor dependencies.
29+
* @param string $className The FQCN of the class we are creating
30+
* @param array $parameters Any parameters to pass to the constructor. Can be keyed by type, name or position.
31+
* @return object
32+
*/
33+
protected function autoMock($className, $parameters = []){
34+
return $this->injector->create($className, $parameters);
35+
}
36+
2737
/**
2838
* Tears down the fixture, for example, close a network connection.
2939
* This method is called after a test is executed.
@@ -33,4 +43,4 @@ protected function tearDown()
3343
parent::tearDown();
3444
$this->injector->checkPredictions();
3545
}
36-
}
46+
}

0 commit comments

Comments
 (0)