我对单元测试很陌生,我想尝试测试我的登录页面,我的目标是:-> 如果它在数据库中匹配-> 重定向到路由“/”-> 如果不是-> 重定向到路由“ /登录'
<?php
namespace Tests\Feature;
use App\Domain\Core\Models\User;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class userTest extends TestCase
{
use DatabaseMigrations;
/**
* A basic test example.
*
* @return void
*/
public function testLoginTrue()
{
$credential = [
'email' => 'user@ad.com',
'password' => 'user'
];
$this->post('login',$credential)->assertRedirect('/');
}
public function testLoginFalse()
{
$credential = [
'email' => 'user@ad.com',
'password' => 'usera'
];
$this->post('login',$credential)->assertRedirect('/login');
}
}
Run Code Online (Sandbox Code Playgroud)
当我在 TestLoginTrue 上测试时,它成功返回到 '/' 但是当我尝试 TestLoginFalse …
我有一个这样的查询
SELECT
totalvolume = SUM(volume),
totalusage = SUM(usage),
percentage = CAST(SUM(usage) * 100 / SUM(volume) as decimal (10,2)),
YEAR
FROM
table1
Run Code Online (Sandbox Code Playgroud)
我得到如下表
|totalvolume|totalusage|percentage|Year
|--------------------------------------
| 100 | 50 | 50.00 |2016
| 200 | 50 | 25.00 |2015
Run Code Online (Sandbox Code Playgroud)
我的目标是使用以下命令使列表变得像这样PIVOT:
|Type |2015 |2016 |
|------------------------ |
| totalvolume| 200 | 100 |
| totalusage | 50 | 50 |
| percentage |25.00|50.00 |
Run Code Online (Sandbox Code Playgroud)
所以我决定首先使用 a) 创建此表UNPIVOT:
Type | Value | year
-------------------
totalvolume |100 |2016
totalusage |50 …Run Code Online (Sandbox Code Playgroud)