国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

??
??? ?? ??? ???
通過POST數(shù)據(jù)創(chuàng)建carousel
? PHP ????? Laravel Laravel? ??? ?? ???: ??? ?? ??(?? ??)

Laravel? ??? ?? ???: ??? ?? ??(?? ??)

Aug 08, 2018 pm 02:17 PM
laravel ?? ??? ??? ?? ??

? ??? ??? Laravel? ?? ???: ??? ?? ??(?? ??)? ?? ?????. ??? ??? ???? ??? ? ??? ????. .

??? ?? ??? ???

?????? ?? ???? ??? ? ?? ??? ?? ???? ?? ???? ???? ??? ?????. ?????? ???. ? ???? Admin ? Front ??????? ???? ?? ??? ???? ????? ??? ???? ?????. AdminFront來分離管理后臺的測試和前端頁面的測試。

現(xiàn)在讓我們專注于管理后臺carousel的CRUD功能測試。在test/Feature目錄里添加CarouselFeatureTest ?類。

<?php
namespace Tests\Feature\Admin\Carousels;
use Tests\TestCase;
class CarouselFeatureTest extends TestCase
{
    /** @test */
    public function it_can_show_the_create_carousel_page()
    {
       $employee = factory(User::class)->create();
????????$this
????????????->actingAs($employee,?'admin')
????????????->get(route('admin.carousel.create'))
????????????->assertStatus(200)
????????????->assertSee('Title')
????????????->assertSee('Subtitle')
????????????->assertSee('Link')
????????????->assertSee('Link?Text')
????????????->assertSee('Image');
????}
}

我們來分析一下上面的代碼。

  • 我們需要->actingAs()方法來通過用戶認證中間件并且模擬admin用戶(如果項目中沒有進行使用認證看守器則不需要這一步)。

  • 然后我們通過route()取出了創(chuàng)建carousel的頁面。

  • 斷言響應的HTTP狀態(tài)碼為200

  • 最后斷言會在頁面上看到的文本值。

運行phpunit看看會發(fā)生什么。

PHPUnit?6.5.7?by?Sebastian?Bergmann?and?contributors.
E???????????????????????????????????????????????????????????????????1?/?1?(100%)
Time:?920?ms,?Memory:?26.00MB
There?was?1?error:
1)?Tests\Feature\Admin\Carousels\CarouselFeatureTest::it_can_show_the_create_carousel_page
InvalidArgumentException:?Route?[admin.carousel.create]?not?defined.

出錯就對了。我們還沒有在web.php這個路由文件中定義路由,所以將會出現(xiàn)上面的錯誤。讓我們定義這個路由。

<?php
Route::namespace(&#39;Admin&#39;)->group(function?()?{
????Route::resource('carousel',?'Carousels\CarouselController');
});

分析:

  • 在我的app/Http/Controllers目錄中還有其他目錄歸置文件和文件夾。我有Admin, FrontAuth這幾個目錄。

  • Admin這個命名空間中還有Carousels文件夾,在這個文件夾中是CarouselController.php文件。

在終端中運行中運行如下命令來創(chuàng)建控制器

php?artisan?make:controller?--resource?Admin/Carousels/CarouselController

定義路由、創(chuàng)建好Controller之后,再次運行phpunit

PHPUnit?6.5.7?by?Sebastian?Bergmann?and?contributors.
F???????????????????????????????????????????????????????????????????1?/?1?(100%)
Time:?987?ms,?Memory:?28.00MB
There?was?1?failure:
1)?Tests\Feature\Admin\Carousels\CarouselFeatureTest::it_can_show_the_create_carousel_page
Failed?asserting?that?''?contains?"Title".

起作用了!路由錯誤消失了不過我們遇到了一個新的錯誤,通過新錯誤讓我們想到應該是測試用例服務在響應的UI頁面上找到Title這個單詞。Hmm 好吧,這是應為我們沒有在create方法中返回視圖,讓我們加上返回視圖的代碼。

