Php Docker Laradock Browsertest with Dask:默认测试返回空页 码头工人:19.03.5,建造633a0ea 拉威尔6*

Php Docker Laradock Browsertest with Dask:默认测试返回空页 码头工人:19.03.5,建造633a0ea 拉威尔6*,php,docker,laravel-dusk,laradock,Php,Docker,Laravel Dusk,Laradock,我尝试将我的项目从Vbox移动到DOCKER。目前,这是一个LARAVEL项目。为此,我安装了一个测试项目 看起来工作正常,但是如果我尝试执行默认浏览器测试,测试的响应是一个空页面 黄昏 ... APP_URL=http://localhost:8000 ... tests/Browser/ExampleTest.php <?php class ExampleTest extends DuskTestCase { /** * @return \Facebook\We

我尝试将我的项目从Vbox移动到DOCKER。目前,这是一个LARAVEL项目。为此,我安装了一个测试项目

看起来工作正常,但是如果我尝试执行默认浏览器测试,测试的响应是一个空页面

黄昏

...
APP_URL=http://localhost:8000
...
tests/Browser/ExampleTest.php

<?php

class ExampleTest extends DuskTestCase
{

    /**
     * @return \Facebook\WebDriver\Remote\RemoteWebDriver
     */
    protected function driver()
    {
        $options = (new ChromeOptions)->addArguments([
            '--disable-gpu',
            '--headless',
            '--no-sandbox',
        ]);

        return RemoteWebDriver::create(
            'http://localhost:9515',
            DesiredCapabilities::chrome()->setCapability(ChromeOptions::CAPABILITY, $options)
        );
    }

    /**
     * A basic browser test example.
     *
     * @return void
     */
    public function testBasicExample()
    {
        $this->browse(function (Browser $browser) {
            $browser->visit('/');

            var_dump(
                $browser->driver->getCurrentURL(),
                $browser->driver->getPageSource()
            );
        });
    }
}

好的,我终于找到了解决方案

我有一个多项目,所以我像Laradock那样配置它

不幸的是,手册没有解释(至少我没有找到),在服务中设置什么来访问具有特定url的特定应用程序

我有两个类似的应用程序:

  • 项目1
  • 项目2
我在nginx的sites文件夹中有2个conf文件

project1.conf

project2.conf

为了让它工作,我必须在服务工作区的extra_hosts部分的docker-compose.yml中设置额外的行:

现在测试工作很好:-))

root@339f233de952:/var/www/project_http# php artisan dusk
PHPUnit 8.5.0 by Sebastian Bergmann and contributors.

R                                                                   1 / 1 (100%)string(22) "http://localhost:8000/"
string(39) "<html><head></head><body></body></html>"


Time: 1.38 seconds, Memory: 16.00 MB

There was 1 risky test:

1) Tests\Browser\ExampleTest::testBasicExample
This test did not perform any assertions

/var/www/project_http/tests/Browser/ExampleTest.php:37

OK, but incomplete, skipped, or risky tests!
Tests: 1, Assertions: 0, Risky: 1.
server {
    ...

    server_name project1.local;
    ...
server {
    ...

    server_name project2.local;
...
### Workspace Utilities ##################################
    workspace:
      ...
      extra_hosts:
        - "dockerhost:${DOCKER_HOST_IP}"
        - "project1.local:${DOCKER_HOST_IP}"
        - "project2.local:${DOCKER_HOST_IP}"
      ....
...