This repository was archived by the owner on Jul 28, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +28
-27
lines changed
Expand file tree Collapse file tree 4 files changed +28
-27
lines changed Original file line number Diff line number Diff line change 22
33namespace Wavevision \NetteTests ;
44
5+ use Nette \Configurator ;
6+ use PHPUnit \Framework \TestCase ;
7+
58class Configuration
69{
710
@@ -10,19 +13,34 @@ class Configuration
1013 */
1114 private static $ configuratorFactory ;
1215
13- public static function setConfiguratorFactory (callable $ configuratorFactory ): void
16+ public static function setup (callable $ configuratorFactory ): void
1417 {
18+ ob_start ();
1519 self ::$ configuratorFactory = $ configuratorFactory ;
1620 }
1721
18- public static function getConfiguratorFactory (): callable
19- {
20- return self ::$ configuratorFactory ;
21- }
22-
23- public static function setup (): void
22+ public static function createConfigurator (TestCase $ testCase ): Configurator
2423 {
25- ob_start ();
24+ $ configuratorFactory = self ::$ configuratorFactory ;
25+ if (!is_callable ($ configuratorFactory )) {
26+ throw new InvalidState (
27+ sprintf (
28+ "Setup method not called. Call '%s::setup()' method in bootstrap file. " ,
29+ self ::class
30+ )
31+ );
32+ }
33+ $ configurator = $ configuratorFactory ($ testCase );
34+ if ($ configurator instanceof Configurator) {
35+ return $ configurator ;
36+ } else {
37+ throw new InvalidState (
38+ sprintf (
39+ '\'%1$s::getConfigurationFactory() \' should return instance of \'%1$s \'. ' ,
40+ Configuration::class
41+ )
42+ );
43+ }
2644 }
2745
2846}
Original file line number Diff line number Diff line change 22
33namespace Wavevision \NetteTests \TestCases ;
44
5- use Nette \Configurator ;
65use PHPUnit \Framework \TestCase ;
76use Wavevision \NetteTests \Configuration ;
8- use Wavevision \NetteTests \InvalidState ;
97use Wavevision \NetteTests \TestCases \Parts \SetupContainer ;
108
119class DIContainerTestCase extends TestCase
@@ -16,18 +14,7 @@ class DIContainerTestCase extends TestCase
1614 protected function setUp (): void
1715 {
1816 parent ::setUp ();
19- $ configuration = Configuration::getConfiguratorFactory ()($ this );
20- if ($ configuration instanceof Configurator) {
21- $ this ->setupContainer ($ configuration , $ this );
22- } else {
23- throw new InvalidState (
24- sprintf (
25- "'%s::getConfigurationFactory()' should return instance of '%s'. " ,
26- Configuration::class,
27- Configurator::class
28- )
29- );
30- }
17+ $ this ->setupContainer (Configuration::createConfigurator ($ this ), $ this );
3118 }
3219
3320}
Original file line number Diff line number Diff line change 1313use Wavevision \NetteTests \Runners \PresenterRequest ;
1414use Wavevision \NetteTests \Runners \PresenterResponse ;
1515
16- /**
17- * @todo flash messages
18- */
1916trait PresenterAsserts
2017{
2118
Original file line number Diff line number Diff line change 44use Wavevision \NetteTests \Configuration ;
55
66require __DIR__ . '/../../../vendor/autoload.php ' ;
7- Configuration::setup ();
8- Configuration::setConfiguratorFactory (
7+ Configuration::setup (
98 function (): Configurator {
109 $ configurator = new Configurator ();
1110 $ rootDir = __DIR__ . '/.. ' ;
You can’t perform that action at this time.
0 commit comments