当我想在Laravel 5网站上运行PHPUnit测试时,我收到了错误消息。你能给我一个提示吗?已经更新了composer和phpunit包。
PHPUnit 5.2.12 by Sebastian Bergmann and contributors.
Starting test 'Warning'.
W
Starting test 'ExampleTest::testEncryptionIsIntelligent'.
PHP Fatal error: Call to a member function getContent() on null in /var/www/hu.testsite/vendor/laravel/framework/src/Illuminate/Foundation/Testing/InteractsWithPages.php on line 187
[Symfony\Component\Debug\Exception\FatalErrorException]
Call to a member function getContent() on null
这是我的测试文件:
<?
class ExampleTest extends TestCase
{
/**
* My test implementation
*/
public function testEncryptionIsIntelligent()
{
$this->see('Laravel 5');
$this->visit('/');
$this->visit('/auth/login');
$this->type('test.admin@testsite.hu', 'email');
$this->type('test', 'password');
$this->press('');
$this->seePageIs('/admin');
$this->see('Welcome to the dashboard');
$this->visit('/');
}
}
以下是安装的作曲家包:
barryvdh/elfinder-flysystem-driver v0.1.4 A Flysystem Driver for elFinder
barryvdh/laravel-debugbar v2.2.0 PHP Debugbar integration for Laravel
barryvdh/laravel-elfinder v0.3.6 A Laravel Package to integrate elFinder 2
behat/behat v3.0.15 Scenario-oriented BDD framework for PHP 5.3
behat/gherkin v4.4.1 Gherkin DSL parser for PHP 5.3
behat/mink v1.7.1 Browser controller/emulator abstraction for PHP
behat/mink-browserkit-driver v1.3.2 Symfony2 BrowserKit driver for Mink framework
behat/mink-extension v2.2 Mink extension for Behat
behat/mink-goutte-driver v1.2.1 Goutte driver for Mink framework
behat/mink-selenium2-driver v1.3.1 Selenium2 (WebDriver) driver for Mink framework
behat/transliterator v1.1.0 String transliterator
classpreloader/classpreloader 3.0.0 Helps class loading performance by generating a single PHP file containing all of the autoloaded files for a specific use case
danielstjules/stringy 1.10.0 A string manipulation library with multibyte support
davejamesmiller/laravel-breadcrumbs 3.0.0 A simple Laravel-style way to create breadcrumbs in Laravel 4+.
dnoegel/php-xdg-base-dir 0.1 implementation of xdg base directory specification for php
doctrine/inflector v1.1.0 Common String Manipulations with regard to casing and singular/plural rules.
doctrine/instantiator 1.0.5 A small, lightweight utility to instantiate objects in PHP without invoking their constructors
fabpot/goutte v3.1.2 A simple PHP Web Scraper
fzaninotto/faker v1.5.0 Faker is a PHP library that generates fake data for you.
greggilbert/recaptcha 2.1.1 reCAPTCHA Validator for Laravel 5
guzzlehttp/guzzle 6.2.0 Guzzle is a PHP HTTP client library
guzzlehttp/promises 1.1.0 Guzzle promises library
guzzlehttp/psr7 1.2.3 PSR-7 message implementation
hamcrest/hamcrest-php v1.2.2 This is the PHP port of Hamcrest Matchers
illuminate/html v5.0.0
instaclick/php-webdriver 1.4.3 PHP WebDriver for Selenium 2
intervention/image 2.3.6 Image handling and manipulation library with support for Laravel integration
jakub-onderka/php-console-color 0.1
jakub-onderka/php-console-highlighter v0.3.2
jeremeamia/SuperClosure 2.2.0 Serialize Closure objects, including their context and binding
laracasts/behat-laravel-extension 1.0 Laravel extension for Behat
laravel/framework v5.1.31 The Laravel Framework.
league/flysystem 1.0.20 Filesystem abstraction: Many filesystems, one API.
maatwebsite/excel v2.1.2 An eloquent way of importing and exporting Excel and CSV in Laravel 4 with the power of PHPExcel
maximebf/debugbar v1.11.1 Debug bar in the browser for php application
mockery/mockery 0.9.4 Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing...
monolog/monolog 1.18.1 Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/cron-expression v1.1.0 CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due
myclabs/deep-copy 1.5.0 Create deep copies (clones) of your objects
nesbot/carbon 1.21.0 A simple API extension for DateTime.
nikic/php-parser v2.0.1 A PHP parser written in PHP
paragonie/random_compat v1.4.1 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
phpdocumentor/reflection-docblock 2.0.4
phpoffice/phpexcel 1.8.1 PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine
phpspec/php-diff v1.0.2 A comprehensive library for generating differences between two hashable objects (strings or arrays).
phpspec/phpspec 2.5.0 Specification-oriented BDD framework for PHP 5.3+
phpspec/prophecy v1.6.0 Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage 3.3.0 Library that provides collection, processing, and rendering functionality for PHP code coverage information.
phpunit/php-file-iterator 1.4.1 FilterIterator implementation that filters files based on a list of suffixes.
phpunit/php-text-template 1.2.1 Simple template engine.
phpunit/php-timer 1.0.7 Utility class for timing
phpunit/php-token-stream 1.4.8 Wrapper around PHP's tokenizer extension.
phpunit/phpunit 5.2.12 The PHP Unit Testing framework.
phpunit/phpunit-mock-objects 3.1.0 Mock Object library for PHPUnit
psr/http-message 1.0 Common interface for HTTP messages
psr/log 1.0.0 Common interface for logging libraries
psy/psysh v0.7.2 An interactive shell for modern PHP.
sebastian/code-unit-reverse-lookup 1.0.0 Looks up which function or method a line of code belongs to
sebastian/comparator 1.2.0 Provides the functionality to compare PHP values for equality
sebastian/diff 1.4.1 Diff implementation
sebastian/environment 1.3.5 Provides functionality to handle HHVM/PHP environments
sebastian/exporter 1.2.1 Provides the functionality to export PHP variables for visualization
sebastian/global-state 1.1.1 Snapshotting of global state
sebastian/recursion-context 1.0.2 Provides functionality to recursively process PHP variables
sebastian/resource-operations 1.0.0 Provides a list of PHP built-in functions that operate on resources
sebastian/version 1.0.6 Library that helps with managing the version number of Git-hosted PHP projects
studio-42/elfinder 2.1.9 File manager for web
swiftmailer/swiftmailer v5.4.1 Swiftmailer, free feature-rich PHP mailer
symfony/browser-kit v2.8.3 Symfony BrowserKit Component
symfony/class-loader v2.8.3 Symfony ClassLoader Component
symfony/config v2.8.3 Symfony Config Component
symfony/console v2.7.10 Symfony Console Component
symfony/css-selector v2.7.10 Symfony CssSelector Component
symfony/debug v2.7.10 Symfony Debug Component
symfony/dependency-injection v2.8.3 Symfony DependencyInjection Component
symfony/dom-crawler v2.7.10 Symfony DomCrawler Component
symfony/event-dispatcher v2.8.3 Symfony EventDispatcher Component
symfony/filesystem v3.0.3 Symfony Filesystem Component
symfony/finder v2.7.10 Symfony Finder Component
symfony/http-foundation v2.7.10 Symfony HttpFoundation Component
symfony/http-kernel v2.7.10 Symfony HttpKernel Component
symfony/polyfill-apcu v1.1.1 Symfony polyfill backporting apcu_* functions to lower PHP versions
symfony/polyfill-php56 v1.1.1 Symfony polyfill backporting some PHP 5.6+ features to lower PHP versions
symfony/polyfill-util v1.1.1 Symfony utilities for portability of PHP codes
symfony/process v2.7.10 Symfony Process Component
symfony/routing v2.7.10 Symfony Routing Component
symfony/translation v2.7.10 Symfony Translation Component
symfony/var-dumper v2.7.10 Symfony mechanism for exploring and dumping PHP variables
symfony/yaml v2.8.3 Symfony Yaml Component
tijsverkoyen/css-to-inline-styles 1.5.5 CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is v...
vlucas/phpdotenv v1.1.1 Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.
watson/sitemap 2.0.12 Generate Google Sitemaps in Laravel 4/5
帮助会很感激。
答案 0 :(得分:2)
改变这个:
$this->see('Laravel 5');
$this->visit('/');
到
$this->visit('/')
->see('Laravel 5');
您正在尝试首先检查laravel不知道在哪里检查的内容。首先访问页面,然后检查内容。
我会将这些行链接如下:
$this->visit('/')
->see('Laravel 5')
->visit('/auth/login')
->type('test.admin@testsite.hu', 'email')
->type('test', 'password')
->press('')
->seePageIs('/admin')
->visit('/')
->see('Welcome to the dashboard');