Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Dec 29, 2016
1 parent c45f40e commit f7d7783
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Varnish.php
Expand Up @@ -16,7 +16,7 @@ public function flush($host = null)
{
$host = $this->getHosts($host);

$command = $this->generateFlushCommand($host);
$command = $this->generateBanCommand($host);

return $this->executeCommand($command);
}
Expand All @@ -37,7 +37,7 @@ protected function getHosts($host = null): array
return $host;
}

protected function generateFlushCommand(array $hosts): string
public function generateBanCommand(array $hosts): string
{
if (! is_array($hosts)) {
$hosts = [$hosts];
Expand Down
4 changes: 2 additions & 2 deletions src/VarnishServiceProvider.php
Expand Up @@ -21,9 +21,9 @@ public function boot()

public function register()
{
$this->mergeConfigFrom(__DIR__.'/../config/laravel-uptime-monitor.php', 'laravel-uptime-monitor');
$this->mergeConfigFrom(__DIR__.'/../config/laravel-varnish.php', 'laravel-varnish');

$this->app->bind('command.monitor:check-uptime', FlushVarnishCache::class);
$this->app->bind('command.varnish:flush', FlushVarnishCache::class);

$this->commands([
'command.varnish:flush',
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionsTest.php → tests/HelpersTest.php
Expand Up @@ -5,7 +5,7 @@
use Spatie\Varnish\Varnish;
use PHPUnit_Framework_TestCase;

class FunctionsTest extends PHPUnit_Framework_TestCase
class HelpersTest extends PHPUnit_Framework_TestCase
{
/** @test */
public function it_returns_an_instance_of_varnish()
Expand Down
29 changes: 29 additions & 0 deletions tests/VarnishTest.php
@@ -0,0 +1,29 @@
<?php

namespace Spatie\Varnish\Test;

use Spatie\Varnish\Varnish;
use PHPUnit_Framework_TestCase;

class VarnishTest extends TestCase
{
/** @test */
public function it_can_generate_a_ban_command_for_a_single_host()
{
$expectedCommand = "sudo varnishadm -S -T 127.0.0.1: 'ban req.http.host ~ (^example.com$)'";


$this->assertEquals($expectedCommand, (new Varnish())->generateBanCommand(['example.com']));
}

/** @test */
public function it_can_generate_a_ban_command_for_multiple_hosts()
{
$expectedCommand = "sudo varnishadm -S -T 127.0.0.1: 'ban req.http.host ~ (^example.com$)|(^example2.com$)'";

$this->assertEquals($expectedCommand, (new Varnish())->generateBanCommand([
'example.com',
'example2.com'
]));
}
}

0 comments on commit f7d7783

Please sign in to comment.