Skip to content

Commit

Permalink
Add Semaphore CI
Browse files Browse the repository at this point in the history
Add CI Pipeline
Add Laravel Dusk Browser tests and integration test
  • Loading branch information
TomFern authored Jan 16, 2020
1 parent 3302fa4 commit 972229c
Show file tree
Hide file tree
Showing 10 changed files with 321 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
APP_NAME=Laravel
APP_ENV=local
APP_NAME=semaphore-demo-php-unsplash
APP_ENV=development
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost
APP_URL=http://localhost:8021

LOG_CHANNEL=stack

Expand Down
56 changes: 56 additions & 0 deletions .semaphore/semaphore.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: v1.0
name: CI Pipeline
agent:
machine:
type: e1-standard-2
os_image: ubuntu1804
blocks:
- name: Install dependencies
task:
jobs:
- name: Composer
commands:
- checkout
- cache restore
- composer install
- cache store
env_vars:
- name: APP_ENV
value: development
- name: Code analysis
task:
prologue:
commands:
- checkout
- cache restore
jobs:
- name: Mess Detect
commands:
- php vendor/bin/phpmd routes json phpmd_rules.xml
- php vendor/bin/phpmd resources json phpmd_rules.xml
- php vendor/bin/phpmd app/Http json phpmd_rules.xml
- name: Code Sniffer
commands:
- php vendor/bin/phpcs -n --standard=PSR2 app routes resources
- name: Security Test
commands:
- 'vendor/bin/security-checker security:check composer.lock'
- name: Tests
task:
secrets:
- name: unsplash
prologue:
commands:
- checkout
- cache restore
- cp .env.example .env
- 'php artisan key:generate'
jobs:
- name: Integration Tests
commands:
- php vendor/bin/phpunit
- name: Browser Tests
commands:
- 'php artisan dusk:chrome-driver'
- php artisan serve --port=8021 &
- php artisan dusk
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"require-dev": {
"facade/ignition": "^1.4",
"fzaninotto/faker": "^1.4",
"laravel/dusk": "^5.8",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^3.0",
"phpmd/phpmd": "^2.8",
Expand Down
130 changes: 129 additions & 1 deletion composer.lock

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

23 changes: 23 additions & 0 deletions tests/Browser/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?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('/')
->assertTitle('Unsplash Image Gallery Demo');
});
}
}
41 changes: 41 additions & 0 deletions 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 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 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 tests/Browser/screenshots/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
44 changes: 44 additions & 0 deletions tests/DuskTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Tests;

use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Laravel\Dusk\TestCase as BaseTestCase;

abstract class DuskTestCase extends BaseTestCase
{
use CreatesApplication;

/**
* Prepare for Dusk test execution.
*
* @beforeClass
* @return void
*/
public static function prepare()
{
static::startChromeDriver();
}

/**
* Create the RemoteWebDriver instance.
*
* @return \Facebook\WebDriver\Remote\RemoteWebDriver
*/
protected function driver()
{
$options = (new ChromeOptions)->addArguments([
'--disable-gpu',
'--headless',
'--window-size=1920,1080',
]);

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

0 comments on commit 972229c

Please sign in to comment.