<?php
namespace App\Http\Controllers\Admin\Carousels;
use App\Http\Controllers\Controller;
class CarouselController extends Controller
{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function create()
    {
        return view(&#39;admin.carousels.create&#39;);
    }
}

視圖文件位于resource/views/admin/carousels/create.blade.php

@extends(&#39;layouts.admin.app&#39;)

@section(&#39;content&#39;)
    <!-- Main content -->
????<section class="content">
????????@include('layouts.errors-and-messages')
????????<p class="box">
????????????<p class="box-body">
????????????????<form action="{{ route(&#39;admin.carousel.store&#39;) }}" method="post" enctype="multipart/form-data">
????????????????????{{?csrf_field()?}}
????????????????????<p class="form-group">
????????????????????????<label for="title">Title</label>
????????????????????????<input type="text" name="title" id="title" class="form-control" placeholder="Title" value="{{ old(&#39;title&#39;) }}">
????????????????????</p>
????????????????????<p class="form-group">
????????????????????????<label for="image">Image</label>
????????????????????????<input type="file" name="image" id="image" class="form-control">
????????????????????</p>
????????????????????<p class="form-group">
????????????????????????<label for="link">Link</label>
????????????????????????<p class="input-group">
????????????????????????????<span class="input-group-addon">http://</span>
????????????????????????????<input type="text" name="link" id="link" class="form-control" placeholder="www.example.com" value="{{ old(&#39;link&#39;) }}">
????????????????????????</p>
????????????????????</p>
????????????????????<p class="btn-group">
????????????????????????<a href="{{ route(&#39;admin.carousel.index&#39;) }}" class="btn btn-default btn-sm">Back</a>
????????????????????????<button type="submit" class="btn btn-primary btn-sm">Create</button>
????????????????????</p>
????????????????</form>
????????????</p>
????????</p>
????</section>
????<!-- /.content -->
@endsection

視圖文件夾中并沒有admincarousels文件夾,所以你需要自己創(chuàng)建它們。

創(chuàng)建好blade視圖文件后再次運行phpunit

???git:?phpunit?--filter=CarouselFeatureTest::it_can_show_the_create_carousel_page
PHPUnit?6.5.7?by?Sebastian?Bergmann?and?contributors.
.???????????????????????????????????????????????????????????????????1?/?1?(100%)
Time:?810?ms,?Memory:?28.00MB
OK?(1?test,?6?assertions)

Nice,看起來非常好。

現(xiàn)在,如果有人搞亂了你的blade模板,你會馬上知道因為這個測試會執(zhí)行失敗。到Github里去檢查一下到底是誰搞亂模板文件,蛤!

通過POST數(shù)據(jù)創(chuàng)建carousel

現(xiàn)在讓我們測試一下通過頁面里的表單是否能夠創(chuàng)建carousel數(shù)據(jù)。

要創(chuàng)建carousel別忘了先寫測試,沒有捷徑。

<?php
namespace Tests\Feature\Admin\Carousels;
use Tests\TestCase;
class CarouselFeatureTest extends TestCase
{
    /** @test */
    public function it_can_create_the_carousel()
    {
        $file = UploadedFile::fake()->create('image.jpg');
????????$data?=?[
????????????'title'?=>?$this->faker->word,
????????????'link'?=>?$this->faker->url,
????????????'image'?=>?$file,
????????];
??????
????????$employee?=?factory(User::class)->create();
??????
????????$this
????????????->actingAs($employee,?'admin')
????????????->post(route('admin.carousel.store'),?$data)
????????????->assertStatus(302)
????????????->assertRedirect(route('admin.carousel.index'))
????????????->assertSessionHas('message',?'Create?carousel?successful!');
????}
??
????/**?@test?*/
????public?function?it_can_show_the_create_carousel_page()
????{
???????$employee?=?factory(User::class)->create();
????????$this
????????????->actingAs($employee,?'admin')
????????????->get(route('admin.carousel.create'))
????????????->assertStatus(200)
????????????->assertSee('Title')
????????????->assertSee('Subtitle')
????????????->assertSee('Link')
????????????->assertSee('Link?Text')
????????????->assertSee('Image');
????}
}

分析:

  • 我們斷言在創(chuàng)建成功后會重定向到carousel列表頁。

  • 我們還斷言成功設置了Create carousel successful!這個Flash信息

這個測試會執(zhí)行失敗,因為store()方法現(xiàn)在還空著,讓我們用下面的代碼填充它:

<?php
namespace App\Http\Controllers\Admin\Carousels;
use App\Http\Controllers\Controller;
use App\Shop\Carousels\Exceptions\CarouselNotFoundException;
use App\Shop\Carousels\Exceptions\CreateCarouselErrorException;
use App\Shop\Carousels\Exceptions\UpdateCarouselErrorException;
use App\Shop\Carousels\Repositories\CarouselRepository;
use App\Shop\Carousels\Repositories\CarouselRepositoryInterface;
use App\Shop\Carousels\Requests\CreateCarouselRequest;
use App\Shop\Carousels\Requests\UpdateCarouselRequest;
use Illuminate\Http\UploadedFile;
class CarouselController extends Controller
{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function create()
    {
        return view(&#39;admin.carousels.create&#39;);
    }
    /**
     * @param CreateCarouselRequest $request
     * @return \Illuminate\Http\RedirectResponse
     */
    public function store(CreateCarouselRequest $request)
    {
        try {
          
            $data = $request->except('_token');
????????????if?($request->hasFile('image')?&&?$request->file('image')?instanceof?UploadedFile)?{
????????????????$data['src']?=?$request->file('image')->store('carousels',?['disk'?=>?'public']);
????????????}
????????????
????????????$carouselRepo?=?new?CarouselRepository(new?Carousel);
????????????$carouselRepo->createCarousel($data);
??????????
????????????$request->session()->flash('message',?'Create?carousel?successful!');
????????????return?redirect()->route('admin.carousel.index');
????????}?catch?(CreateCarouselErrorException?$e)?{
????????????$request->session()->flash('error',?$e->getMessage());
????????????return?redirect()->back()->withInput();
????????}
????}
}

然后運行phpunit

?? ?? ?? ???? CRUD ?? ???? ???????. test/Feature ????? CarouselFeatureTest ???? ?????.

???git:?phpunit?--filter=CarouselFeatureTest::it_can_create_the_carousel??????????
PHPUnit?6.5.7?by?Sebastian?Bergmann?and?contributors.
.???????????????????????????????????????????????????????????????????1?/?1?(100%)
Time:?993?ms,?Memory:?28.00MB
OK?(1?test,?5?assertions)
? ??? ??? ?????.

phpunit? ???? ?? ?? ????? ?????.

rrreee ???? ?????. ??? ?? web.php? ??? ???? ??? ??? ?? ?? ??? ?????. ? ??? ??? ?????. rrreee

??:


  • ? app/Http/Controllers ????? ????. ??? ??? ???? ?? ???????. Admin, Front ? Auth ????? ????.
  • #????#Admin ???????? Carousels ??? ??, ? ???? CarouselController? ????. php ??. #????#
#????#????? ????? ????? ?? ???? ????? #????#rrreee#????#???? ???? ????? ??? ? ?? ? ????? phpunit#????#rrreee#????# ?????! ??? ??? ????? ??? ??? ???? ??? ?? ???? ?? UI ????? ????? ??? ????? ??????. ? ????. create ????? ?? ???? ??? ?????. ?? ???? ??? ??? ?????. #????#rrreee#????#? ??? resource/views/admin/carousels/create.blade.php? ????.#????#rrreee#????#? ???? ?? ?? admin ? carousels ??? ???? ?? ???? ???. #????##????#???? ? ??? ??? ? ?? phpunit? ??? ???. #????#rrreee#????#???, ?? ?? ????. #????##????#?? ???? ???? ???? ????? ???? ????? ?? ? ? ????. Github? ?? ?? ??? ??? ???? ??? ???. #????##????#POST ???? ?? ??? ??#????##????#?? ???? ??? ?? ??? ???? ??? ? ??? ???? ?????. #????##????# ???? ???? ?? ???? ???? ?? ?? ???. ???? ????. #????#rrreee#????#??: #????#
  • #????#??? ??? ?? ???? ????? ??? ? ????? ???? ?????. #????#
  • #????# ?? ??? ??? ??! ??? ???? ????? ?????? ????? #????#
#?? ?? # store() ???? ??? ?? ?? ??? ? ???? ?????. ?? ??? ???????. #????#rrreee#????#?? ?? phpunit code>? ?????. #????#rrreee#????#?? ???? ???? ??? ? ?? ?? ?? ???? ???? ??? ??? ???. #????##????# ?? ?? ??: #????##????##????#Nginx ??? ???? ?????? nginx ??? ??? ? ??? ???? ?#????##????##????##????# Laravel? ??? ??? ?? ??(??)#????##????##????## ???? #laravel5.5 ??????? ? ? ???? ???? ??(?? ??) #????##????##????##????##????#

? ??? Laravel? ??? ?? ???: ??? ?? ??(?? ??)? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
PHP ???? ?? ??? ???? ?? PHP ?? ?? ?? ??? ?? ?? PHP ???? ?? ??? ???? ?? PHP ?? ?? ?? ??? ?? ?? Jul 25, 2025 pm 08:33 PM

PHP?? ?? ??? ???? ? ?? ?? ??? ????. 1. php.ini? ?? ??? ??; 2. ? ?? (? : Apache? Setenv ?? nginx? FastCGI_Param)? ??????. 3. PHP ?????? putenv () ??? ??????. ? ??? Php.ini? ????? ??? ???? ??? ???? ? ?? ??? ?? ???? ????? ???? Putenv ()? ?? ??? ?????. ?? ???? ?? ?? (? : php.ini ?? ? ?? ??)? ???? ????. ?? ?? ??? ??? ?? ??? ????? ???? ?? ????.

Laravel? ?? ???? ?????? Laravel? ?? ???? ?????? Jul 27, 2025 am 03:54 AM

Laravel? ?? ??? ?? ?? ??? ?? ?? ??? ???? ??? ??????. ?? ???? ?? ??? ????? ? ???? I/O ?? ? ?? ?? ??? ???? ???? ??? ?? ? ????. 1. ?? ????? ?? ? ? ???????? ??? ????? ?? ???? ??????. 2. ??? ? ??? ?? ? ? PhPartisAnconfig? ?? ???????. 3. ?? ??? ??? ??? ???? ?? ?? ?? ???? ???? ????. 4. ?? ?? ??? ???? ?? ??? ??? .env ??? ???? ?? ???????.

PHP ????? ?? ??? ??? ??? ?????? PHP ??? ????? ?? ? CI ?? ?? PHP ????? ?? ??? ??? ??? ?????? PHP ??? ????? ?? ? CI ?? ?? Jul 25, 2025 pm 08:54 PM

PHP ????? ?? ??? ??? ? ??? ??? CI (Continuous Integration) ????? ???? ? ????. 1. DockerFile? ???? ?? ???, ?? ??, ??? ?? ? ?? ??? ???? PHP ??? ?????. 2. Gitlabci? ?? CI/CD ??? ???? .gitlab-ci.yml ??? ?? ??, ??? ? ?? ??? ???? ?? ??, ??? ? ??? ?????. 3. PHPUNIT? ?? ??? ??? ??? ???? ?? ?? ? ???? ???? ????????. 4. Kubernetes? ?? ?? ?? ??? ???? ?? .yaml ??? ?? ?? ??? ?????. 5. Dockerfile ??? ? ??? ??? ??????

PHP ?? ??? ?? ?? ?? ?? PHP ?? ?? ? ?? ?? PHP ?? ??? ?? ?? ?? ?? PHP ?? ?? ? ?? ?? Jul 25, 2025 pm 06:51 PM

??? ?? ??? PHP ???? ?? ?? ??? ???? ?? ???????. RBAC (Role-Based Access Control) ??? ?? ???, ?? ? ??? ???? ??? ?? ?? ? ??? ?????. ?? ???? ??? ?????. 1. ???, ?? ? ??? ? ???? user_roles ? role_permissions? 3 ?? ?? ???; 2. $ user-> can ( 'edit_post')? ?? ???? ?? ?? ??? ?????. 3. ??? ???? ??? ??????. 4. ?? ??? ???? ?? ?? ?? ? ??? ? ???? ???? ?? ??? ? ?? ??? ?????. 5. ??? ??? ?? ?? ???? ?? ???? "??"? ??????.

Laravel Eloquent Scopes? ??????. Laravel Eloquent Scopes? ??????. Jul 26, 2025 am 07:22 AM

Laravel? eloquentscopes? ?? ??? ??? ??? ?????? ?? ?? ??? ????? ?????. 1. ?? ??? ???? ???? ???? ???? Post :: published (); 2. ??? ??? ?? ??? ???? ???? ?? ??? ?? ?? ?? ??? ???? ???? ??? ?????? ??? ???? ???????. 3. ????? ?? ?? ?? ??? ??? ?? ?? ??? ?? ? ? ??? ?? ? ? ?? ?? ??? ?????. 4. ?? ??? ? ??? ?? ???? ? ??? ? ?? ??, ?? ??, ?? ???? ? ?? ?????????.

Laravel?? ??? ??? ??? ??? Laravel?? ??? ??? ??? ??? Jul 26, 2025 am 08:58 AM

CreateAhelpers.phpfileInapp/helperswithCustOmFunctionsikeFormatPrice, isactiveroute, andisAdmin.2.addTheFileTothe "??"sectionOfcomposer.jsonUnderAutoLoad.3.runcomposerDump-AUTOLOADTOMAKETHINGTICTIONSGLOBELYAVAILABLE.4.USETHEHELPERFUNCUNTION

PHP PHP ?? ?? ? ?? ??? ?? ?? ???? ???? ?? PHP PHP ?? ?? ? ?? ??? ?? ?? ???? ???? ?? Jul 25, 2025 pm 08:48 PM

?? ?? ?? : ?? ????? PHP? ?? Error_Log ()? ??? ? ????. ????? ???? ??? ?? ??? ?????? ???? ?? ??? ? ?? ??? ???? ??? ?? ???, ??, ?? ? ?? ? ?? ?? ??? ???? ??? ??????. 2. ??? ?? ?? : ??? ??? ??? ??? ? ??? ?? ??? ??? ?? ??? ??? ??????? ??????. MySQL/PostgreSQL? ???? ??? ? ???? ??????. Elasticsearch Kibana? ? ???/? ???? ?????. ???, ??? ?? ? ??? ? ?? ??? ?? ??????. 3. ?? ? ?? ????? : ??, ???, ?? ? ??? ??? ??????. Kibana? ?? ????? PHP ??? ?? ?? ?????? ???? ???? ?????? ???? ??? ? ?? ??? ??? ? ????.

Laravel ????? ??? ???? ??? ?????? Laravel ????? ??? ???? ??? ?????? Jul 27, 2025 am 03:13 AM

USEMOCKERYFORCUSTOMDENCENTICESBYSETEXPINTIONSWITHSHOULDRECEIVE ()

See all articles