Skip to content

Commit

Permalink
Support Laravel 8 (#18)
Browse files Browse the repository at this point in the history
* fix tests

* add github actions script
  • Loading branch information
daryledesilva authored Jan 20, 2021
1 parent 668f230 commit 5967cad
Show file tree
Hide file tree
Showing 35 changed files with 379 additions and 175 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI
on:
push:
branches:
- '**'
tags-ignore:
- '**'
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0' ]
laravel: [ '6.*', '7.*', '8.*' ]
prefer: [ 'prefer-lowest', 'prefer-stable' ]
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} --${{ matrix.prefer }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
tools: composer:v2, phpunit
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Setup problem matchers for PHP
run: echo "::add-matcher::${{ runner.tool_cache }}/php.json"

- name: Setup problem matchers for PHPUnit
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}-${{ matrix.prefer }}-
restore-keys: ${{ runner.os }}-composer-${{ matrix.prefer }}-

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update
composer update --${{ matrix.prefer }} --prefer-dist --no-interaction --no-suggest
- name: Test with phpunit
run: phpunit
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"issues": "https://github.com/FrozenNode/Laravel-Administrator/issues"
},
"require": {
"php": ">=5.4.0",
"laravel/framework": "^6.0|^7.0",
"php": "^7.4|^8.0",
"laravel/framework": "^6.0|^7.0|^8.0",
"ckeditor/ckeditor": "4.*"
},
"require-dev": {
"mockery/mockery": "~0.9"
"mockery/mockery": "^1.3.1"
},
"autoload": {
"psr-0": {
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="true"
syntaxCheck="false"
stopOnFailure="false"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
4 changes: 2 additions & 2 deletions src/Frozennode/Administrator/DataTable/Columns/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function build()
$options['sort_field'] = $this->validator->arrayGet($options, 'sort_field', $options['column_name']);

//if the supplied item is an accessor, make this unsortable for the moment
if (method_exists($model, camel_case('get_'.$options['column_name'].'_attribute')) && $options['column_name'] === $options['sort_field'])
if (method_exists($model, \Illuminate\Support\Str::camel('get_'.$options['column_name'].'_attribute')) && $options['column_name'] === $options['sort_field'])
{
$options['sortable'] = false;
}
Expand All @@ -165,7 +165,7 @@ public function build()
}

//now we do some final organization to categorize these columns (useful later in the sorting)
if (method_exists($model, camel_case('get_'.$options['column_name'].'_attribute')) || $select)
if (method_exists($model, \Illuminate\Support\Str::camel('get_'.$options['column_name'].'_attribute')) || $select)
{
$options['is_computed'] = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Frozennode/Administrator/Fields/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function getOption($key)

if (!array_key_exists($key, $options))
{
throw new \InvalidArgumentException("An invalid option '$key' was searched for in the '" . $this->userOptions['field_name'] . "' field");
throw new \InvalidArgumentException("An invalid option '$key' was searched for in the '" . ($this->userOptions['field_name'] ?? null) . "' field");
}

return $options[$key];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public function filterQuery(QueryBuilder &$query, &$selects = null)
$query->whereIn($column2, $value);

//add having clauses
$query->havingRaw('COUNT(DISTINCT ' . $query->getConnection()->getTablePrefix() . $column2 . ') = ' . count($value));
if($value instanceof \Countable || is_array($value)){
$query->havingRaw('COUNT(DISTINCT ' . $query->getConnection()->getTablePrefix() . $column2 . ') = ' . count($value));
}

//add select field
if ($selects && !in_array($column2, $selects))
Expand Down
6 changes: 3 additions & 3 deletions src/Frozennode/Administrator/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ protected function add(array &$menu, string $item, $key): void
$settingsPrefix = $this->configFactory->getSettingsPrefix();
$pagePrefix = $this->configFactory->getPagePrefix();
if (strpos($item, $settingsPrefix) === 0) {
$url = route('admin_settings', array(substr($item, strlen($settingsPrefix))));
$url = \Illuminate\Support\Facades\URL::route('admin_settings', array(substr($item, strlen($settingsPrefix))));
} elseif (strpos($item, $pagePrefix) === 0) {
$url = route('admin_page', array(substr($item, strlen($pagePrefix))));
$url = \Illuminate\Support\Facades\URL::route('admin_page', array(substr($item, strlen($pagePrefix))));
} elseif (filter_var($item, FILTER_VALIDATE_URL)) {
$url = $item;
} else {
$url = route('admin_index', array($item));
$url = \Illuminate\Support\Facades\URL::route('admin_index', array($item));
}
$menu[$url] = $key;
}
Expand Down
14 changes: 5 additions & 9 deletions tests/Actions/ActionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Mockery as m;

class ActionFactoryTest extends \PHPUnit_Framework_TestCase {
class ActionFactoryTest extends \PHPUnit\Framework\TestCase {

/**
* The Validator mock
Expand All @@ -29,7 +29,7 @@ class ActionFactoryTest extends \PHPUnit_Framework_TestCase {
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
$this->validator = m::mock('Frozennode\Administrator\Validator');
$this->config = m::mock('Frozennode\Administrator\Config\Model\Config');
Expand All @@ -39,7 +39,7 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
m::close();
}
Expand All @@ -59,21 +59,17 @@ public function testParseDefaults()
$this->assertEquals($this->factory->parseDefaults('action', array()), $output);
}

/**
* @expectedException InvalidArgumentException
*/
public function testParseDefaultsInvalidName()
{
$this->expectException(\InvalidArgumentException::class);
$this->config->shouldReceive('getDataModel')->once()
->shouldReceive('getOption')->once();
$this->factory->parseDefaults(true, array());
}

/**
* @expectedException InvalidArgumentException
*/
public function testParseDefaultsInvalidOptions()
{
$this->expectException(\InvalidArgumentException::class);
$this->config->shouldReceive('getDataModel')->once()
->shouldReceive('getOption')->once();
$this->factory->parseDefaults('action', true);
Expand Down
23 changes: 14 additions & 9 deletions tests/Actions/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use Mockery as m;

class ActionTest extends \PHPUnit_Framework_TestCase {
class ActionTest extends \PHPUnit\Framework\TestCase {

/**
* The Validator mock
Expand All @@ -29,7 +29,7 @@ class ActionTest extends \PHPUnit_Framework_TestCase {
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
$this->validator = m::mock('Frozennode\Administrator\Validator');
$this->config = m::mock('Frozennode\Administrator\Config\Model\Config');
Expand All @@ -41,37 +41,44 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
m::close();
}

/**
* @doesNotPerformAssertions
*/
public function testValidates()
{
$this->validator->shouldReceive('override')->once()
->shouldReceive('fails')->once()->andReturn(false);
$this->action->validateOptions();
}

/**
* @expectedException InvalidArgumentException
*/
public function testValidateFails()
{
$this->expectException(\InvalidArgumentException::class);
$this->validator->shouldReceive('override')->once()
->shouldReceive('fails')->once()->andReturn(true)
->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array())));
$this->config->shouldReceive('getOption')->once()->andReturn('');
$this->action->validateOptions();
}

/**
* @doesNotPerformAssertions
*/
public function testBuild()
{
$this->action->shouldReceive('buildStringOrCallable')->twice();
$this->validator->shouldReceive('arrayGet')->once()->andReturn(array());
$this->action->build();
}

/**
* @doesNotPerformAssertions
*/
public function testBuildStringOrCallableEmpty()
{
$this->config->shouldReceive('getDataModel')->once();
Expand Down Expand Up @@ -129,11 +136,9 @@ public function testGetOptionSucceeds()
$this->assertEquals($this->action->getOption('foo'), 'bar');
}

/**
* @expectedException InvalidArgumentException
*/
public function testGetOptionFails()
{
$this->expectException(\InvalidArgumentException::class);
$this->action->shouldReceive('getOptions')->once()->andReturn(array('action_name' => 'bar'));
$this->action->getOption('foo');
}
Expand Down
14 changes: 8 additions & 6 deletions tests/Config/ConfigFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mockery as m;
use Frozennode\Administrator\Config\Factory;

class ConfigFactoryTest extends \PHPUnit_Framework_TestCase {
class ConfigFactoryTest extends \PHPUnit\Framework\TestCase {

/**
* The Validator mock
Expand All @@ -25,7 +25,7 @@ class ConfigFactoryTest extends \PHPUnit_Framework_TestCase {
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
$this->validator = m::mock('Frozennode\Administrator\Validator');
$this->validator->shouldReceive('override')->once()
Expand All @@ -35,24 +35,23 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
m::close();
}

/**
* Tests that the validation is run
* @doesNotPerformAssertions
*/
public function testValidationRun()
{
$factory = new Factory($this->validator, $this->validator, array());
}

/**
* @expectedException InvalidArgumentException
*/
public function testValidationErrorThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->validator->shouldReceive('fails')->once()->andReturn(true)
->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array())));

Expand All @@ -76,6 +75,9 @@ public function testMakeReturnsFalse()
$this->assertEquals($factory->make('some_model'), false);
}

/**
* @doesNotPerformAssertions
*/
public function testUpdateConfigOptions()
{
$config = m::mock('Frozennode\Administrator\Config\Config');
Expand Down
20 changes: 11 additions & 9 deletions tests/Config/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use Mockery as m;
use Frozennode\Administrator\Config\Config;

class ConfigTest extends \PHPUnit_Framework_TestCase {
class ConfigTest extends \PHPUnit\Framework\TestCase {

/**
* The Validator mock
Expand All @@ -30,7 +30,7 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
$this->validator = m::mock('Frozennode\Administrator\Validator');
$this->config = m::mock('Frozennode\Administrator\Config\Config', array($this->validator, $this->validator, array('name' => 'model_name')))->makePartial();
Expand All @@ -39,29 +39,33 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
m::close();
}

/**
* @doesNotPerformAssertions
*/
public function testValidates()
{
$this->validator->shouldReceive('override')->once()
->shouldReceive('fails')->once()->andReturn(false);
$this->config->validateOptions();
}

/**
* @expectedException InvalidArgumentException
*/
public function testValidateFails()
{
$this->expectException(\InvalidArgumentException::class);
$this->validator->shouldReceive('override')->once()
->shouldReceive('fails')->once()->andReturn(true)
->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array())));
$this->config->validateOptions();
}

/**
* @doesNotPerformAssertions
*/
public function testBuild()
{
$this->config->build();
Expand All @@ -80,11 +84,9 @@ public function testGetOptionWorks()
$this->assertEquals($this->config->getOption('name'), 'model_name');
}

/**
* @expectedException InvalidArgumentException
*/
public function testGetOptionThrowsException()
{
$this->expectException(\InvalidArgumentException::class);
$this->config->shouldReceive('getOptions')->once()->andReturn(array('name' => 'model_name'));
$this->config->getOption('foo');
}
Expand Down
Loading

0 comments on commit 5967cad

Please sign in to comment.