Skip to content

Commit

Permalink
Add support for Laravel 8 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
richan-fongdasen authored Sep 19, 2020
1 parent cc14aa1 commit e805145
Show file tree
Hide file tree
Showing 15 changed files with 151 additions and 128 deletions.
8 changes: 2 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ matrix:
fast_finish: true
include:
- php: 7.3
env: LARAVEL=^6.0 ORCHESTRA=^4.0
env: LARAVEL=^8.0 ORCHESTRA=^6.0
- php: 7.4
env: LARAVEL=^6.0 ORCHESTRA=^4.0
- php: 7.3
env: LARAVEL=^7.0 ORCHESTRA=^5.0
- php: 7.4
env: LARAVEL=^7.0 ORCHESTRA=^5.0 COVERAGE=1
env: LARAVEL=^8.0 ORCHESTRA=^6.0 COVERAGE=1

allow_failures:
- env: COVERAGE=1
Expand Down
27 changes: 14 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
},
"require": {
"php": "^7.3",
"guzzlehttp/guzzle": "~6.0",
"illuminate/database": "^6.0|^7.0",
"illuminate/support": "^6.0|^7.0"
"guzzlehttp/guzzle": "~7.0",
"illuminate/database": "^8.0",
"illuminate/support": "^8.0"
},
"require-dev": {
"ekino/phpstan-banned-code": "^0.3.1",
"mockery/mockery": "~1.0",
"orchestra/database": "~4.0|~5.0",
"orchestra/testbench": "~4.0|~5.0",
"phpmd/phpmd": "^2.8",
"phpstan/phpstan": "^0.11|^0.12",
"phpstan/phpstan-deprecation-rules": "^0.11|^0.12",
"phpstan/phpstan-strict-rules": "^0.11|^0.12",
"phpunit/phpunit": "^8.0|^9.0",
"sebastian/phpcpd": "^5.0"
"mockery/mockery": "~1.3",
"orchestra/database": "^6.0",
"orchestra/testbench": "^6.0",
"phpmd/phpmd": "^2.9",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-deprecation-rules": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^9.3",
"sebastian/phpcpd": "^6.0"
},
"config": {
"sort-packages": true
Expand All @@ -48,7 +48,8 @@
},
"autoload-dev": {
"psr-4": {
"RichanFongdasen\\Varnishable\\Tests\\": "tests/"
"RichanFongdasen\\Varnishable\\Tests\\": "tests/",
"Database\\Factories\\": "tests/Supports/Factories/"
}
},
"extra": {
Expand Down
31 changes: 11 additions & 20 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true">
<testsuites>
<testsuite name="Laravel Varnishable Test Suite">
<directory suffix="Tests.php">./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Laravel Varnishable Test Suite">
<directory suffix="Tests.php">./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ $ composer require richan-fongdasen/laravel-varnishable
| 5.5.x - 5.8.x | 1.0.x - 1.1.x |
| 6.x | 1.2.x |
| 7.x | 1.3.x |
| 8.x | 1.4.x |

> If you are using Laravel version 5.5+ then you can skip registering the service provider in your Laravel application.
Expand Down
31 changes: 21 additions & 10 deletions tests/Concerns/InvalidateVarnishCacheTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace RichanFongdasen\Varnishable\Tests\Concerns;

use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
use Illuminate\Container\Container;
use RichanFongdasen\Varnishable\Tests\TestCase;
use RichanFongdasen\Varnishable\VarnishableService;

Expand All @@ -15,6 +17,13 @@ class InvalidateVarnishCacheTests extends TestCase
*/
protected $guzzle;

/**
* Dummy guzzle response
*
* @var Response
*/
protected $response;

/**
* Varnishable service object.
*
Expand All @@ -36,6 +45,8 @@ public function setUp() :void

$this->guzzle = \Mockery::mock(Client::class);
$this->service = new VarnishableService($this->guzzle);

$this->response = Container::getInstance()->make(Response::class, []);
}

/** @test */
Expand All @@ -45,11 +56,11 @@ public function it_can_send_fullban_request_to_flush_the_entire_cache()
$this->guzzle->shouldReceive('request')
->with('FULLBAN', 'http://192.168.10.10:8888/', $options)
->times(1)
->andReturn(true);
->andReturn($this->response);
$this->guzzle->shouldReceive('request')
->with('FULLBAN', 'http://192.168.10.30:8888/', $options)
->times(1)
->andReturn(true);
->andReturn($this->response);

$this->service->flush('localhost:8000');
}
Expand All @@ -68,17 +79,17 @@ public function it_can_send_ban_requests_based_on_the_given_regex_patterns()

