Php 在单元测试中显示两个字符串的错误相等

Php 在单元测试中显示两个字符串的错误相等,php,laravel,unit-testing,Php,Laravel,Unit Testing,我已经创建了一个小型的Laravel项目,我正在我的项目上应用单元测试。当我在函数中填写错误的凭证时,它不会重定向到登录页面,并在终端上显示错误,表示断言两个字符串相等失败。这是我的密码 $credentials = [ 'email' => 'test@gmail.com', 'password' => 'wrongcode' ]; $this->post('/login', $credentials)->assertRedirect('/login'

我已经创建了一个小型的Laravel项目,我正在我的项目上应用单元测试。当我在函数中填写错误的凭证时,它不会重定向到登录页面,并在终端上显示错误,表示断言两个字符串相等失败。这是我的密码

$credentials = [
    'email' => 'test@gmail.com',
    'password' => 'wrongcode'
];

$this->post('/login', $credentials)->assertRedirect('/login');
但是,当我将
assertRedirect('/login')
更改为
assertRedirect('/')
时,它可以正常工作

$credentials = [
    'email' => 'test1234@gmail.com',
    'password' => '98756412'
];

$this->post('/login', $credentials)->assertRedirect('/');

assertRedirect检查两个字符串,其中一个是方法的参数,第二个是重定向路径。看起来一切正常。你们写了一个测试,测试失败了,你们有反馈来改进应用程序。在这种情况下,重定向路径与您预期的不同

对于下面这样的单个场景,应该有两种不同的方法

public function testCorrectCredential() {

  $credentials = [
    'email' => 'test1234@gmail.com',
    'password' => '98756412'
  ];

   $this->post('/login', $credentials)->assertRedirect('/');
}

public function testInCorrectCredential() {

      $credentials = [
        'email' => 'incorrect@gmail.com',
        'password' => '98756412'
      ];

       $this->post('/login', $credentials)->assertRedirect('/incorrect-url');
    }