Php 从5.0升级到5.1-现在模拟测试获胜';不及格

Php 从5.0升级到5.1-现在模拟测试获胜';不及格,php,laravel-5,phpunit,laravel-5.1,mockery,Php,Laravel 5,Phpunit,Laravel 5.1,Mockery,我想知道是否有人能帮我解决这个问题。在Laravel 5.0下,我的所有测试都运行良好,但自从今天早上更新到5.1(.17)后,任何使用mockry的测试现在都会失败,类似于: vagrant@homestead:~/Code/nps$ php phpunit.phar tests/Workers/AutomatedEmailerWorkerTest.php PHPUnit 4.6.2 by Sebastian Bergmann and contributors. Configuration

我想知道是否有人能帮我解决这个问题。在Laravel 5.0下,我的所有测试都运行良好,但自从今天早上更新到5.1(.17)后,任何使用
mockry
的测试现在都会失败,类似于:

vagrant@homestead:~/Code/nps$ php phpunit.phar tests/Workers/AutomatedEmailerWorkerTest.php
PHPUnit 4.6.2 by Sebastian Bergmann and contributors.

Configuration read from /home/vagrant/Code/nps/phpunit.xml.dist

E

Time: 16.27 seconds, Memory: 56.50Mb

There was 1 error:

1) TRP\Nps\Tests\Workers\AutomatedEmailerWorkerTest::testEmail
Mockery\Exception\InvalidCountException: Method connected() from Mockery_0_Illuminate_Queue_QueueManager should be called
 exactly 1 times but called 4 times.
以及有关的测试:

class AutomatedEmailerWorkerTest extends TestCase
{
    private $autoWorker;
    private $returned;
    private $payload = [
        'content' => 'PHPUnit Test Email Content',
        'subject' => 'PHPUnit Test Email Subject',
        'blade_template' => 'emails.interaction',
        'closed_loop_step_id' => '1',
    ];


    public function testEmail()
    {
        Mail::pretend(false);
        self::pretendQueue();

        $mock = Mockery::mock(
            'Swift_Mailer[send]',
            [
                Mockery::mock('Swift_Transport')->shouldIgnoreMissing()
            ]
        );

        Mail::setSwiftMailer($mock);
        $globalMessage = null;

        $mock->shouldReceive('send')->atLeast()->times(1)
            ->andReturnUsing(function ($msg) use (&$globalMessage) {
                $globalMessage = $msg;
            });

        $response = $this->call(
            'POST',
            '/api/v1/automatedemail',
            $this->payload,
            [],
            [],
            ['HTTP_AUTHORIZATION' => 'Bearer '.$this->getAuthToken()],
            []
        );

        $this->assertEquals($this->payload['subject'], $globalMessage->getSubject());
        $this->assertContains($this->payload['content'], $globalMessage->getBody());
        $this->assertNotEmpty($globalMessage->getTo());
        $this->assertNotEmpty($globalMessage->getFrom());
    }
}

在过去的一个小时里,我一直把头撞在屏幕上,我想不出来,这肯定是件愚蠢的事情……

由于有些测试不关心队列,我设法通过模仿每个测试用例中的
队列::推送
队列::连接的
方法来解决这个问题。像这样:

\Queue::shouldReceive('push')->atLeast();
\Queue::shouldReceive('connected')->atLeast();

以防万一,它会帮助人们摆脱困境,因为这是一个令人头痛的问题

由于一些测试不关心队列,因此我在每个需要它的测试用例中模拟了
Queue::push
Queue::connected
方法,从而绕过了这个问题。像这样:

\Queue::shouldReceive('push')->atLeast();
\Queue::shouldReceive('connected')->atLeast();
以防万一,它会帮助人们摆脱困境,因为这是一个令人头痛的问题