$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.10:8888/', $options1)->times(1)
->andReturn(true);
->andReturn($this->response);
$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.30:8888/', $options1)->times(1)
->andReturn(true);
->andReturn($this->response);

$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.10:8888/', $options2)->times(1)
->andReturn(true);
->andReturn($this->response);
$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.30:8888/', $options2)->times(1)
->andReturn(true);
->andReturn($this->response);

$this->service->banByPatterns('localhost:8000', [
'/products/[0-9]*/view', '/product-news/(.)*'
Expand All @@ -99,17 +110,17 @@ public function it_can_send_ban_requests_based_on_the_given_urls()

$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.10:8888/', $options1)->times(1)
->andReturn(true);
->andReturn($this->response);
$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.30:8888/', $options1)->times(1)
->andReturn(true);
->andReturn($this->response);

$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.10:8888/', $options2)->times(1)
->andReturn(true);
->andReturn($this->response);
$this->guzzle->shouldReceive('request')
->with('BAN', 'http://192.168.10.30:8888/', $options2)->times(1)
->andReturn(true);
->andReturn($this->response);

$this->service->banByUrls('localhost:8000', [
'/home', '/about-us/company-overview'
Expand Down
36 changes: 36 additions & 0 deletions tests/Supports/Factories/PostFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use RichanFongdasen\Varnishable\Tests\Supports\Models\Post;

class PostFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Post::class;

/**
* Define the model's default state.
*
* @return array
* @throws \Exception
*/
public function definition()
{
$time = random_int(1483203600, 1530378000);

return [
'title' => $this->faker->sentence,
'description' => $this->faker->paragraph(2),
'content' => implode("\n<br />\n", $this->faker->paragraphs(10)),
'created_at' => '2016-01-01 00:00:00',
'updated_at' => date('Y-m-d H:i:s', $time),
];
}
}
37 changes: 37 additions & 0 deletions tests/Supports/Factories/UserFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use RichanFongdasen\Varnishable\Tests\Supports\Models\User;

class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;

/**
* Define the model's default state.
*
* @return array
* @throws \Exception
*/
public function definition()
{
$time = random_int(1483203600, 1530378000);

return [
'name' => $this->faker->name,
'email' => $this->faker->email,
'password' => bcrypt(Str::random(12)),
'remember_token' => Str::random(12),
'created_at' => '2016-01-01 00:00:00',
'updated_at' => date('Y-m-d H:i:s', $time),
];
}
}
2 changes: 2 additions & 0 deletions tests/Supports/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace RichanFongdasen\Varnishable\Tests\Supports\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use RichanFongdasen\Varnishable\Model\Concerns\Varnishable;

class Post extends AbstractModel
{
use HasFactory;
use Varnishable;

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/Supports/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

namespace RichanFongdasen\Varnishable\Tests\Supports\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use RichanFongdasen\Varnishable\Model\Concerns\Varnishable;

class User extends AbstractModel
{
use HasFactory;
use SoftDeletes;
use Varnishable;

Expand Down
15 changes: 0 additions & 15 deletions tests/Supports/database/factories/PostFactory.php

This file was deleted.

17 changes: 0 additions & 17 deletions tests/Supports/database/factories/UserFactory.php

This file was deleted.

Loading

0 comments on commit e805145

Please sign in to comment.