我如何 运行 将所有 model/controller 的 phpunit 放在一个文件中
How do I run the phpunit in a single file for all the model/controller
我遇到了 php 单元的挑战,测试 运行 非常适合用户输入,但无法识别产品功能。我曾尝试删除 运行 产品插入等用户身份验证功能,但它似乎不起作用。
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use \App\Models\Product;
use \App\Models\User;
class LoginTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_user_can_view_a_login_form(){
$response = $this->get('user/signin');
$response->assertStatus(200);
$response->assertViewIs('user.signin');
}
public function test_user_cannot_view_a_login_from_when_authenticated() {
$user = new User([
'email' => 'jobtest@test.com',
'password' => bcrypt($password = 'i-want-this-job'),
]);
if ($user === null) {
$user->save();
}
else{
echo "User exists";
}
$response = $this->post('user/signin', [
'email' => $user->email,
'password' => $password,
]);
$response = $this->actingAs($user)->get('user/signin');
$this->assertAuthenticatedAs($user);
}
**THE PRODUCT METHODS START FROM HERE**
public function user_can_access_home_page() {
$response = $this->get('/');
$response->assertStatus(200);
$response->assertViewIs('/');
}
public function can_user_insert_product() {
$product = new Product([
'imagePath' => 'https://i0.wp.com/ae01.alicdn.com/kf/HLB1V4vwbjLuK1Rjy0Fhq6xpdFXaJ/Elegant-Women-Dresses-Bodycon-Office-Formal-Business-Work-Party-Sheath-Tunic-Pencil-Midi-O-neck-Short.jpg?fit=800%2C800&ssl=1',
'title' => 'Elegant Women Dresses',
'description' => 'Some quick example text to build on the card title and make up the bulk of the content',
'price' => '8',
'quantity' => '3'
]);
$product->save();
if($product) {
echo "Product inserted";
}
$response = $this->post('/', [
'imagePath' => $product->imagePath,
'title' => $product->title,
'description' => $product->description,
'price' => $product->price,
'quantity' => $product->quantity,
]);
$response = assertRedirect('/');
}
}
我也尝试为它创建另一个测试文件,但仍然显示在class“Tests\Feature\Auth\LoginTest”中找不到测试。
而当追加到同一测试文件中时,它将 运行 并忽略产品方法。
还是我需要 运行 php artisan make:test Auth/LoginTest 分别用于用户登录和 运行 php artisan make:test Product/ProductTest 因为不知道为什么用户会工作而产品不会
对于 运行 的 phpunit
测试,它们要么以单词 test
开头,要么具有 @test
注释。您的产品测试不遵循这些规则。
通常的解决方案
public function test_can_user_insert_product(){
或者注解解决
/** @test **/
public function can_user_insert_product
我遇到了 php 单元的挑战,测试 运行 非常适合用户输入,但无法识别产品功能。我曾尝试删除 运行 产品插入等用户身份验证功能,但它似乎不起作用。
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
use \App\Models\Product;
use \App\Models\User;
class LoginTest extends TestCase
{
/**
* A basic feature test example.
*
* @return void
*/
public function test_user_can_view_a_login_form(){
$response = $this->get('user/signin');
$response->assertStatus(200);
$response->assertViewIs('user.signin');
}
public function test_user_cannot_view_a_login_from_when_authenticated() {
$user = new User([
'email' => 'jobtest@test.com',
'password' => bcrypt($password = 'i-want-this-job'),
]);
if ($user === null) {
$user->save();
}
else{
echo "User exists";
}
$response = $this->post('user/signin', [
'email' => $user->email,
'password' => $password,
]);
$response = $this->actingAs($user)->get('user/signin');
$this->assertAuthenticatedAs($user);
}
**THE PRODUCT METHODS START FROM HERE**
public function user_can_access_home_page() {
$response = $this->get('/');
$response->assertStatus(200);
$response->assertViewIs('/');
}
public function can_user_insert_product() {
$product = new Product([
'imagePath' => 'https://i0.wp.com/ae01.alicdn.com/kf/HLB1V4vwbjLuK1Rjy0Fhq6xpdFXaJ/Elegant-Women-Dresses-Bodycon-Office-Formal-Business-Work-Party-Sheath-Tunic-Pencil-Midi-O-neck-Short.jpg?fit=800%2C800&ssl=1',
'title' => 'Elegant Women Dresses',
'description' => 'Some quick example text to build on the card title and make up the bulk of the content',
'price' => '8',
'quantity' => '3'
]);
$product->save();
if($product) {
echo "Product inserted";
}
$response = $this->post('/', [
'imagePath' => $product->imagePath,
'title' => $product->title,
'description' => $product->description,
'price' => $product->price,
'quantity' => $product->quantity,
]);
$response = assertRedirect('/');
}
}
我也尝试为它创建另一个测试文件,但仍然显示在class“Tests\Feature\Auth\LoginTest”中找不到测试。
而当追加到同一测试文件中时,它将 运行 并忽略产品方法。
还是我需要 运行 php artisan make:test Auth/LoginTest 分别用于用户登录和 运行 php artisan make:test Product/ProductTest 因为不知道为什么用户会工作而产品不会
对于 运行 的 phpunit
测试,它们要么以单词 test
开头,要么具有 @test
注释。您的产品测试不遵循这些规则。
通常的解决方案
public function test_can_user_insert_product(){
或者注解解决
/** @test **/
public function can_user_insert_product