title: Php unit test when using Promise
body: <p>I use the Promise by AWS SDK to save many files to S3 bucket. I fail to build the unit test for that.</p>
  
  <p>My functions </p>
  
  <pre><code>function save($item, array $layers)
  {
      $promises = [];
      foreach ($layers as $key =&gt; $layer) {
          $filename = $this-&gt;getS3Filename($item, $key);
          $promise = $this-&gt;s3Client-&gt;uploadAsync(
          );
          $promise = $promise-&gt;then(
              function () {
              },
              function ($reason) use ($item) {
                  $this-&gt;logger-&gt;error("The promise to store file on S3 was rejected with {$reason} for item {$item-&gt;getId()}");
              }
          );
          $promises[] = $promise;
      }
      all($promises)-&gt;wait();
  }
  </code></pre>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>GuzzleHttp\Promise\RejectionException : The promise was rejected with
    reason: Invoking the wait callback did not resolve the promise 
    /Users/sela/PhpstormProjects/ziggy/vendor/guzzlehttp/promises/src/functions.php:112
    /Users/sela/PhpstormProjects/ziggy/vendor/guzzlehttp/promises/src/Promise.php:75</p>
  </blockquote>
  
  <p>when running my <code>phpunit</code></p>
  
  <p>The following is my unit test code:</p>
  
  <pre><code>protected function setUp()
  {
      $this-&gt;logger = $this-&gt;createMock(LoggerInterface::class);
  
      parent::setUp();
  }
  
  public function testSaveBatch()
  {
      $this-&gt;logger
          -&gt;expects($this-&gt;once())
          -&gt;method('error');
      $this-&gt;s3Client = $this-&gt;getMockBuilder(S3ClientInterface::class)
          -&gt;setMethods(['uploadAsync'])
          -&gt;disableOriginalConstructor()
          -&gt;getMockForAbstractClass();
      $promise = $this-&gt;createMock(PromiseInterface::class);
      $promise
          -&gt;expects($this-&gt;once())
          -&gt;method('then')
          -&gt;will($this-&gt;returnCallback([$this, 'promiseCallback']));
  
      $this-&gt;s3Client
          -&gt;expects($this-&gt;once())
          -&gt;method('uploadAsync')
          -&gt;willReturn(
              $promise
          );
  
      $object = new Object(
      );
      $layers = ['123' =&gt; ''];
      $object-&gt;save($item, $layers);
  }
  
  /**
   * @return null|MockObject
   */
  public function promiseCallback()
  {
      $promise = $this-&gt;createMock(PromiseInterface::class);
  
      $fulfilledPromise = $this-&gt;createMock(FulfilledPromise::class);
      $fulfilledPromise
          -&gt;expects($this-&gt;once())
          -&gt;method('resolve')
          -&gt;will($this-&gt;returnCallback($promise))
      ;
  
      return $fulfilledPromise;
  
  }
  </code></pre>