分类目录归档:Laravel

laravel表单验证中使用中文提示

/**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'title' => 'required|min:3',
            'content' => 'required',
            'published_at' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'required' => ':attribute是必需的',
            'min' => ':attribute最少:min位',
        ];
    }
0

phpunit基础写法

<?php
/**
 * Created by PhpStorm.
 * User: Connie
 * Date: 2019/3/30
 * Time: 16:20
 */

namespace Tests\Unit;


use App\Order;
use App\Product;
use Tests\TestCase;

class OrderTest extends TestCase
{
    /** @var Order $order */
    protected $order;
    protected $iWatch;
    protected $macBook;

    public function setUp()
    {
        $this->order = new Order();
        $this->iWatch = new Product();
        $this->iWatch->setName('i watch');
        $this->iWatch->setPrice(5000);
        $this->macBook = new Product();
        $this->macBook->setName('macBook Pro');
        $this->macBook->setPrice(12000);

        $this->order->add($this->iWatch);
        $this->order->add($this->macBook);
    }

    /** @test */
    public function order_can_consists_products()
    {
        $this->assertEquals(2, count($this->order->getProducts()));
    }

    /** @test */
    public function we_can_get_price_from_an_order()
    {
        $this->assertEquals(17000,$this->order->total());
    }

}

0