Skip to content

Commit

Permalink
Merge pull request #80 from GeneaLabs/feature/implement-orchestral-te…
Browse files Browse the repository at this point in the history
…stsuite

Get all existing tests converted to Orchestral
  • Loading branch information
mikebronner authored Jan 10, 2018
2 parents 347d11c + 7601045 commit ebd5ef6
Show file tree
Hide file tree
Showing 17 changed files with 112 additions and 87 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/tests/Browser/console
/tests/Browser/screenshots
/vendor
composer.lock
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
dist: trusty
language: php
sudo: required

addons:
chrome: stable

php:
- 7.0
Expand All @@ -7,7 +12,8 @@ php:

before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-source --dev
- travis_retry composer install --no-interaction --dev --prefer-dist --no-suggest
- google-chrome-stable --headless --disable-gpu --remote-debugging-port=9222 http://localhost &

script:
- ./vendor/bin/phpunit --coverage-text --coverage-clover ./build/logs/clover.xml
Expand Down
18 changes: 10 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,21 @@
}
],
"require": {
"php": ">=7.0.0",
"illuminate/support": "5.0 - 5.5",
"illuminate/routing": "5.0 - 5.5",
"jenssegers/model": "*"
"illuminate/routing": "5.5.*",
"illuminate/support": "5.5.*",
"jenssegers/model": "*",
"php": ">=7.0.0"
},
"require-dev": {
"laravel/laravel": "5.5.*",
"codedungeon/phpunit-result-printer": "^0.5.0",
"mockery/mockery": "0.9.*",
"orchestra/testbench-browser-kit": "^3.5",
"orchestra/testbench-dusk": "3.5.x-dev@dev",
"orchestra/testbench": "^3.5",
"phpmd/phpmd": "^2.6",
"phpunit/phpunit": "5.7.*",
"phpunit/phpunit": "*",
"satooshi/php-coveralls" : "*",
"sebastian/phpcpd": "*",
"symfony/thanks": "^1.0"
"sebastian/phpcpd": "*"
},
"autoload": {
"psr-4": {
Expand Down
11 changes: 9 additions & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Browser">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>

<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
Expand All @@ -27,6 +33,7 @@
<php>
<env name="APP_KEY" value="base64:Xgs1LQt1GdVHhD6qyYCXnyq61DE3UKqJ5k2SJc+Nw2g="/>
<env name="APP_ENV" value="testing"/>
<env name="APP_URL" value="http://127.0.0.1:8000"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
Expand Down
10 changes: 0 additions & 10 deletions src/Providers/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

class Service extends ServiceProvider
{
protected $defer = false;

public function boot()
{
app('router')->group($this->middlewareGroupExists('web')
Expand Down Expand Up @@ -39,10 +37,7 @@ public function boot()
$this->publishes([
$configPath => config_path('genealabs-laravel-caffeine.php')
], 'config');
}

public function register()
{
$this->commands(Publish::class);
$this->mergeConfigFrom(__DIR__ . '/../../config/genealabs-laravel-caffeine.php', 'genealabs-laravel-caffeine');

Expand All @@ -58,11 +53,6 @@ public function register()
}
}

public function provides() : array
{
return ['genealabs-laravel-caffeine'];
}

protected function middlewareGroupExists(string $group) : bool
{
$routes = collect(app('router')->getRoutes()->getRoutes());
Expand Down
16 changes: 16 additions & 0 deletions tests/Browser/DripTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests\Browser;

use GeneaLabs\LaravelCaffeine\Tests\BrowserTestCase;
use Laravel\Dusk\Browser;

class DripTest extends BrowserTestCase
{
public function testFormDoesntExpire()
{
$this->browse(function (Browser $browser) {
$response = $browser->visit('tests/form');

$response->assertSee('Test Form');
});
}
}
18 changes: 18 additions & 0 deletions tests/BrowserTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests;

use Orchestra\Testbench\Dusk\TestCase as BaseTestCase;

abstract class BrowserTestCase extends BaseTestCase
{
use CreatesApplication;

public static function setUpBeforeClass()
{
static::serve();
}

public static function tearDownAfterClass()
{
static::stopServing();
}
}
21 changes: 5 additions & 16 deletions tests/CreatesApplication.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,14 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests;

use GeneaLabs\LaravelCaffeine\Providers\Service as LaravelCaffeineService;
use Illuminate\Contracts\Console\Kernel;

trait CreatesApplication
{
public function createApplication()
/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function getPackageProviders($app)
{
$this->loadRoutes();
$app = require __DIR__ . '/../vendor/laravel/laravel/bootstrap/app.php';
$app->make(Kernel::class)->bootstrap();
$app->register(LaravelCaffeineService::class);

return $app;
}

protected function loadRoutes()
{
$routes = file_get_contents(__DIR__ . '/../routes/web.php');
$routes .= str_replace('<?php', '', file_get_contents(__DIR__ . '/../tests/routes/web.php'));

file_put_contents(__DIR__ . '/../vendor/laravel/laravel/routes/web.php', $routes);
return [LaravelCaffeineService::class];
}
}
25 changes: 15 additions & 10 deletions tests/Feature/CaffeineTest.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests\Feature;

use GeneaLabs\LaravelCaffeine\Http\Middleware\LaravelCaffeineDripMiddleware;
use GeneaLabs\LaravelCaffeine\Tests\TestCase;
use GeneaLabs\LaravelCaffeine\Tests\FeatureTestCase;

class CaffeineTest extends TestCase
class CaffeineTest extends FeatureTestCase
{
public function testDripEndpoint()
{
$dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');

$response = $this->get($dripRoute);

$response->assertStatus(204);
$response->seeStatusCode(204);
}

public function testMiddlewareInjectsDripScript()
Expand All @@ -20,13 +20,15 @@ public function testMiddlewareInjectsDripScript()

$response = $this->get(route('genealabs-laravel-caffeine.tests.form'));

$response->assertSee($expectedResult);
$response->see($expectedResult);
}

public function testSuccessfulDrip()
{
$dripRoute = config('genealabs-laravel-caffeine.route', 'genealabs/laravel-caffeine/drip');
$html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
$html = $this
->get(route('genealabs-laravel-caffeine.tests.form'))
->response
->getContent();
$matches = [];
preg_match('/<meta name="csrf-token" content="(.*?)">/', $html, $matches);
Expand All @@ -36,7 +38,7 @@ public function testSuccessfulDrip()
'_token' => $csrfToken,
]);

$response->assertStatus(204);
$response->seeStatusCode(204);
}

public function testExpiredDrip()
Expand All @@ -45,7 +47,9 @@ public function testExpiredDrip()
'genealabs-laravel-caffeine.drip-interval',
'genealabs/laravel-caffeine/drip'
);
$html = $this->get(route('genealabs-laravel-caffeine.tests.form'))
$html = $this
->get(route('genealabs-laravel-caffeine.tests.form'))
->response
->getContent();
$matches = [];
preg_match(
Expand All @@ -60,13 +64,14 @@ public function testExpiredDrip()
'_token' => $csrfToken,
]);

