Skip to content

Commit

Permalink
テストソース
Browse files Browse the repository at this point in the history
  • Loading branch information
maibaba committed Nov 30, 2022
1 parent 71c81d3 commit aa604c7
Show file tree
Hide file tree
Showing 14 changed files with 405 additions and 1 deletion.
13 changes: 13 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ services:
MYSQL_PASSWORD: ${DB_PASS}
container_name: ${MYSQL_CONTAINER}

mysql.test:
image: mysql:8.0
environment:
MYSQL_DATABASE: ${DB_NAME}
MYSQL_USER: ${DB_USER}
MYSQL_ROOT_PASSWORD: ${DB_PASS}
MYSQL_PASSWORD: ${DB_PASS}
MYSQL_ALLOW_EMPTY_PASSWORD: 1
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-p${DB_PASSWORD}" ]
retries: 3
timeout: 5s

phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
Expand Down
50 changes: 50 additions & 0 deletions src/.github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Laravel

on:
push:
pull_request:

env:
DB_USERNAME: sail
DB_PASSWORD: password
MAIL_FROM_ADDRESS: [email protected]

jobs:
phpunit:

runs-on: ubuntu-latest

services:
mysql.test:
image: 'mysql/mysql-server:8.0'
ports:
- 3306:3306
env:
MYSQL_DATABASE: 'example_app'
MYSQL_USER: ${{ env.DB_USERNAME }}
MYSQL_PASSWORD: ${{ env.DB_PASSWORD }}
MYSQL_ALLOW_EMPTY_PASSWORD: 1
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1'
tools: composer:v2
- name: Copy .env
run: cp .env.example .env.testing
- name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate --env testing
- name: Set hostname
run: sudo echo "127.0.0.1 mysql.test" | sudo tee -a /etc/hosts
- name: Execute tests (Unit and Feature tests) via PHPUnit
run: vendor/bin/phpunit
1 change: 1 addition & 0 deletions src/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"require-dev": {
"facade/ignition": "^2.5",
"fakerphp/faker": "^1.9.1",
"laravel/dusk": "*",
"laravel/sail": "^1.0.1",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^5.10",
Expand Down
140 changes: 139 additions & 1 deletion src/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<server name="CACHE_DRIVER" value="array"/>
<!-- <server name="DB_CONNECTION" value="sqlite"/> -->
<!-- <server name="DB_DATABASE" value=":memory:"/> -->
<server name="DB_HOST" value="mysql.test"/>
<server name="MAIL_MAILER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
Expand Down
1 change: 1 addition & 0 deletions src/resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,6 @@
</div>
</div>
</div>
Hello!
</body>
</html>
24 changes: 24 additions & 0 deletions src/tests/Browser/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\Browser;

use Illuminate\Foundation\Testing\DatabaseMigrations;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;

class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* @return void
*/
public function testBasicExample()
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel')
->assertSee('Hello!');
});
}
}
41 changes: 41 additions & 0 deletions src/tests/Browser/Pages/HomePage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Tests\Browser\Pages;

use Laravel\Dusk\Browser;

class HomePage extends Page
{
/**
* Get the URL for the page.
*
* @return string
*/
public function url()
{
return '/';
}

/**
* Assert that the browser is on the page.
*
* @param \Laravel\Dusk\Browser $browser
* @return void
*/
public function assert(Browser $browser)
{
//
}

/**
* Get the element shortcuts for the page.
*
* @return array
*/
public function elements()
{
return [
'@element' => '#selector',
];
}
}
20 changes: 20 additions & 0 deletions src/tests/Browser/Pages/Page.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Browser\Pages;

use Laravel\Dusk\Page as BasePage;

abstract class Page extends BasePage
{
/**
* Get the global element shortcuts for the site.
*
* @return array
*/
public static function siteElements()
{
return [
'@element' => '#selector',
];
}
}
2 changes: 2 additions & 0 deletions src/tests/Browser/console/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions src/tests/Browser/screenshots/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
2 changes: 2 additions & 0 deletions src/tests/Browser/source/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
Loading

0 comments on commit aa604c7

Please sign in to comment.