如何从VSCode在Docker容器上运行更好的phpunit [英] Howto run better phpunit on a docker container from VSCode

查看:211
本文介绍了如何从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:-

OCI运行时exec失败:exec失败:container_linux.go:346:启动容器进程导致"exec格式错误":未知终端进程" C:\ Windows \ System32 \ cmd.exe/d/c docker exec laraboard_php_1/var/www/html/vendor/bin/phpunit.bat/var/www/html/tests/Feature/ThreadsT​​est.php --filter'^.* :: a_user_can_browse_threads'"终止,退出代码:126.

OCI runtime exec failed: exec failed: container_linux.go:346: starting container process caused "exec format error": unknown The terminal process "C:\Windows\System32\cmd.exe /d /c docker exec laraboard_php_1 /var/www/html/vendor/bin/phpunit.bat /var/www/html/tests/Feature/ThreadsTest.php --filter '^.*::a_user_can_browse_threads'" terminated with exit code: 126.

我要去哪里错了?

推荐答案

这里的问题可能是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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