$response->assertStatus(404);
$response->seeStatusCode(404);
}

public function testDisabledCaffeination()
{
$html = $this
->get(route('genealabs-laravel-caffeine.tests.disabled-page'))
->response
->getContent();

$isDisabled = (bool) preg_match(
Expand All @@ -86,7 +91,7 @@ public function testNonStringReturnContent()
{
$response = $this->get(route('genealabs-laravel-caffeine.tests.null-response'));

$response->assertDontSee('const caffeineSendDrip');
$response->dontSee('const caffeineSendDrip');
}

public function testRouteMiddleware()
Expand All @@ -99,6 +104,6 @@ public function testRouteMiddleware()
$response = $this
->get(route('genealabs-laravel-caffeine.tests.route-middleware'));

$response->assertSee('const caffeineSendDrip');
$response->see('const caffeineSendDrip');
}
}
8 changes: 8 additions & 0 deletions tests/FeatureTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests;

use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;

abstract class FeatureTestCase extends BaseTestCase
{
use CreatesApplication;
}
8 changes: 0 additions & 8 deletions tests/TestCase.php

This file was deleted.

7 changes: 3 additions & 4 deletions tests/Unit/Console/Commands/PublishTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests\Unit\Console\Commands;

use GeneaLabs\LaravelCaffeine\Tests\TestCase;
use GeneaLabs\LaravelCaffeine\Tests\UnitTestCase;

