From 3588d41b4c89f5b1aff0919ec9683cbec8da923c Mon Sep 17 00:00:00 2001 From: Guilherme Frias Date: Wed, 10 Jun 2026 13:00:39 -0300 Subject: [PATCH] =?UTF-8?q?[feat]:=20Implementando=20Docker=20e=20Dusk=20a?= =?UTF-8?q?o=20reposit=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + composer.json | 5 +- composer.lock | 148 ++++++++++++++++++++++++++- docker-compose.yml | 56 ++++++++++ dockerfile | 15 +++ tests/Browser/ExampleTest.php | 21 ++++ tests/Browser/Pages/HomePage.php | 36 +++++++ tests/Browser/Pages/Page.php | 20 ++++ tests/Browser/console/.gitignore | 2 + tests/Browser/screenshots/.gitignore | 2 + tests/Browser/source/.gitignore | 2 + tests/DuskTestCase.php | 50 +++++++++ 12 files changed, 353 insertions(+), 6 deletions(-) create mode 100644 docker-compose.yml create mode 100644 dockerfile create mode 100644 tests/Browser/ExampleTest.php create mode 100644 tests/Browser/Pages/HomePage.php create mode 100644 tests/Browser/Pages/Page.php create mode 100644 tests/Browser/console/.gitignore create mode 100644 tests/Browser/screenshots/.gitignore create mode 100644 tests/Browser/source/.gitignore create mode 100644 tests/DuskTestCase.php diff --git a/.gitignore b/.gitignore index eb7148e4..4414598a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ /vendor .env .env.backup +.env.dusk.local +.phpunit.cache/ .phpunit.result.cache Homestead.json Homestead.yaml diff --git a/composer.json b/composer.json index b2dc2f6e..de37e112 100644 --- a/composer.json +++ b/composer.json @@ -32,11 +32,12 @@ "uspdev/utils": "^1.1.0" }, "require-dev": { - "spatie/laravel-ignition": "^2.0", "fakerphp/faker": "^1.9.1", + "laravel/dusk": "^8.6", "mockery/mockery": "^1.3.1", "nunomaduro/collision": "^8.1", - "phpunit/phpunit": "^11.0" + "phpunit/phpunit": "^11.0", + "spatie/laravel-ignition": "^2.0" }, "config": { "optimize-autoloader": true, diff --git a/composer.lock b/composer.lock index 3f85f56c..862799ce 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f21a10a9a763216c2548c50503201e37", + "content-hash": "5897068e8aaa52a15ae14edf6f459c3e", "packages": [ { "name": "barryvdh/laravel-debugbar", @@ -8913,6 +8913,80 @@ }, "time": "2025-04-30T06:54:44+00:00" }, + { + "name": "laravel/dusk", + "version": "v8.6.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/dusk.git", + "reference": "e7fd48762c6a82ad2cd311db07587aa2a97ce143" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/dusk/zipball/e7fd48762c6a82ad2cd311db07587aa2a97ce143", + "reference": "e7fd48762c6a82ad2cd311db07587aa2a97ce143", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-zip": "*", + "guzzlehttp/guzzle": "^7.5", + "illuminate/console": "^10.0|^11.0|^12.0|^13.0", + "illuminate/support": "^10.0|^11.0|^12.0|^13.0", + "php": "^8.1", + "php-webdriver/webdriver": "^1.15.2", + "symfony/console": "^6.2|^7.0|^8.0", + "symfony/finder": "^6.2|^7.0|^8.0", + "symfony/process": "^6.2|^7.0|^8.0", + "vlucas/phpdotenv": "^5.2" + }, + "require-dev": { + "laravel/framework": "^10.0|^11.0|^12.0|^13.0", + "mockery/mockery": "^1.6", + "orchestra/testbench-core": "^8.19|^9.17|^10.8|^11.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.1|^11.0|^12.0.1", + "psy/psysh": "^0.11.12|^0.12", + "symfony/yaml": "^6.2|^7.0|^8.0" + }, + "suggest": { + "ext-pcntl": "Used to gracefully terminate Dusk when tests are running." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Dusk\\DuskServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Dusk\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Dusk provides simple end-to-end testing and browser automation.", + "keywords": [ + "laravel", + "testing", + "webdriver" + ], + "support": { + "issues": "https://github.com/laravel/dusk/issues", + "source": "https://github.com/laravel/dusk/tree/v8.6.0" + }, + "time": "2026-04-15T14:50:40+00:00" + }, { "name": "mockery/mockery", "version": "1.6.12", @@ -9273,6 +9347,72 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-webdriver/webdriver", + "version": "1.16.0", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "ac0662863aa120b4f645869f584013e4c4dba46a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/ac0662863aa120b4f645869f584013e4c4dba46a", + "reference": "ac0662863aa120b4f645869f584013e4c4dba46a", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^7.3 || ^8.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^5.0 || ^6.0 || ^7.0 || ^8.0" + }, + "replace": { + "facebook/webdriver": "*" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.20.0", + "ondram/ci-detector": "^4.0", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpunit/phpunit": "^9.3", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^5.0 || ^6.0 || ^7.0 || ^8.0" + }, + "suggest": { + "ext-simplexml": "For Firefox profile creation" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Exception/TimeoutException.php" + ], + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.", + "homepage": "https://github.com/php-webdriver/php-webdriver", + "keywords": [ + "Chromedriver", + "geckodriver", + "php", + "selenium", + "webdriver" + ], + "support": { + "issues": "https://github.com/php-webdriver/php-webdriver/issues", + "source": "https://github.com/php-webdriver/php-webdriver/tree/1.16.0" + }, + "time": "2025-12-28T23:57:40+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.9", @@ -11128,12 +11268,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": [], + "stability-flags": {}, "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^8.3" }, - "platform-dev": [], - "plugin-api-version": "2.6.0" + "platform-dev": {}, + "plugin-api-version": "2.9.0" } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..1c710797 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,56 @@ +services: + estagios: + image: estagios:latest + container_name: estagios + ports: + - "8000:80" + depends_on: + - mariadb + networks: + - estagios-network + volumes: + - ./:/var/www/html + environment: + HOME: /tmp + user: "${UID:-1000}:${GID:-1000}" + + mariadb: + image: mariadb:11 + container_name: estagios_mariadb + restart: always + environment: + MYSQL_DATABASE: estagios + MYSQL_USER: estagios + MYSQL_PASSWORD: estagios + MYSQL_ROOT_PASSWORD: estagios + volumes: + - mariadb_data:/var/lib/mysql + networks: + - estagios-network + + selenium: + image: selenium/standalone-chrome + container_name: estagios_selenium + ports: + - "7900:7900" # VNC (pra ver o browser rodando) + networks: + - estagios-network + shm_size: 2gb + + senhaunica-faker: + image: uspdev/senhaunica-faker + container_name: estagios_senhaunica-faker + ports: + - "3141:3141" + environment: + - APP_URL=http://auth.local:3141 + networks: + estagios-network: + aliases: + - auth.local + +networks: + estagios-network: + +volumes: + mariadb_data: \ No newline at end of file diff --git a/dockerfile b/dockerfile new file mode 100644 index 00000000..07539062 --- /dev/null +++ b/dockerfile @@ -0,0 +1,15 @@ +FROM uspdev/uspdev-php-apache:8.3 + +RUN sed -i 's|/var/www/html|/var/www/html/public|' \ + /etc/apache2/sites-available/000-default.conf + +USER www-data + +COPY --chown=www-data . . + +RUN composer install \ + --no-dev \ + --optimize-autoloader \ + --no-interaction + +CMD ["apache2-foreground"] \ No newline at end of file diff --git a/tests/Browser/ExampleTest.php b/tests/Browser/ExampleTest.php new file mode 100644 index 00000000..401d9d13 --- /dev/null +++ b/tests/Browser/ExampleTest.php @@ -0,0 +1,21 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('Estágios'); + }); + } +} diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php new file mode 100644 index 00000000..45d9283f --- /dev/null +++ b/tests/Browser/Pages/HomePage.php @@ -0,0 +1,36 @@ + + */ + public function elements(): array + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php new file mode 100644 index 00000000..eb9a2ded --- /dev/null +++ b/tests/Browser/Pages/Page.php @@ -0,0 +1,20 @@ + + */ + public static function siteElements(): array + { + return [ + '@element' => '#selector', + ]; + } +} diff --git a/tests/Browser/console/.gitignore b/tests/Browser/console/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/Browser/console/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Browser/screenshots/.gitignore b/tests/Browser/screenshots/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/Browser/screenshots/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/Browser/source/.gitignore b/tests/Browser/source/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/tests/Browser/source/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/tests/DuskTestCase.php b/tests/DuskTestCase.php new file mode 100644 index 00000000..f171a545 --- /dev/null +++ b/tests/DuskTestCase.php @@ -0,0 +1,50 @@ +addArguments(collect([ + $this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080', + '--disable-search-engine-choice-screen', + '--disable-smooth-scrolling', + ])->unless($this->hasHeadlessDisabled(), function (Collection $items) { + return $items->merge([ + '--disable-gpu', + '--headless=new', + ]); + })->all()); + + return RemoteWebDriver::create( + $_ENV['DUSK_DRIVER_URL'] ?? env('DUSK_DRIVER_URL') ?? 'http://localhost:9515', + DesiredCapabilities::chrome()->setCapability( + ChromeOptions::CAPABILITY, $options + ) + ); + } +}