File tree Expand file tree Collapse file tree
library/aik099/PHPUnit/MinkDriver
tests/aik099/PHPUnit/MinkDriver Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,7 +52,14 @@ public function add(IMinkDriverFactory $driver_factory)
5252 public function get ($ driver_name )
5353 {
5454 if ( !isset ($ this ->_registry [$ driver_name ]) ) {
55- throw new \OutOfBoundsException (sprintf ('No driver factory for "%s" driver. ' , $ driver_name ));
55+ $ error_msg = 'The " ' . $ driver_name . '" driver is unknown. ' ;
56+
57+ if ( $ this ->_registry ) {
58+ $ drivers = '" ' . implode ('", " ' , array_keys ($ this ->_registry )) . '" ' ;
59+ $ error_msg .= ' Please instead use any of these supported drivers: ' . $ drivers . '. ' ;
60+ }
61+
62+ throw new \OutOfBoundsException ($ error_msg );
5663 }
5764
5865 return $ this ->_registry [$ driver_name ];
Original file line number Diff line number Diff line change @@ -60,10 +60,28 @@ public function testAddingExisting()
6060 $ this ->_driverFactoryRegistry ->add ($ factory );
6161 }
6262
63- public function testGettingNonExisting ()
63+ public function testGettingNonExistingWithoutAlternatives ()
6464 {
6565 $ this ->expectException ('OutOfBoundsException ' );
66- $ this ->expectExceptionMessage ('No driver factory for "test" driver. ' );
66+ $ this ->expectExceptionMessage ('The "test" driver is unknown. ' );
67+
68+ $ this ->_driverFactoryRegistry ->get ('test ' );
69+ }
70+
71+ public function testGettingNonExistingWithAlternatives ()
72+ {
73+ $ this ->expectException ('OutOfBoundsException ' );
74+ $ this ->expectExceptionMessage (
75+ 'The "test" driver is unknown. Please instead use any of these supported drivers: "driver1", "driver2". '
76+ );
77+
78+ $ factory1 = m::mock (IMinkDriverFactory::class);
79+ $ factory1 ->shouldReceive ('getDriverName ' )->once ()->andReturn ('driver1 ' );
80+ $ this ->_driverFactoryRegistry ->add ($ factory1 );
81+
82+ $ factory2 = m::mock (IMinkDriverFactory::class);
83+ $ factory2 ->shouldReceive ('getDriverName ' )->once ()->andReturn ('driver2 ' );
84+ $ this ->_driverFactoryRegistry ->add ($ factory2 );
6785
6886 $ this ->_driverFactoryRegistry ->get ('test ' );
6987 }
You can’t perform that action at this time.
0 commit comments