class PublishTest extends TestCase
class PublishTest extends UnitTestCase
{
public function testConfigFileGetsPublished()
{
app('Illuminate\Contracts\Console\Kernel')->call('caffeine:publish', ['--config' => true]);
$this->artisan('caffeine:publish', ['--config' => true]);

$this->assertFileExists(base_path('config/genealabs-laravel-caffeine.php'));
}
Expand All @@ -19,6 +19,5 @@ public function testConfigFileContainsCorrectSettings()
$this->assertContains("'domain' => null,", $settings);
$this->assertContains("'route' => 'genealabs/laravel-caffeine/drip',", $settings);
$this->assertContains("'outdated-drip-check-interval' => 2000,", $settings);
$this->assertContains("'use-route-middleware' => false,", $settings);
}
}
4 changes: 2 additions & 2 deletions tests/Unit/DripperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

use Exception;
use GeneaLabs\LaravelCaffeine\Dripper;
use GeneaLabs\LaravelCaffeine\Tests\TestCase;
use GeneaLabs\LaravelCaffeine\Tests\UnitTestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class DripperTest extends TestCase
class DripperTest extends UnitTestCase
{
public function testAgeCheckIntervalAttributeValue()
{
Expand Down
17 changes: 0 additions & 17 deletions tests/Unit/Providers/ServiceTest.php

This file was deleted.

8 changes: 8 additions & 0 deletions tests/UnitTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php namespace GeneaLabs\LaravelCaffeine\Tests;

use Orchestra\Testbench\TestCase as BaseTestCase;

abstract class UnitTestCase extends BaseTestCase
{
use CreatesApplication;
}
1 change: 1 addition & 0 deletions tests/resources/views/tests/form.blade.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@extends('genealabs-laravel-caffeine::tests.layout')

@section('content')
<h1>Test Form</h1>
<form method="post">
{{ csrf_field() }}
<input type="hidden" name="success" value="true">
Expand Down
17 changes: 8 additions & 9 deletions tests/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

use GeneaLabs\LaravelCaffeine\Tests\Http\Controllers\Test;

Route::group([
'middleware' => ['web'],
'as' => 'genealabs-laravel-caffeine.',
'prefix' => 'tests'
'prefix' => 'tests',
'namespace' => 'GeneaLabs\LaravelCaffeine\Tests\Http\Controllers',
], function () {
Route::any('form', Test::class . '@drippedForm')
Route::any('form', 'Test@drippedForm')
->name('tests.form');
Route::any('dripped-form', Test::class . '@drippedForm');
Route::any('expiring-form', Test::class . '@expiredForm');
Route::any('disabled-page', Test::class . '@disabledPage')
Route::any('dripped-form', 'Test@drippedForm');
Route::any('expiring-form', 'Test@expiredForm');
Route::any('disabled-page', 'Test@disabledPage')
->name('tests.disabled-page');
Route::any('null-response', Test::class . '@nullResponse')
Route::any('null-response', 'Test@nullResponse')
->name('tests.null-response');
Route::any('route-middleware', Test::class . '@drippedForm')
Route::any('route-middleware', 'Test@drippedForm')
->name('tests.route-middleware')
->middleware('caffeinated');
});

0 comments on commit ebd5ef6

Please sign in to comment.