我曾经使用 PHPUnit 的方法设置来为我的测试方法创建一个实例。但是在 Laravel 5.8 中我做不到
我已经尝试了两种方法,它的工作原理是为每个方法创建一个实例,如下所示。
这有效:
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Service\MyService;
class MyServiceTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function testInstanceOf()
{
$myService = new MyService;
$this->assertInstanceOf( 'App\Service\MyService' , $myService );
}
}
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<?php
namespace Tests\Unit;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\Service\MyService;
class MyServiceTest extends TestCase
{
private $instance;
function setUp(){
$this->instance = new MyService;
}
/**
* A …Run Code Online (Sandbox Code Playgroud) 我想在我的 Laravel 项目中安装 Chart.js。使用 npm install(Webpack 的配置),并查看我的索引页和一些 Chart.js 示例。在我第一次尝试时,我在浏览器中收到此错误。也许我没有正确配置 webpack?
未捕获的引用错误:图表未定义于(索引):134
因此,我复制并粘贴了在 Chart.js 文档集成中找到的此要求。
require(['path/to/chartjs/dist/Chart.min.js'], function(Chart){
var myChart = new Chart(ctx, {...});
});
Run Code Online (Sandbox Code Playgroud)
我在 上遇到了这个错误npm run dev。
./resources/js/app.js 中的错误模块构建失败(来自 ./node_modules/babel-loader/lib/index.js):语法错误:/home/sa/laravelproject/resources/js/app.js:意外的标记(37:37)
35 | 35 36 | 36 需要(['路径/到/chartjs/dist/Chart.min.js'],函数(图表){
37 | 37 var myChart = new Chart(ctx, {...}); | ^ 38 | });