title: How can I unit test a method that dispatches events that alter behavior of the method under test?
body: <p>I have a custom event that has a public property:</p>
  
  <pre><code>class MyCustomEvent
  {
      public $allowAction = false;
  }
  </code></pre>
  
  <p>I have a class that creates this event, and dispatches an event with the event object, allowing event listeners/subscribers to change the property on the object.</p>
  
  <pre><code>class MyBizLogic
  {
      private $dispatcher;
  
      public function __construct(EventDispatcher $dispatcher)
      {
          $this-&gt;dispatcher = $dispatcher;
      }
  
      public function doSomething()
      {
          $event = new MyCustomEvent();
          $dispatcher = $this-&gt;dispatcher-&gt;dispatch('my_custom_event', $event);
          if ($event-&gt;allowAction) {
              // do action
          } else {
              // do something else
          }
      }
  }
  </code></pre>
  
  <p>How can I unit test <code>doSomething</code>? I need a way to control the properties of the event object, but the event object is not a dependency I can mock. It's created within the method I'm testing.</p>
  
  <p>I don't think this is a design smell, since this is how imagine most developers dispatch events. What can I do here to properly test the different outcomes that <code>doSomething</code> should deal with?</p>