Skip to content

Commit

Permalink
Merge pull request #1 from intouchinsight/laravel-upgrade
Browse files Browse the repository at this point in the history
Laravel Upgrade
  • Loading branch information
craig-roy authored Oct 9, 2024
2 parents 24c1803 + 44177de commit f17e2b8
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 47 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
unit-tests:
runs-on: ubuntu-latest
name: unit-tests
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 10

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: xdebug

- name: Install dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

- name: Execute tests - Unit
run: vendor/bin/phpunit --testsuite Unit
phplint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 10
- uses: shivammathur/setup-php@v2
with:
php-version: '8.3'
coverage: xdebug

- name: Install dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-suggest --no-progress --prefer-dist

- name: Run laravel pint
run: ./vendor/bin/pint --test
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ tests/coverage
vendor
composer.lock
.phpstorm.meta.php
tests/reports
tests/reports
.phpunit.cache
13 changes: 8 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,18 @@
}
},
"require": {
"php": "^8.0",
"aws/aws-sdk-php": "^3.20",
"illuminate/support": "5.*"
"illuminate/support": "^10|^11"
},
"require-dev": {
"mockery/mockery": "^0.9.6",
"laravel/framework": ">5.1",
"phpunit/phpunit": "~4.8",
"laravel/pint": "^1.15",
"mockery/mockery": "^1.4.4",
"laravel/framework": "^10|^11",
"phpunit/phpunit": "^10.0",
"squizlabs/php_codesniffer": "^2.8",
"scrutinizer/ocular": "^1.3"
"scrutinizer/ocular": "^1.9",
"symfony/console": "^6.0"
},
"scripts": {
"cs": "phpcs --standard=psr2 src/",
Expand Down
2 changes: 1 addition & 1 deletion config/laravel-aws-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
/**
* The Laravel cache store defined in `config/cache.php` to use.
*/
'cache' => env('LARAVEL_AWS_CACHE_CACHE', 'file')
'cache' => env('LARAVEL_AWS_CACHE_CACHE', 'file'),
];
29 changes: 8 additions & 21 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name=":vendor Test Suite">
<testsuite name="Unit">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-text"/>
<log type="coverage-clover" target="tests/reports/clover.xml"/>
</logging>
</phpunit>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>
12 changes: 5 additions & 7 deletions src/LaravelCacheAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,27 @@ public function __construct(CacheManager $manager, $store, $prefix = null)
{
$this->manager = $manager;
$this->store = $store;
$this->prefix = 'aws_credentials_' . $prefix;
$this->prefix = 'aws_credentials_'.$prefix;
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function get($key)
{
return $this->getCache()->get($this->generateKey($key));
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function remove($key)
{
$this->getCache()->forget($this->generateKey($key));
}

/**
* @inheritdoc
* {@inheritdoc}
*/
public function set($key, $value, $ttl = 0)
{
Expand All @@ -65,12 +65,11 @@ public function set($key, $value, $ttl = 0)
/**
* Generate a cache key which incorporates the prefix.
*
* @param $key
* @return string
*/
protected function generateKey($key)
{
return $this->prefix . $key;
return $this->prefix.$key;
}

/**
Expand All @@ -79,7 +78,6 @@ protected function generateKey($key)
* the nearest whole minute for any value over one minute. First, if the passed in TTL is 0 we return
* 0 to allow an unlimited cache lifetime.
*
* @param $ttl
* @return float|int
*/
protected function convertTtl($ttl)
Expand Down
14 changes: 5 additions & 9 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ public function register()
/**
* Bootstrap any application services.
*
* @param CacheManager $manager
* @param Repository $config
* @return void
*/
public function boot(CacheManager $manager, Repository $config)
{
$this->publishes([
__DIR__ . '/../config/laravel-aws-cache.php' => config_path('laravel-aws-cache.php')
__DIR__.'/../config/laravel-aws-cache.php' => config_path('laravel-aws-cache.php'),
]);

if (config('laravel-aws-cache.enable')) {
Expand All @@ -45,22 +43,20 @@ public function boot(CacheManager $manager, Repository $config)

protected function insertCredentialSetting(CacheManager $manager, Repository $config)
{
if (!empty(config('laravel-aws-cache.filesystems'))) {
if (! empty(config('laravel-aws-cache.filesystems'))) {
collect(explode(',', config('laravel-aws-cache.filesystems')))
->each(function ($filesystem) use ($manager, $config) {
$config->set([
'filesystems.disks.' . $filesystem . '.credentials' =>
new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache'))
'filesystems.disks.'.$filesystem.'.credentials' => new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache')),
]);
});
}

if (!empty(config('laravel-aws-cache.queues'))) {
if (! empty(config('laravel-aws-cache.queues'))) {
collect(explode(',', config('laravel-aws-cache.queues')))
->each(function ($queue) use ($manager, $config) {
$config->set([
'queue.connections.' . $queue . '.credentials' =>
new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache'))
'queue.connections.'.$queue.'.credentials' => new LaravelCacheAdapter($manager, config('laravel-aws-cache.cache')),
]);
});
}
Expand Down
7 changes: 4 additions & 3 deletions tests/LaravelCacheAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@

class LaravelCacheAdapterTest extends TestCase
{
/** @var \Mockery\MockInterface */
/** @var \Mockery\MockInterface */
protected $manager;

protected $repository;

public function tearDown()
public function tearDown(): void
{
m::close();
}

public function setUp()
public function setUp(): void
{
$this->manager = m::mock('Illuminate\Cache\CacheManager');
$this->manager->shouldReceive('store')
Expand Down

0 comments on commit f17e2b8

Please sign in to comment.