本文介绍了如何从VSCode在Docker容器上运行更好的phpunit的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用更好的phpunit扩展从vs代码在docker容器上运行php单元测试,但是我无法使其正常工作.

I am trying to run php unit tests on a docker container from vs code using the better phpunit extension, but I cannot get it to work.

我到目前为止有什么:-

what I have so far:-

docker-compose.yml:-

docker-compose.yml:-

version: '3.1'

services:
    php:
        build:
            context: .
            dockerfile: .docker/Dockerfile
        image: laraboard
        ports:
            - 8000:80
        restart: always
        volumes:
            - .:/var/www/html
        networks:
            - laraboard
    mysql:
        image: mysql:8.0
        volumes:
            - db_data:/var/lib/mysql
        restart: always
        ports:
            - 3306:3306
        environment:
            MYSQL_DATABASE: laraboard
            MYSQL_USER: root
            MYSQL_PASSWORD: password
            MYSQL_ROOT_PASSWORD: password
        networks:
            - laraboard
    phpmyadmin:
        depends_on:
            - mysql
        image: phpmyadmin/phpmyadmin
        restart: always
        ports:
            - 8001:80
        environment:
            PMA_HOST: mysql
            MYSQL_ROOT_PASSWORD: password 
        networks:
            - laraboard
networks:
    laraboard:
volumes:
    db_data:

settings.json:-

settings.json:-

"better-phpunit.docker.enable": true,
    "better-phpunit.docker.command": "docker exec laraboard_php_1",
    "better-phpunit.docker.paths": {
        "c:/Users/Chris/Web/laraboard": "/var/www/html"
    }

ThreadTest.php:-

ThreadTest.php:-

<?php

namespace Tests\Feature;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class ThreadsTest extends TestCase
{
    /** @test */
    public function a_user_can_browse_threads()
    {
        $response = $this->get('/threads');

        $response->assertStatus(200);
    }
}

使用此设置,我会收到错误消息:-

with this setup I get error:-

我要去哪里错了?

推荐答案

这里的问题可能是phpunit可执行文件的路径错误.它应该是/var/www/html/vendor/bin/phpunit 而不是/var/www/html/vendor/bin/phpunit.bat

The problem here might be, that the path to the phpunit executable is wrong. It should be /var/www/html/vendor/bin/phpunit instead of /var/www/html/vendor/bin/phpunit.bat

这篇关于如何从VSCode在Docker容器上运行更好的phpunit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 09:55