-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from TheDragonCode/1.x
From main - added URL column to table
- Loading branch information
Showing
6 changed files
with
194 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: phpunit | ||
on: [ push ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: [ "7.3", "7.4", "8.0" ] | ||
laravel: [ "6.0" ,"7.0", "8.0" ] | ||
|
||
name: php ${{ matrix.php }}, laravel ${{ matrix.laravel }} | ||
|
||
services: | ||
mysql: | ||
image: mysql:5.7 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: default | ||
ports: | ||
- 3306:3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis, pdo_mysql, pdo_pgsql | ||
tools: composer:v2 | ||
coverage: none | ||
|
||
- name: Install dependencies | ||
run: composer require laravel/framework:^${{ matrix.laravel }} | ||
|
||
- name: Execute tests | ||
run: sudo vendor/bin/phpunit | ||
env: | ||
MYSQL_HOST: 127.0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit | ||
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" | ||
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" | ||
stopOnError="false" | ||
stopOnFailure="false" | ||
verbose="true" | ||
> | ||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
<report> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
<html outputDirectory="build/logs/coverage"/> | ||
<text outputFile="build/logs/coverage.txt"/> | ||
</report> | ||
</coverage> | ||
<php> | ||
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/> | ||
<env name="APP_URL" value="http://localhost"/> | ||
<env name="DB_USERNAME" value="root"/> | ||
<env name="DB_PASSWORD" value="root"/> | ||
<env name="DB_DATABASE" value="default"/> | ||
</php> | ||
<testsuites> | ||
<testsuite name="Test Suite"> | ||
<directory suffix="Test.php">./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
use Carbon\Carbon; | ||
use Helldar\LastModified\Services\LastItem; | ||
use Helldar\LastModified\Services\LastModified; | ||
|
||
class MainTest extends TestCase | ||
{ | ||
protected $table = 'last_modified'; | ||
|
||
public function testRoute() | ||
{ | ||
$this->assertDatabaseCount($this->table, 0); | ||
|
||
$this->get('foo')->assertStatus(200); | ||
$this->get('foo')->assertStatus(200); | ||
|
||
$this->assertDatabaseCount($this->table, 0); | ||
} | ||
|
||
public function testLastModified() | ||
{ | ||
$this->assertDatabaseCount($this->table, 0); | ||
|
||
$this->get('foo')->assertStatus(200); | ||
$this->get('bar')->assertStatus(200); | ||
$this->get('baz')->assertStatus(200); | ||
|
||
$date = Carbon::now(); | ||
|
||
(new LastModified()) | ||
->manuals( | ||
(new LastItem('http://localhost/foo', $date)), | ||
(new LastItem('http://localhost/bar', $date)) | ||
) | ||
->update(); | ||
|
||
$this->assertDatabaseCount($this->table, 2); | ||
|
||
$this->withHeaders(['if-modified-since' => $date->format('r')])->get('foo')->assertStatus(304); | ||
$this->withHeaders(['if-modified-since' => $date->format('r')])->get('bar')->assertStatus(304); | ||
$this->withHeaders(['if-modified-since' => $date->format('r')])->get('baz')->assertStatus(200); | ||
|
||
$this->get('foo')->assertStatus(304); | ||
$this->get('foo')->assertStatus(304); | ||
$this->get('foo')->assertStatus(304); | ||
|
||
$this->get('bar')->assertStatus(304); | ||
$this->get('bar')->assertStatus(304); | ||
$this->get('bar')->assertStatus(304); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
use Helldar\LastModified\Middlewares\CheckLastModified; | ||
use Helldar\LastModified\ServiceProvider; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Orchestra\Testbench\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
protected function getPackageProviders($app): array | ||
{ | ||
return [ServiceProvider::class]; | ||
} | ||
|
||
protected function getEnvironmentSetUp($app) | ||
{ | ||
$this->setRoutes($app); | ||
} | ||
|
||
protected function setRoutes($app) | ||
{ | ||
$app['router'] | ||
->middleware(CheckLastModified::class) | ||
->get('{slug}', function (string $slug) { | ||
return response()->json($slug); | ||
}); | ||
} | ||
} |