11<?php
2+
23namespace Bigcommerce \MockInjector ;
34
45use Prophecy \Exception \Prediction \AggregateException ;
@@ -11,6 +12,7 @@ class ProphecyMockingContainer implements MockingContainerInterface
1112 * @var Prophet
1213 */
1314 private $ prophet ;
15+
1416 /**
1517 * Collection of mocks we've auto-created keyed by their FQCN
1618 * @var ObjectProphecy[]
@@ -43,7 +45,7 @@ public function checkPredictions()
4345 */
4446 public function get ($ id )
4547 {
46- return $ this ->createOrGetMock ($ id )->reveal ();
48+ return $ this ->createOrGetMock ($ id )->reveal ();
4749 }
4850
4951 /**
@@ -59,19 +61,25 @@ public function has($id)
5961 /**
6062 * Fetch one of the mocks that was auto-created by the MockInjector to construct objects used in the current test,
6163 * so that you can set expectations or configure mock methods.
64+ * Alternatively, will create and return a mock which the injector will use (useful for setting expectations
65+ * on constructor behaviours prior to calling injector create)
6266 * @param string $mockClassName FQCN of the dependency we mocked
6367 * @return ObjectProphecy
64- * @throws \InvalidArgumentException
6568 */
6669 public function getMock ($ mockClassName )
6770 {
68- if (!isset ($ this ->mocks [$ mockClassName ])) {
69- throw new \InvalidArgumentException (
70- "The MockInjector did not create a ' $ mockClassName' mock so it can not be retrieved. "
71- );
72- }
71+ return $ this ->createOrGetMock ($ mockClassName );
72+ }
7373
74- return $ this ->mocks [$ mockClassName ];
74+ /**
75+ * Set a prophecy to be used by the injector rather than creating on demand.
76+ * @param string $mockClassName
77+ * @param ObjectProphecy $mock
78+ * @return void
79+ */
80+ public function setMock (string $ mockClassName , ObjectProphecy $ mock )
81+ {
82+ $ this ->mocks [$ mockClassName ] = $ mock ;
7583 }
7684
7785 /**
0 commit comments