私はLaravel 5ベースのウェブサイトを持っていると私はそれにPHPUnitのテストを実行したい:Laravel 5とPHPUnitのテストがあるため、未定義のインデックスで失敗:REMOTE_ADDR
:そのために、私は私のテストフォルダに以下のファイルを持っていますExampleTest.php
<?php
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
* A basic functional test example.
*
* @return void
*/
public function testBasicExample()
{
$this->visit('/')
->see('Laravel 5');
}
}
NewTest.php
<?
class Example22Test extends TestCase
{
/**
* My test implementation
*/
public function testEncryptionIsIntelligent()
{
$this->visit('/')
->see('Laravel 5')
->visit('/auth/login')
->type('[email protected]', 'email')
->type('[email protected]', 'email')
->type('admin', 'password')
->press('')
->seePageIs('/admin')
->see('Welcome to the dashboard')
->visit('/');
}
}
TestCase.php
<?php
#class TestCase extends Illuminate\Foundation\Testing\TestCase
abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
}
PHPUnit 5.2.12 by Sebastian Bergmann and contributors.
Starting test 'ExampleTest::testBasicExample'.
.
Starting test 'Example22Test::testEncryptionIsIntelligent'.
F 2/2 (100%)
Time: 433 ms, Memory: 21.25Mb
There was 1 failure:
1) Example22Test::testEncryptionIsIntelligent
A request to [http://localhost/admin] failed. Received status code [500].
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:165
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:63
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:109
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:63
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:85
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:688
/var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php:675
/var/www/hu.testsite/tests/NewTest.php:17
Caused by
exception 'ErrorException' with message 'Undefined index: REMOTE_ADDR' in /var/www/hu.testsite/app/Http/Middleware/QueryLogAfterMiddleware.php:88
Stack trace:
#0 /var/www/hu.testsite/app/Http/Middleware/QueryLogAfterMiddleware.php(88): Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined index...', '/var/www/hu.bit...', 88, Array)
#1 /var/www/hu.testsite/app/Http/Middleware/QueryLogAfterMiddleware.php(23): App\Http\Middleware\QueryLogAfterMiddleware->getIp()
#2 [internal function]: App\Http\Middleware\QueryLogAfterMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#3 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#4 /var/www/hu.testsite/app/Http/Middleware/QueryLogBeforeMiddleware.php(18): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#5 [internal function]: App\Http\Middleware\QueryLogBeforeMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#6 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#7 /var/www/hu.testsite/app/Http/Middleware/AuthenticateAdmin.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#8 [internal function]: App\Http\Middleware\AuthenticateAdmin->handle(Object(Illuminate\Http\Request), Object(Closure))
#9 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#10 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#11 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#12 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Routing/Router.php(710): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#13 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Routing/Router.php(675): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#14 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Routing/Router.php(635): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
#15 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(236): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#16 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#17 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(139): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#18 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#19 [internal function]: Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
#20 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#21 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#22 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#23 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#24 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(62): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#25 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
#26 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#27 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#28 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
#29 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#30 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(59): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#31 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
#32 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#33 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#34 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
#35 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#36 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#37 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#38 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(122): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#39 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(87): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
#40 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/CrawlerTrait.php(394): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
#41 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php(61): Illuminate\Foundation\Testing\TestCase->call('GET', 'http://localhos...', Array, Array, Array)
#42 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php(109): Illuminate\Foundation\Testing\TestCase->makeRequest('GET', 'http://localhos...')
#43 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php(63): Illuminate\Foundation\Testing\TestCase->followRedirects()
#44 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php(85): Illuminate\Foundation\Testing\TestCase->makeRequest('POST', 'http://localhos...', Array, Array, Array)
#45 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php(688): Illuminate\Foundation\Testing\TestCase->makeRequestUsingForm(Object(Symfony\Component\DomCrawler\Form), Array)
#46 /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php(675): Illuminate\Foundation\Testing\TestCase->submitForm('', Array, Array)
#47 /var/www/hu.testsite/tests/NewTest.php(17): Illuminate\Foundation\Testing\TestCase->press('')
#48 [internal function]: Example22Test->testEncryptionIsIntelligent()
#49 /var/www/hu.testsite/vendor/phpunit/phpunit/src/Framework/TestCase.php(984): ReflectionMethod->invokeArgs(Object(Example22Test), Array)
#50 /var/www/hu.testsite/vendor/phpunit/phpunit/src/Framework/TestCase.php(844): PHPUnit_Framework_TestCase->runTest()
#51 /var/www/hu.testsite/vendor/phpunit/phpunit/src/Framework/TestResult.php(686): PHPUnit_Framework_TestCase->runBare()
#52 /var/www/hu.testsite/vendor/phpunit/phpunit/src/Framework/TestCase.php(800): PHPUnit_Framework_TestResult->run(Object(Example22Test))
#53 /var/www/hu.testsite/vendor/phpunit/phpunit/src/Framework/TestSuite.php(747): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult))
#54 /var/www/hu.testsite/vendor/phpunit/phpunit/src/Framework/TestSuite.php(747): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#55 /var/www/hu.testsite/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(436): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))
#56 /var/www/hu.testsite/vendor/phpunit/phpunit/src/TextUI/Command.php(158): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)
#57 /var/www/hu.testsite/vendor/phpunit/phpunit/src/TextUI/Command.php(109): PHPUnit_TextUI_Command->run(Array, true)
#58 /var/www/hu.testsite/vendor/phpunit/phpunit/phpunit(47): PHPUnit_TextUI_Command::main()
#59 {main}
FAILURES!
Tests: 2, Assertions: 6, Failures: 1.
は、あなたがこのようなエラーを見たことがあり、またはあなたは私のテストは失敗になり、問題を見ることができます:
そしてここでは、PHPUnitのテストのために私の結果ですか?